Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Dimmer 12 posts 155 karma points
    Jun 06, 2019 @ 13:56
    James Dimmer
    0

    Coupon redeem issue when applying more than one to a basket

    Hi,

    We are currently using Merchello v2.7.0 and are experiencing the following issue:

    When redeeming more than one voucher to a customer basket we currently are running into an issue where either the constraints are not being applied correctly or the discount is not being calculated correctly.

    We have setup some test coupons to make a single product free by using an offer code of "FREE", setting the reward to be discount the price 100%, and adding a constraint so that it only applies to a single product (Notebook). When applying this to the current basket it functions correctly.


    We then have another coupon to award a 10% discount which uses an offer code of "10OFF", a reward of discount the price 10%, and no constraints. When applying this to the same basket which has a Notebook @ £2.30 and a Pen @ £2.20, the 10% off is being calculated from the combined values of both products, regardless of the fact that there is also the "FREE" coupon applied. This results in the following discount lines being added to the basket:

    • FREE Notebook: £2.30
    • 10% Discount: £0.45

    This then making the basket total cheaper than it should be as the 10% should only be taken from the Pen line item.


    We also have a coupon setup to award a 20% discount which uses an offer code of "20OFF", a reward of discount the price 20%, and a constraint so it can only be applied with no other coupons. The issue here is that I was able to apply it to the same basket as mentioned above and it was added successfully with a value of a £0.90 discount.


    The code which applies a coupon to the basket is based on the FastTrack controller and can be found below:

    if (!checkoutManager.Payment.IsReadyToInvoice())
            {
                // we need to set a dummy address to be able to apply the discount
                checkoutManager.Customer.SaveBillToAddress(new Address
                {
                    Address1 = "",
                    Address2 = "",
                    Locality = "",
                    Region = "",
                    PostalCode = "",
                    CountryCode = "",
                    AddressType = AddressType.Billing,
                    Name = ""
                });
            }
    
            LogHelper.Info(this.GetType(), string.Format("Applying Discount code {1} to customer {0}", CurrentCustomer.Key, offerCode));
    
            var redeemResult = checkoutManager.Offer.RedeemCouponOffer(offerCode);
            response.Success = redeemResult.Success;
            response.LineItem = redeemResult.Success ? redeemResult.Award : null;
            response.Exception = redeemResult.Exception;
            response.Messages = redeemResult.Messages;
            if (!customerBasket.Items.Contains(offerCode) && response.Success)
            {
                customerBasket.Items.Add(response.LineItem);
                customerBasket.Save();
            }
    

    Any help or advice would be greatly appreciated.

    Thanks, James

Please Sign in or register to post replies

Write your reply to:

Draft