Copied to clipboard

Flag this post as spam?

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


  • iiii 15 posts 154 karma points
    Sep 11, 2017 @ 11:08
    iiii
    0

    [discount coupons] Add promo code and calculating total amount

    Hello!

    I'm new to umbraco+merchello, and I have a cart page where the user can add a promocode which will update the total to be charged. (After this step, he will be asked to fulfill the address and then the payment details.)

    I have a BasketController that calls the following function:

    public void AddPromoCode(string promoCode)
        {
            var checkoutManager = _basket.GetCheckoutManager();
            var result = checkoutManager.Offer.RedeemCouponOffer(promoCode);
    
            if (!result.Success)
            {
                throw new Exception(result.Exception.Message);
            }
        }
    

    When the user inserts a invalid promocode it works as expected: throws a "code doesnt exist" exception, that i take care. When he inserts a valid promocode it throws a "object reference not found" exception.

    Can you help me with this?

    Thank you! :)

  • iiii 15 posts 154 karma points
    Sep 18, 2017 @ 08:55
    iiii
    100

    basically just defined a dummy billing address and it worked.

           var checkoutManager = _basket.GetCheckoutManager();
           checkoutManager.Customer.SaveBillToAddress(GetDummyAddress());
           var result = checkoutManager.Offer.RedeemCouponOffer(promoCode);
    

    however.. it doesnt update the basket total but the invoice total.. (if i do checkoutManager.Payment.PrepareInvoice() the invoice total includes the discount)

Please Sign in or register to post replies

Write your reply to:

Draft