cancel
Showing results for 
Search instead for 
Did you mean: 

Why is a voucher application setting the free shipping?

Former Member
0 Kudos

We found this interesting behaviour after having applied a voucher on a cart (both by HMC and from our code)

 voucherFacade.applyVoucher(voucherCode);

What happens is that the cart gets a free shipping, even if the voucher has not free shipping included.

By decompiling this incredibly well coded part, we found this code that indeed sets the free shipping, but we cannot really understand why.

 public VoucherValue getVoucherValue(AbstractOrder anOrder) {
     Iterator discounts = anOrder.getDiscounts().iterator();
     boolean found = false;
     boolean applyFreeShipping = false;

     while(discounts.hasNext() && !found) {
         Discount applicableValue = (Discount)discounts.next();
         if(applicableValue instanceof Voucher) {
             Voucher resultValue = (Voucher)applicableValue;
             if(resultValue.isApplicable((AbstractOrder)anOrder) && resultValue.isFreeShippingAsPrimitive()) {
                 if(resultValue.equals(this)) {
                     applyFreeShipping = true;
                 }

                 found = true;
             }
         }
     }

Any ideas?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

This looks like a bug. It finds only vouchers with free shipping.

Former Member
0 Kudos

Are you saying that it should find only the one with free shipping? Thanks