Is it possible to update a cart with an item, without said item being a product in the catalog?

Kyounis
New Member
2 0 0

Hey there,

 

My team and I are currently developing an application that will interact with the merchant's checkout page utilizing Shopify's Webhooks APIs. The question I am currently working through is regarding the addition of an item to the cart. I am wondering if it is possible to add an item ( that is not listed on the merchant's product catalog ) to the cart via the cart/update webhook. The item that will be added is dynamic based on the items and total of the cart, which is why there is a challenge of creating a product that can simply be added into the product catalog. We are new to Shopify and are very excited to get this application onto the store. Any feedback here is very welcomed and appreciated.

 

Thanks!

0 Likes
_JB
Shopify Staff
Shopify Staff
750 86 163

Hey @Kyounis,

 

If you're looking to add/change items in the cart on the storefront, the AJAX API is what you'll use. This API does require the product to already exist in the store, but there's a few additional options you can consider to achieve your desired functionality. 

 

Since this API requires the product to exist in the store, one option is to create the product beforehand with multiple variant options. Each product can have up to 100 variants, so if it makes sense for your app, you can create the variants first and use the resulting variant_ids to load the cart.

 

You can also use the AJAX API to take advantage of line_item properties, which allows you to add additional information to each item in the cart. If it makes sense for your use case, you can consider creating a product with multiple variants with different pricing, and then use the AJAX API to add a variant to the cart with custom line_item properties. 

 

Although this will be a more involved build, it's also an option to use cart#update webhooks in conjunction with the admin API to create these new products on the fly, and then add the newly created product via AJAX on the storefront. There's potential for this to create a delay on the storefront, since the process goes through multiple APIs, but it's an option nonetheless. 

JB | 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

Kyounis
New Member
2 0 0

Hi @_JB ,

Thank you for the detailed response! This is very helpful as it points me in the correct direction. I am interested in trying to do some sort of combined mixture between the AJAX API and manipulating a line_item through custom line_item properties.

One last question. Is the price of a product a field that can be manipulated? The example would be: we create a product and add it to their store, our app adds the product to the checkout and then based off of computations we adjust the price of the product directly on the cart.

 

Thanks again, for your time!

0 Likes