RFC: Fixing custom data handling in Checkout

Shopify Checkout Extensibility is fantastic, but there are key issues with handling custom order data like tax IDs. This RFC highlights two main problems: the inability to validate metafields in server-side functions and performance issues with order attributes. Fixing these will improve data integrity and order accuracy for merchants.

The Problem

Let’s say you’re building a checkout extension that collects additional information, such as a tax ID. You need to store this data somewhere, and Shopify gives you two main options:

  1. Metafields: These are the modern, recommended way to store custom data.
  2. Order Attributes: An older method, but still widely used.

You choose metafields because it’s 2024 Everything works smoothly at first - you can save the tax ID and even refresh the checkout to confirm that the data is still there. But soon, you’re tasked with validating the tax ID to match a specific format. Here’s where the problem starts.

To perform secure validation, you naturally turn to Shopify’s server-side validation functions. They are ideal for ensuring that only properly formatted data gets passed through to the final order. But—you can’t access metafields within these validation functions. This severely limits your ability to enforce data integrity when using metafields, which is supposed to be the modern solution.

So, you’re forced to switch to order attributes, because they can be read by the server-side functions. But this brings along two new problems:

  • Performance Issues: Saving order attributes is much slower compared to metafields. Every time the user interacts with the field - it takes around one second to save the changes, whereas metafields are nearly instant.
  • Inability to Delete Attributes: Once you’ve added an order attribute, you can’t remove it—you can only set it to an empty string. This creates issues when, for example, a buyer decides to remove their tax ID. An empty attribute could confuse downstream systems expecting either valid data or no data at all, not an empty string.

What Needs to Change

To solve these issues and improve custom data handling in Shopify checkout, I suggest the following changes:

  1. Allow access to metafields in validation functions: Developers need to be able to validate data stored in metafields directly within Shopify’s validation functions. This would eliminate the need for insecure client-side validation and improve overall data integrity.

  2. Improve order attribute performance: Order attributes should save as quickly as metafields to avoid checkout delays. Slower save times negatively affect the user experience and increase the likelihood of errors.

  3. Allow deletion of order attributes: Instead of setting attributes to an empty string, allow developers to fully remove them. This would prevent empty fields from causing problems in downstream systems.

Conclusion

These issues—metafield validation, order attribute performance, and the inability to delete attributes—can result in inaccurate data being passed into orders, causing problems for merchants and downstream systems. Addressing these gaps will improve data integrity and ensure smoother operations for merchants relying on accurate order information.

Hi @Patrick_Jakubik , thanks for the feedback. I can confirm that suggestions 1 (exposing metafields to functions) and 3 (remove cart attribute API) are on the roadmap for the near term. I assume the remove cart attribute API should be mostly straightforward, but exposing metafields to functions will take a bit more time. This also relates to suggestion 2 (improve order attribute performance).

Metafields in checkout UI extensions today are faster because we don’t do any server validation until the buyer attempts to complete checkout. Attributes are slower because we pass them through our servers so that functions can run whenever they are updated (because functions only run on the server). In order to expose metafields to functions, they will have to go through a similar flow as attributes today. It can also take more/less time depending on how many functions are active on a shop. I don’t expect performance to improve in the short term.

1 Like

Hey @Steven-Shopify, thanks for providing more context! It’s always interesting to see how these things work behind the scenes.

Just to clarify:

  1. Will the metafields set using the updateMetafield type be accessible? I heard that only updateCartMetafield is planned, which isn’t particularly useful for the described case.
  2. We only run validation functions during the CHECKOUT_COMPLETION event. Running them during CHECKOUT_INTERACTION showed errors too often, leading to a poor UX.

We’d like to unify the metafield types as right now I think it’s confusing there are both “cart” and “checkout” metafields that have different uses and structure. The current thinking is to allow cart metafields to optionally be persisted to the order, but we haven’t confirmed how we should do this yet.

Understood on your point about only running on checkout_completion, but this behavior isn’t specific to validation functions, its any function that wants to react to changes to cart attributes/metafields (which could be any function)

1 Like