Hi, I’m creating a new Shopify App for product option with an additional price. For example, on the product page, the product’s price is 10$, when selecting an option, the additional price is 5$. If I add that product with an option to cart, how can I submit the total price (15$) instead of product’s price (10$)?
Thank you.
Hello @tnet1399 ,
You can follow these steps:
- Create a new cart in your Shopify app, or retrieve the existing cart if one already exists.
- When adding the product with an option to the cart, use the variant ID that corresponds to the selected option with the additional price.
- Calculate the total price for the product and the selected option by adding the base price of the product to the additional price of the selected option.
- Update the line item in the cart to reflect the new total price by setting the price attribute of the line item to the calculated total price, like this:
cart = ShopifyAPI::Cart.find(cart_id)
line_item = cart.line_items.find(line_item_id)
total_price = line_item.variant.price + selected_option_additional_price
line_item.price = total_price
line_item.save
Hope this will help.
OneCommerce team.
3 Likes
Thank you! Your solution works perfectly as my expectation!
1 Like
@OneCommerce Can you please share me the API reference and can you tell me that could we update the cart price by adding the additional prices using RestFull API or GraphQL.
Please Reply must and thanks in advance!
@tnet1399 Can you please guide me in updating the cart? can you tell me which shopify APIs are used and how you update the Cart.
@Prudentt have you got any solution ? or know which API’s they are using ??
1 Like
Hello
can you please send more information of the API you are using to make that adjustments on the cart item price?
Thanks
Héctor
1 Like