Im looking to throw up a Modal dialog box (materialcss) if the user hasn’t set their preferred currency. Primarily because the cart resets and empties if the reset is done with a full cart. Which is annoying to a visitor.
I don’t want to do in the initial landing page which can deter a visitor. SO, Id like to throw up the screen when a visitor adds an item to the cart.
I have the modal box opened (modal.open
) in the Snipcart.events.on('item.adding',
Snipcart.events.on(‘item.adding’, (parsedCartItem) => {
…
if (currency == undefined) {
modal.open
});Snipcart.events.on(‘item.added’, (cartItem) => {
console.log(“item added”);
});
BUT… given the async nature item.added
is fired prior to the currency selected in the modal box.
The result: the cart is reset and emptied AFTER and not before the first item is added
I need to either do some blocking during the modal call OR removing the item.added event and then calling it later.
Another possibility is SAVING THE ENTIRE CART STATE and then recalculate all items. Since price includes all currencies in a json format.!
Anyone face a similar situation with a good solution!