Copied to clipboard

Flag this post as spam?

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


  • deeppatel 25 posts 95 karma points
    Sep 20, 2017 @ 11:28
    deeppatel
    0

    Clear Basket when browser closed

    Hi

    i want to remove items in basket when ever browser closed or set some specific time for items stay in basket and after time over set basket clear.

    thanks.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 20, 2017 @ 11:32
    Alex Skrypnyk
    0

    Hi Deeppatel

    What basket are you talking about?

    Thanks,

    Alex

  • deeppatel 25 posts 95 karma points
    Sep 20, 2017 @ 11:38
    deeppatel
    0

    i mean shopping bag

    i want to clear shopping bag after specified time period.

    thanks

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 20, 2017 @ 11:39
    Alex Skrypnyk
    0

    What e-commerce system are you using?

    Can you show the code of your basket?

  • deeppatel 25 posts 95 karma points
    Sep 20, 2017 @ 11:41
    deeppatel
    0

    i am using uCommerce system

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 20, 2017 @ 11:44
    Alex Skrypnyk
    0

    I think you need to add js method on close window event and call server code like this:

    public void ClearBasket()
     {
     // Get rid of the lines
     foreach (var orderLineId in PurchaseOrder.OrderLines.Select(x => x.OrderLineId).ToList())
     {
     UpdateLineItem(orderLineId, 0);
     }
     // Remove all the discounts
     while (PurchaseOrder.Discounts.Any())
     {
     PurchaseOrder.RemoveDiscount(PurchaseOrder.Discounts.FirstOrDefault());
     }
     // Vouchers are also represented as properties, and if not removed from properties they 
                // will be re-generated on the order via the pipeline
     var prop = PurchaseOrder.OrderProperties.FirstOrDefault(v => v.Key == "voucherCodes");
     if (prop != null)
     {
     prop.Value = string.Empty;
     prop.Save();
     }
     PurchaseOrder.Save(); 
     ExecuteBasketPipeline();
     }
    
  • deeppatel 25 posts 95 karma points
    Sep 20, 2017 @ 11:53
    deeppatel
    0

    thanks Alex Skrypnyk

    in which page i need to add ClearBasket() code?

    and how too call ClearBasket() from js?

    thanks.

  • Marcio Goularte 374 posts 1346 karma points
    Sep 20, 2017 @ 14:48
    Marcio Goularte
    0

    try this:

    window.onbeforeunload = function (event) {
    
         $.ajax({
             type: "POST",
             url: '@Url.Action("ClearBasket", "MySurface")',
             async: false,
             success: function (result) {
                 if (result.status)
                 {
    
                 }
             }
         });
     };
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 20, 2017 @ 12:00
    Alex Skrypnyk
    0

    it depends on how your site was built

    What are js frameworks you using?

  • deeppatel 25 posts 95 karma points
    Sep 20, 2017 @ 12:04
    deeppatel
    0

    i use only jquery

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 20, 2017 @ 13:48
    Alex Skrypnyk
    0

    Deeppatel, I can't show the code exactly - try to ask on ucommerce forum - http://eureka.ucommerce.net/#!/

    Maybe there is a ready solution

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft