refreshing cart on change

New Member
52 0 0

Hello all. 

 

I am looking to update the cart automatically when someone changes the value of the quantity. So far I have used the onblur & onchange function in the input tag but neither have worked. When someone updates the quantity the cart refresehed but after refresh is finished it returns back to the quantity of 1. Any ideas? Thanks. 

 

Below are the two ways I have already tried:

<input id="updates_{{ item.key }}" type="number" step="1" min="0" name="updates[]" value="{{ item.quantity }}" title="{{ 'cart.label.quantity' | t }}" class="input-text qty text" size="4" pattern="[0-9]*" onchange="this.form.submit();"/>
<input id="updates_{{ item.key }}" type="number" step="1" min="0" name="updates[]" value="{{ item.quantity }}" title="{{ 'cart.label.quantity' | t }}" class="input-text qty text" size="4" pattern="[0-9]*" onblur="this.form.submit();"/>
0 Likes
Shopify Expert
2490 417 525

Hi @DEAUXTECH 

As you are submitting form and when form will submit it will reload page, so you have to update it by Ajax cart function. check this doc

 

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes
New Member
52 0 0
Hello. Thanks for your reply.

Where do I add this code? Do I add it in my .js file?
0 Likes
Shopify Expert
2490 417 525

Yes you have to add update Js in Asset->theme.js file at bottom. 

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes
New Member
52 0 0

Hello, how would I write this in my theme.js? instead of the numbers would I use the 'variant_id' object? 

 

Thanks. 

0 Likes
Shopify Expert
2490 417 525

You have to pass variant id and qty in update Js. that you have to get by custom Js code. so when you update any qty you ahve to pass its variants id and qty in ajax Js function. 

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes
New Member
52 0 0

Thanks again for your reply, I don't quite understand? 

 

Would I write it like this in my theme.js?

jQuery.post('/cart/update.js', {
  updates: {
    [variant_id]: 2,
    [variant_id]: 3
  }
});
0 Likes
Shopify Expert
2490 417 525

Yes you have to pass variant id and its qty in this function. so it will update cart as you passed values. 

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes