VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: vmfyelloq19 on March 07, 2022, 13:33:21 PM

Title: Get cart data *before* it get's updated
Post by: vmfyelloq19 on March 07, 2022, 13:33:21 PM
Hi friends,

in my template override for cart/default.php I need to know what has changed when a customer updates cart items (quantity, remove item).
$this->cart is already updated with the news quantities, removed items are removed, $_POST only contains cart position ids ans quantities.

I need to display something like:
- Product #123 Foo's quantity has been updated from 1 to 3
- Product #444 Bar has been removed.

Any hints appreciated!
Title: Re: Get cart data *before* it get's updated
Post by: pinochico on March 07, 2022, 18:51:52 PM
Every action in cart use trigger (add to cart, remove from cart, change quantity) or equivalent in JS.

You can create system plugin for echo this trigger or custom JS fot the same.
Title: Re: Get cart data *before* it get's updated
Post by: vmfyelloq19 on March 07, 2022, 19:15:12 PM
Thank you pinochico,

I cannot use JS for this. It needs to be done in PHP.

But for other tasks JS might be helpful. Mind providing examples how to intercept add/remove/upadte cart events with own JS?
Title: Re: Get cart data *before* it get's updated
Post by: Milbo on March 09, 2022, 12:04:06 PM
I think the best trigger for you is plgVmOnAddToCartFilter
Title: Re: Get cart data *before* it get's updated
Post by: vmfyelloq19 on March 09, 2022, 12:55:38 PM
Milbo, thank you for your reply.

I was suspecting that I would need to go the plugin way...

So basically I will need maintain some sort of "shadow cart" keeping track of every add/remove/update event, and offer a way for the template to get this "cart before update"?

(Note to self: make sure this really is a robust solution even if customers use several tabs updating the cart from either of them.)

In case I write a plugin, I'll post it here.
Title: Re: Get cart data *before* it get's updated
Post by: pinochico on March 09, 2022, 22:23:51 PM
QuoteSo basically I will need maintain some sort of "shadow cart" keeping track of every add/remove/update event, and offer a way for the template to get this "cart before update"?

Why?

Now existing a lot of plugins with GA Enhanced Ecommerce, which make the same.
But go on :)
Title: Re: Get cart data *before* it get's updated
Post by: vmfyelloq19 on March 10, 2022, 09:52:45 AM
Hi pinochico.

what exaclty is GA Enhanced Ecommerce and how does it help getting the required data in my template as described in the inital question?