Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

Re: AppBridge Cart API chain actions (add_line_items and set_discount)

AppBridge Cart API chain actions (add_line_items and set_discount)

ddds
Shopify Partner
1 0 0

https://shopify.dev/apps/tools/app-bridge/actions/cart

 

What's the proper way of chaining those actions?

 

if you just go inline: dispatch after dispatch you can end up having a race condition (that set_discount will be processed before add_line_item) and the discount will be 0, because it cant go below current subtotal.

 

As a workaround you may listen to subscriber and call set_discount only when it finishes, but it's pretty inefficient when you work with multiple line_items that you are going to add to the cart.

 

Thanks!

Replies 3 (3)

mmoore99
Visitor
3 0 0

I have the same question. The docs for App Bridge are woefully inadequate with regards to providing examples for real world scenarios. 

 

I hope that someone from Shopify will jump in here and provide some information. Although I am not hopeful as no one seems to pay any attention or reply to most questions raised in this forum. It is hard to know how to get support from Shopify on development issues. Good luck!

Alan
Shopify Staff
129 15 25

Hi @ddds and @mmoore99 

Thanks for getting in touch here. I definitely understand where you're coming from on this - there have been some updates and changes to App Bridge recently that have impacted workflows.

That said, @ddds 's solution is the best workaround for the moment when it comes to avoiding the race condition that results in the conflict between the set_discount and add_line_item actions. I can share that our developers have worked on this issue recently and an upcoming release will queue all actions and execute them in sequence. This means that running addLineItem, setDiscount, fetch will return a cart with lineItem and the proper discount at the end of  a fetch.

 

I can't guarantee a timeline specifically for when these changes will go live, but please keep an eye out on our changelog for the next few days/weels as it is anticipated that these will roll out very shortly. 

Alan | API 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

mmoore99
Visitor
3 0 0

@Alan wrote:

Hi @ddds and @mmoore99 

Thanks for getting in touch here. I definitely understand where you're coming from on this - there have been some updates and changes to App Bridge recently that have impacted workflows.

That said, @ddds 's solution is the best workaround for the moment when it comes to avoiding the race condition that results in the conflict between the set_discount and add_line_item actions. I can share that our developers have worked on this issue recently and an upcoming release will queue all actions and execute them in sequence. This means that running addLineItem, setDiscount, fetch will return a cart with lineItem and the proper discount at the end of  a fetch.

 

I can't guarantee a timeline specifically for when these changes will go live, but please keep an eye out on our changelog for the next few days/weels as it is anticipated that these will roll out very shortly. 


I am also experiencing similar issues when executing SET_LINE_ITEM_PROPERTIES actions following ADD_LINE_ITEM actions. Will they also be resolved with the fixes that you described in your post?