EvgeniyMukhamedjanov / liquid-ajax-cart

Build a Shopify Ajax-cart without JavaScript coding
https://liquid-ajax-cart.js.org
194 stars 22 forks source link

Having a hard time getting a data-ajax-cart-section to update after ATC button clicks #33

Closed xmadscientist closed 2 years ago

xmadscientist commented 2 years ago

Our product form uses a button that sends a post req to cart/add. I am having a really really really hard time getting my data-ajax-cart-section to refresh after anything is added to the cart...

In the cart itself, the data-ajax-cart-section updates work perfectly when adjusting quantities, however.

Does anyone know what the cause might be?

Site: https://olsatools.com/products/magnetic-socket-holder?variant=39430920437811

EvgeniyMukhamedjanov commented 2 years ago

I think the product form is missing the input with the name="id".

xmadscientist commented 2 years ago

What does the input with the name="id" do? @EvgeniyMukhamedjanov

EvgeniyMukhamedjanov commented 2 years ago

Each product form must have an input with the name="id": https://shopify.dev/themes/architecture/templates/product#the-variant-selector even if there is no variants (only Default variant).

xmadscientist commented 2 years ago

@EvgeniyMukhamedjanov I see it being rendered on my product page:

image

EvgeniyMukhamedjanov commented 2 years ago

Yeah, I see. Can you shift the data-ajax-cart-section from the form element to the element with the cart_content_ajax class so that you always have the same amount of the data-ajax-cart-section attributes in your cart? Now you have two attributes if the cart is not empty, and only one data-ajax-cart-section attribute if the cart is empty.

xmadscientist commented 2 years ago

@EvgeniyMukhamedjanov I tried that and couldn't get it to work. I ended up building my own cart update trigger on ATC button clicks and now it works. Closing this issue now.