Quantcast
Channel: Opinion: Shopify Community - Shopify APIs & SDKs
Viewing all articles
Browse latest Browse all 25503

{{variant.id}} not working when attempting AJAX API for Add to Cart? by Damon Bolesta

$
0
0

I'm trying to use the AJAX API so I can add items to my cart without refreshing or redirecting.

I have the API file linked in my theme: http://cdn.shopify.com/s/shopify/api.jquery.js?a1c9e2b858c25e58ac6885c29833a7872fcea2ba

And I'm following the AJAX API Sandbox here: http://mayert-douglas4935.myshopify.com/pages/api

 

I added: 

onclick="Shopify.addItem({{ variant.id }}, 1); return false

to my input submit in my product form. I have also tried just adding an entirely separate a tag:

<a href="#" onclick="Shopify.addItem({{ product.id }}, 1); return false">Add Item</a>

In both cases, looking at the source shows me: 

onclick="Shopify.addItem(, 1); return false"

Meaning it is not registering the variant.id.

 

How do I fix this? Do some products not have variants? If so, how do you use the AJAX function, since using the {{product.id}} will provide the right number, but clicking the link gives me an error saying "Cart Error(400): We were not able to add this item to your shopping cart because no variant ID was passed to us. (request_id: 864f24c82d1bfbae4542a9603674861e)". So obviously, it needs a variant id.


Viewing all articles
Browse latest Browse all 25503

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>