Skip to Content
author's profile photo Former Member
Former Member

Why is a voucher application setting the free shipping?

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?

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Dec 11, 2014 at 11:28 AM

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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.