Pankaj Sharma
Pankaj Sharma

Reputation: 107

How can we add product in cart using it's SKU number?

I am currently using ajax api /cart/add.js to add product in cart like this:

$.ajax({
   type: 'POST', 
   url: '/cart/add.js',
   dataType: 'json', 
   data: {quantity: 1,id: gift_variant_id},
   error:function(){ console.log('error'); }
 });

is there any way I can add product in cart using product sku number?

because {quantity: 1,sku: sku_number} is not working.

Upvotes: 0

Views: 458

Answers (1)

David Lazar
David Lazar

Reputation: 11427

No. There is only one way to add a product to the cart, and that is by providing a valid variant ID.

A SKU is not unique in Shopify, it is simply a descriptive string value, meaning a shop with 1000 products could theoretically assign them all a single SKU with no errors. Hence, that is a problem. So rule is, use a valid ID.

Upvotes: 1

Related Questions