Dawn Theme - Subscribe to cart:update event

Hi guys,

I need your help with the PUB/SUB event machnism in Dawn Theme.
I currently implement a giftbar and would like to update the giftbar whenever there is an update to the cart.
My code looks e.g. like that:

subscribe(PUB_SUB_EVENTS.cartUpdate, (event) => {
                console.log('Cart updated via PUB_SUB_EVENTS:', event);
                updateGiftBar();
            });

The problem I am facing is that this event is only correctly catched and working once I have refreshed the complete page.
So when I add a product to the the cart the drawer opens up and event is not fetched.
When I refresh only then this event is working (e.g. when I then update the quantity).
I noticed that PUB_SUB_EVENTS is not available right after I added a product. It seems to be only available once I have refreshed the page.

Could someone maybe explain me the issue? How can I make use of the PUB_SUB_EVENTS right after a product was added to the cart and the drawer opened up?

Really appreciate your support!

Thank you very much!

1 Like