Hi Everyone,
I’m developing an app focusedd on creating advanced product bundles. A core feature allows merchants to set up complex pricing rules, including:
-
Bundle Override Pricing: Setting a fixed total price for the bundle, regardless of the individual item costs.
-
Mixed Discounts: Applying specific percentage/fixed discounts to certain items within the bundle.
-
Free Gifts: Including specific items for free as part of the bundle.
The crucial part is that the final discount structure (which items get what price/discount) for a specific bundle instance is calculated dynamically on our app’s backend. This calculation depends on the merchant’s specific offer rules and the exact items the customer adds to their cart.
We want to use the new unified Discount Functions API (specifically targeting cart.lines.discounts.generate.run) to apply these calculated discounts correctly during checkout.
The Main Challenge: Our app needs to be available for merchants on standard Shopify plans (not just Plus/Enterprise). This means we cannot rely on network access (fetch) within the Discount Function to call our backend and retrieve the calculated discount instructions for the current cart.
What We’ve Considered:
-
Cart Attributes: Passing the calculated details or identifiers (like an internal offer ID) via cart attributes. We understand this is insecure, as attributes can be manipulated client-side, potentially allowing users to claim unintended discounts.
-
Discount Metafields (discountNode.metafield): We know these are intended for static configuration set up when the discount is created/defined. They don’t seem suitable for holding the dynamic, per-cart results calculated by our backend during the checkout process.
-
Admin API metafieldSet: Updating metafields via the Admin API isn’t feasible during the live checkout flow for every cart.
-
Multiple Combined Shopify Discounts: Attempting to replicate our bundle logic by creating many small, combinable Shopify discounts seems extremely complex to manage and unlikely to reliably achieve the exact override pricing due to Shopify’s stacking rules.
Our Question:
Given the need to apply dynamically calculated discounts (determined by our backend based on the specific cart) and the restriction of no network access in the Discount Function for standard plans, what is the recommended, secure, and viable approach?
How can we securely get the specific, pre-calculated discount instructions from our backend logic into the running Discount Function without using fetch or relying on easily manipulated cart attributes? Are there standard patterns, alternative Shopify APIs, or architectural approaches we’re overlooking for this scenario?
Thanks for any insights or suggestions!