Allow passing data to functions using a cart metafield

Hi Shopify team :wave:

Problem
Data must be passed from the cart to the discount function using an attribute. Attributes are not the ideal candidate for this for two reasons. The first is that technical attributes, when rendered by the theme, are confusing for customers. The second is that other apps may interpret these attributes incorrectly. For example an attribute may end up being printed on a shipping label or be included in an order confirmation email. The proposed solution is to use a private attribute, i.e. using an underscore prefix. While this (usually) helps to resolve the aformentioned issues, it has another flaw: because private attributes are not rendered by Liquid and are not returned by Cart.js API requests it is hard to verify that the attribute is indeed applied. More importantly other apps can easily overwrite such private attributes by updating the cart using the Storefront API with the cartAttributesUpdate mutation. Finally, attributes (even private ones) also pollute the Order screen.

Proposed solution
Metafields seem like a much better candidate to communicate between the cart and a discount function. They wouldn’t be rendered in the storefront by Liquid and they wouldn’t end up on the Order screen, shipping labels or order confirmation emails. They also wouldn’t run the risk of being overwritten by other apps (as easily). Apps could use the cartMetafieldsSet mutation to set such a metafield. Unfortunately discount functions don’t seem to have a way to read those metafields unless I’m missing something.

It looks like this is coming in April according to the roadmap here: Apps in checkout

1 Like