FROM CACHE - en_header

Script Editor App's published Line-Item script does not execute on the new Cart object mutations.

FactoryAidan
Shopify Partner
10 1 6

Why did I post?

I believe there's a bug in the interaction between the Storefront API's new Cart object and Shopify's Script Editor scripts. The bug is that Line-Item scripts do not execute on Cart related mutations.

Evidence

I can copy & paste GraphQL queries & responses all day. But the gist of it is, using the latest `v.2021-10` GraphQL endpoint, the published Shopify Script Editor Line-Item scripts properly execute on the `checkoutLineItemsAdd` mutation but does not execute whatsoever on the `cartLinesAdd` mutation. This statement of behavior is true for all the other mutations of those objects.

Assumptions

My Script Editor App's published Line-Item script is fully functional. It is, take my word for it. It's easy to write a simple script to verify this, do it.

I've tested with various Line-Item scripts and they all work perfectly against Storefront API Checkout object mutations and not at all on the Storefront API's Cart object mutations.

Let's talk academics

I assume Shopify created the new Cart object to lighten the processing and database load related to the heavier Checkout object. There's a lot of customer `line_item` activity that never makes it to checkout so why should we burden the checkout infrastructure unnecessarily, right? So, once a customer gets their Cart items locked-in as desired, they then get promoted to Checkout items (eventually). But what if customers change their mind last minute and still want to change some checkout line_items, right? Well that's why keeping both implementations makes sense. So I get that the CartLine object is not a replacement for the CheckoutLineItem object. As a result, there are two places to edit `line_items` that are or will eventually be Checkout related `line_items`. We all understand.

Does this make sense?

If I stretch my imagination, I can grasp at why Shopify Script Editor Line-Item scripts wouldn't be executed on Cart object mutations because:

"A Cart represents the merchandise that a buyer intends to purchase"

And maybe "intends" there means it operates more like a semi-functional Cart; a casual wish-list?

But I still can't really understand why it would make sense to not enact my cart `line_item` modifications executed by the Script Editor on that Cart object. For the customer, this is a very disorienting & misleading experience. Imagine the customer not experiencing the Script Editor `line_item` modifications while browsing the website and using the Cart... and then all of a sudden a rush of `line_item` changes unexpectedly appear when their `line_items` are promoted from Cart to Checkout.

As a result of this current behavior, whether it be a bug or not, I'm forced to continue using the Checkout object site-wide and ignore the new Cart object completely. That means the benefits Shopify intended to realize will not be realized. I don't think this is the intended effect Shopify was moving towards when they conceived of the Cart object concept.

So, what's the plan here, Shopify?

Does this mean one of:

  • it's a bug and that bug will be addressed.
  • I should continue using the Checkout object for all my customer's cart related needs. (ignoring the new Cart object the team worked hard to implement)

?

Reply 1 (1)
PeanutButter
Shopify Partner
376 67 173

Scripts apply in the Liquid cart in Shopify themes so it makes no sense that in the storefront api they do not.

 

It would be great that Shopify clarifies this

Peanut Butter Collective | Shopify Experts
- Was my reply helpful? Please Like and Accept Solution.
- Want to customize and improve your store? Hire us.
- Feel free to contact me us hello@peanutbutter.es