Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Lee 1130 posts 3088 karma points
    Apr 25, 2013 @ 11:14
    Lee
    0

    Unable To Clear Vouchers From Basket

    There seems to be a bug with trying to remove vouchers when clearing the users cart/basket.

    Scenario

    User adds a product to the cart/basket, then from within the cart applys a discount code/voucher. This gets applied and we can see it on the purchase order (And the discount for the order in the database).

    The user then decides they don't want the product, so empties their basket. We now need to remove the discounts as well as the products. We are currently doing this to remove the discounts

     foreach (var discount in discounts)
     {
        basket.PurchaseOrder.RemoveDiscount(discount);
     }
    
     basket.Save();                  
     ExecuteBasketPipeline();

    Using the debugger we can see the discounts are removed from the database once the basket.Save() method is called.

    But after ExecuteBasketPipeline() they magically reappear BACK in the database (Back on the order too). We have the standard Basket pipeline config. And after trial and error of commenting out each line, we have narrowed it down to this pipeline task

    ApplyAwards

    If we comment this out then it works fine. BUT if we comment this out then we won't be able to use the marketing foundation for other campaigns that auto discount the order.

    Slight tearing our hair out here... Especially as there is pretty much NO REAL documentation for this...

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Apr 25, 2013 @ 11:19
    Nickolaj Lundgreen
    100

    If my memory serves me right, vouchers are saved as orderproperties (can't test that right now). Try clearing that list too :)

    Is there a reason why you are not giving the customer a new basket (to avoid the hassle of clearing all the parameters)?

  • Lee 1130 posts 3088 karma points
    Apr 25, 2013 @ 11:24
    Lee
    0

    Thanks for the reply. I'll have a look at that now :)

    We 'could' just abandon the basket and give them a new one. But we want the users to be able to also add a voucher, then remove it if they want. But it's rather clunky to make the user abandon/empty their cart to remove the voucher. 

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Apr 25, 2013 @ 11:31
    Nickolaj Lundgreen
    0

    Maybe this could solve that problem:

    (uCommerceHelpers.CurrentHelper is custom incase you wonder. Just use SiteContext to grab the basket)

    public static void RemoveVoucher(this PurchaseOrder purchaseOrder, string voucher)
    {
        var prop = uCommerceHelpers.CurrentHelper.Basket.OrderProperties.FirstOrDefault(v => v.Key == "voucherCodes");
        if (prop != null)
        {
            prop.Value = prop.Value.Replace(voucher + ",", string.Empty);
            prop.Save();
        }
    }
  • Lee 1130 posts 3088 karma points
    Apr 25, 2013 @ 11:57
    Lee
    0

    You were right. We cleared the voucherCodes property and it worked fine! Thanks :)

Please Sign in or register to post replies

Write your reply to:

Draft