Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
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
}
}
]
});
Solved! Go to the solution
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
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...
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
Thank you very much John! That's perfect!