Solved

Cart API - Add Product To Cart without Variant

mojito
Tourist
12 0 1

Hello, I am using the code below to add a product variant to the cart. However, it doesn't work if the product doesn't have any variants.

How can I add a product without variants to the cart? I tried using the Product ID, but that doesn't work.

Any assistance would be greatly appreciated.

jQuery.post('/cart/add.js', {
items: [
{
quantity: 1,
id: 39486502174869,
properties: {
'Length': metres_required
}
}
]
});

Accepted Solution (1)

_JCC_
Shopify Staff
200 27 55

This is an accepted solution.

Hey @mojito ,

Even though a product has no specified variants, a single default variant is always present. If you were to look at the product in the admin, appending .json to the product id or making an admin API call to the product in question you'd see the product has a single variant.

Hope that helps, if you have any questions please don't to reach out.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 3 (3)

ErikAndersson
Tourist
5 1 0

Hijacking this post. I also want to know as im struggeling with the same issue.

https://community.shopify.com/c/Shopify-APIs-SDKs/Checkout-API-line-items-is-an-empty-array/m-p/1101...

_JCC_
Shopify Staff
200 27 55

This is an accepted solution.

Hey @mojito ,

Even though a product has no specified variants, a single default variant is always present. If you were to look at the product in the admin, appending .json to the product id or making an admin API call to the product in question you'd see the product has a single variant.

Hope that helps, if you have any questions please don't to reach out.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

mojito
Tourist
12 0 1

Thank you very much John! That's perfect!