Skip to Content
0
Former Member
Dec 11, 2014 at 11:21 AM

Why is a voucher application setting the free shipping?

219 Views

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?