Shopify App Bridge Cart.Action.SET_DISCOUNT doesn't seem to fire the cart update notification

conrad-decker
Shopify Expert
58 0 12

I've been digging into Shopify App Bridge and am finally feeling pretty familiar with it at this point. I'm working through a very simple embedded POS app that just opens a modal from a cart action, shows a couple of buttons and takes a couple of actions when you click those buttons. Basically the options are to clear the cart, add a customer, remove a customer, add a discount and remove a discount. Nothing fancy by any means. After digging in I'm feeling good about my understanding of what's happening behind the scenes here. Unfortunately, I'm seeing an anomaly that I was hoping to get another set of eyes on. Let me see if I can explain this clearly...

In my code I've subscribed to Cart.Action.UPDATE and, when the cart is updated, I'm just alerting a message to the screen. When I click one of the buttons I mentioned, I fire a call to an App Bridge action. For example, when the "Clear Cart" button is clicked, I call cart.dispatch(Cart.Action.CLEAR). When that runs, I see the cart clear and I am presented with my alert. The same thing happens when I make calls to: 

  • cart.dispatch(Cart.Action.SET_CUSTOMER, { data: { id: xxx } }) A customer is successfully added to the cart and I receive the callback from my subscription to the cart update action

  • cart.dispatch(Cart.Action.REMOVE_CUSTOMER) - The customer is successfully removed from the cart and I receive the callback from my subscription to the cart update action

  • cart.dispatch(Cart.Action.REMOVE_DISCOUNT) - Any cart discounts are removed and I receive the callback from my subscription to the cart update action

The ONLY time (at least that I've found so far) that I don't receiving a callback from the cart update action is when I call cart.dispatch(Cart.Action.SET_DISCOUNT, { data: discountPayload }). When I make that call, I do see my discount get added to the cart (so I know there's nothing wrong with the call itself) but, if I'm not mistaken, it seems almost as if that specific action isn't correctly firing a cart update action. My verbiage is probably a bit off here but hopefully it makes sense. I'm happy to share my code but before I did that I thought I'd check and see if someone from Shopify would be willing to put eyes on this and see if they can replicate the issue. I'm not 100% sure of the simplest way to replicate what I'm doing but I'd be happy to share whatever I can.

Any help would certainly be appreciated. Thanks!

0 Likes
conrad-decker
Shopify Expert
58 0 12

Here's some additional info in the event that it helps anyone. For now, until I can figure out what might be happening here, I'm basically following my Cart.Action.SET_DISCOUNT call with another CART.Action.FETCH call. That seems to be sufficient enough to refresh the cart object and make sure I'm working with the most up to date information. I think this is counter productive to the way APP BRIDGE seems to be intended to work - but it does the trick. For now. 

0 Likes
conrad-decker
Shopify Expert
58 0 12

Okay, some more information if anyone is interested in helping me troubleshoot.

I've gone back to the "Classic POS" version which seems to have a different outcome with the same code. When I make the SET_DISCOUNT call, it does actually fire the UPDATE action and my subscribed function receives that update. This still does not work on the "All New POS".

Really curious if this is just me or if I'm missing something obvious. 

0 Likes