Build qty discount app: How to store the data

Topic summary

Main issue: How to store and quickly look up user-configured quantity-based discount rules (e.g., buy 2 of A/B/C get 20%; buy 3 get 30%) for a Shopify app that already calculates discounts via Shopify Functions.

Current state: The app’s discount calculation works (following Shopify’s discounts tutorial). Uncertainty remains about where to persist rules and how to query them efficiently; Metaobjects were considered.

Recommendation: Use the Shopify App Storage API rather than Metaobjects for rule storage.

Implementation details:

  • Persist rules as JSON (fields: quantity thresholds, discount percentages, product and collection IDs).
  • On cart updates, retrieve these rules via the App Storage API.
  • Match cart items to rules and apply discounts through Shopify Functions.

Rationale/benefits:

  • Faster, more efficient rule retrieval and matching.
  • Scales better with many rules. Metaobjects are not ideal for this type of lookup.

Terms:

  • Shopify Functions: server-side logic for discounts.
  • Metaobjects: custom data structures in Shopify.
  • App Storage API: per-shop app-managed storage.

Status: Guidance provided; no final decision reported. Discussion remains open.

Summarized with AI on December 27. AI used: gpt-5.

I am new to Shopify development and I am thinking of creating a Qty Discount app to learn more about it.

I followed the tutorial on this page: https://shopify.dev/docs/apps/build/discounts/experience and got it working.

However, for my app, I want to allow customers to select products, collections, etc., to which the discount is applied.

For example, if you buy:

  • 2 products A, B, or C, you will get 20% off.
  • 3 products A, B, or C, you will get 30% off.

I know how to use Shopify Functions to calculate the discount and update the cart. However, I am not sure how or where to store these discount settings configured by the user. I was thinking of using Metaobjects but I am not sure if it is the right approach. If I store the data in custom Metaobjects, when a user adds a product to the cart, how can I quickly look through the Metaobjects and find the relevant discount to be applied to a product?

Does anyone have any ideas?

Hi @leele ,
This is Theodore from PageFly - Shopify Page Builder App.

Building a Qty Discount Shopify app? Here’s how to store user-defined discounts:

Skip Metaobjects: Not ideal for discount rule lookup.

Use Shopify App Storage API:

  1. Store discount rules (quantity, percentage, product/collection IDs) as JSON objects in the App Storage API.
  2. Retrieve rules on cart updates using the App Storage API again.
  3. Match products in cart to rules and apply discounts through your Shopify Functions.

Benefits:

  • Efficient data retrieval for discounts.
  • Scalable for a large number of rules.

Best regards,
Theodore | PageFly