claudio88's avatar

bumbummen99 Cart::destory on page close?

Hello, I've been working on an e-commerce site and in the end, I chose to decrease product stock once a client adds that product to the Cart and increases the product stock when they remove the product from the cart. Now this works ok, not sure if its the best option ( maybe increase / decrease once the order was placed or later when confirmed by an admin)

Regardless if I choose to stay with decreasing the product stock once it's added in the cart, or increase when the product is removed from the cart How and where would I use Cart::destroy once the client classes the page?

So I want the cart to be emptied and the stock to be increased with the quantity that was in the Cart once the client closes the page. How would I achieve this?

Thanks in advance for your replies.

0 likes
1 reply
vincent15000's avatar

You can perhaps try to throw an event just before the window closes.

$(window).on("beforeunload", function() { 
    // Here you throw your event and this one has to be captured by Laravel to execute a method (cart destroy for example)
});

Please or to participate in this conversation.