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**](https://shopify.dev/api/storefront/reference/checkouts/checkoutlineitemsadd?api%5Bversion%5D=2021-10) mutation but does not execute whatsoever on the [**cartLinesAdd**](https://shopify.dev/api/storefront/reference/cart/cartlinesadd?api%5Bversion%5D=2021-10) 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)
?