btahir/next-shopify-starter

How to auto-update cart quantity from product page

amxn opened this issue · 1 comments

amxn commented

I use a single component to render a product page - /product/{product-handle}

Our shop doesn't need quantity or variant fields as such they aren't exposed to the users. Wanted to mimic the functionality where multiple clicks update the cart quantity (and adds them to the cart).

For some reason my 'onClick={handleAddToCart}' works but the cart number nor the cart is updated without a full refresh.

Any ideas on what I'm doing wrong? Thank you!

When you first click on Add To Cart it creates a checkout with Shopify. The update quantity action on the Cart page updates this checkout. One way you can do what you're saying is to add some state logic to the Add To Cart Button which updates the quantity after the first click.

See createShopifyCheckout and updateShopifyCheckout functions in Store.js for more info.