Ajax Cart: Update.js not working with variables

Christopher99
Excursionist
18 0 5

Hello everybody,

i am having trouble with ajax carts update feature.
I am trying to update the stock in a cart to 1 for testing purposes.
I have a configurator page which is basically a featured collection (https://boxifique.com/pages/configurator-layers)

<button onclick="addToCart1({{ variant.id }})">Add1</button>
<button onclick="addToCart2()">Add2</button>
<button onclick="addToCart3()">Add3</button>


<script>
  
  function addToCart1(variantID) { 
    console.log(variantID);
	jQuery.post('/cart/update.js', {updates: {variantID: 1}});
  }
  
  function addToCart2() { 
	jQuery.post('/cart/update.js', {updates: {37860296130729: 1}});
  }
  
  function addToCart3() { 
	jQuery.post('/cart/update.js', {updates: { {{ variant.id }}: 1}});
  }
       
</script>

When I use the hardcoded value it works. The same goes for the variant.id (but the id doesnt change, even when clicking on another "Add3"-button)
When pressing (Add1), you can see, that the correct value is written in the console but only the variable name gets send.

Christopher99_0-1609092247875.png

Thanks for any help!

0 Likes

Try using cart.js instead.

◦ Product page slider & thumbnails with swiping for free themes: Minimal | Debut | Brooklyn | Supply
◦ Replace apps with simple copy/paste code snippets. Examples clicking here.
0 Likes
Christopher99
Excursionist
18 0 5

@diego_ezfy the same problem is happening with cart.js

0 Likes