• Welcome to KonaKart Community Forum. Please login or sign up.
 

Bug with Order Total Discount Module

Started by anstuff, January 04, 2011, 02:12:53 am

Previous topic - Next topic

anstuff

While using Order Total Discount module to implement buy 1 get 1 free promotion, we found that on adding a product other than the eligible products for promotion the discount was not getting applied.
e.g. When you add A and B (both eligible) to cart, you would see one of the products for Free.
But when you add C to cart, the discount was no longer applied.

The promotion we created for this is as follows;
Promo type : Order Total Discount
Active: true, Requires Coupon: true, Cumulative: true
Minimum order value: 39.90, Min total quantity: 2, Min Quantity for a product: 1
Discount 19.95, Percent/Amount: false

Following is the code change, that will fix the problem.

                //Generate a list containing eligible product ids
                List<Integer> applicableProductIds = new ArrayList<Integer>();
                for (OrderProductIf op : promotion.getApplicableProducts()) {                   
                    applicableProductIds.add(op.getProductId());
                }

                ot = new OrderTotal();
                ot.setSortOrder(sortOrder);
                ot.setClassName(code);
                ot.setPromotions(new Promotion[]{promotion});

                // Does promotion only apply to a min order value ?
                if (minTotalOrderVal != null) {
                    if (orderValue.compareTo(minTotalOrderVal) < 0) {
                        // If we haven't reached the minimum amount then continue to the next
                        // promotion
                        continue;
                    }
                }

                // Does promotion only apply to a minimum number of products ordered ?
                if (minTotalQuantity > 0) {
                    int total = 0;
                    //instead of looping through promo.applicableProducts, loop through order.OrderProducts
                    //for (int j = 0; j < promotion.getApplicableProducts().length; j++)
                    for (int j = 0; j < order.getOrderProducts().length; j++) {
                        //ensure that applicable product ids has the product that you are trying use
                        if (applicableProductIds.contains(order.getOrderProducts()[j].getProductId())) {
                            total += order.getOrderProducts()[j].getQuantity();
                        }
                    }
                    if (total < minTotalQuantity) {
                        // If we haven't reached the minimum total then continue to the next
                        // promotion
                        continue;
                    }
                }

                // Does promotion only apply to a minimum number of single products ordered ?
                if (minProdQuantity > 0) {
                    boolean foundMin = false;
                    //instead of looping through promo.applicableProducts, loop through order.OrderProducts
                    //for (int j = 0; j < promotion.getApplicableProducts().length; j++)
                    for (int j = 0; j < order.getOrderProducts().length; j++) {
                        //ensure that applicable product ids has the product that you are trying use
                        if (applicableProductIds.contains(order.getOrderProducts()[j].getProductId())) {
                            if (order.getOrderProducts()[j].getQuantity() >= minProdQuantity) {
                                foundMin = true;
                            }
                        }
                    }
                    if (!foundMin) {
                        // If we haven't reached the minimum total then continue to the next
                        // promotion
                        continue;
                    }
                }