Build qty discount app: How to store the data

Build qty discount app: How to store the data

leele
Shopify Partner
1 0 0

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?

Reply 1 (1)

PageFly-Theodor
Shopify Partner
691 86 106

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

Please let me know if it works by giving it a Like or marking it as a solution!


PageFly - #1 Page Builder for Shopify merchants.


All features are available from Free plan. Live Chat Support is available 24/7.