What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Is it possible to manipulate cart data at all at any stage of the checkout process?

Is it possible to manipulate cart data at all at any stage of the checkout process?

gakimovs
Shopify Partner
3 0 1

Hello!

 

Our dev team is currently working on a Gift With Purchase app (GWP). Idea is to allow customers to add products to checkout with 0.00 price along with other products and complete their purchase. Our goal is to use native shopify cart and checkout.

 

While Backend and admin side project are almost completed and we have no issues there, we ran into a few issues with Shopify cart and checkout when trying to pass data from Backend. We want to push certain product to cart and checkout with 0.00 price (product price in shopify admin will NOT be 0.00). Below are few questions from our developers:

 

1. Is it all possible to push certain product data to cart and checkout as currently we have issues with changing product price to 0.00.

 

2. Is it possible to manipulate cart data at all at any stage of the checkout process?

 

3. We are using official python Shopify SDK on our Backend, and we are trying to add/remove line items in cart:

 

cart = Cart.find(# cart token)
cart.line_items.append(# Some item)
cart.save()

 

however, save gives us a 406 error. Can we manipulate cart items from Backend, or this logic is only accessible via JS / cart.js?

 

Thank you

Replies 4 (4)

EcomGraduates
Shopify Partner
784 68 112

Hello there  

 

Yes, it is possible to add a product to the cart with a 0.00 price. You can create a new variant for the product with a price of 0.00 and add that variant to the cart. Alternatively, you can add a discount code that will apply a 100% discount to the product, effectively making it free.

Yes, it is possible to manipulate cart data at any stage of the checkout process using Shopify's API. You can add, remove or modify line items in the cart using the Cart API.

The 406 error you are experiencing could be due to a variety of reasons such as invalid input or incorrect data format. It is possible to manipulate cart items from Backend using Shopify's API, including the Python SDK. You can use the line_items attribute to add, remove or modify line items in the cart, and then use the save() method to save the changes. Make sure that you are passing valid data to the API and that your requests are properly formatted.


 If this fixed your issue, likes and accepting as a solution are highly appreciated
|  Build an online presence with our custom-built Shopify Theme: EcomifyTheme
|  Check out our reviews: Trustpilot Reviews
|  We are Shopify Partners: EcomGraduates Shopify Partner



gakimovs
Shopify Partner
3 0 1
Thank you for your response!
it seems to me that the issue is not about invalid input or incorrect data format.
I am doing simple logic to change item quantity in the cart
from shopify import Cart

cart = Cart.find("some_token")
cart.line_items[0].quantity = 1
cart.save()
And the error message I am getting, doesn’t give a lot of context
code=406, body="b''",msg="Not Acceptable"
maybe there are some Admin API access scopes we should enable
 
Thanks!
gakimovs
Shopify Partner
3 0 1

Hello!

 

Thank you for your answer

 

I was wondering about this comment you made: "Alternatively, you can add a discount code that will apply a 100% discount to the product, effectively making it free."

 

Is there a way to add discount to product in cart? We couldn't find a way to do that in cart via front or backend. Note NOT to whole cart, but to particular product.

 

Thank you

 

ShopifyDevSup
Shopify Staff
1453 238 525

Hi gakimovs,

 

Information about live carts on the hosted Online Store channel is not available to the Admin API so the updates to the cart for adding a gift would need to be done via the front end before the order gets sent to checkout.

 

During the normal live checkout process the only recommended way to make changes is through Checkout Extensions.

 

Hope you have a great day

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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