Product Discount Functions can now set "prerequisites" on discount candidates. This lets you express the "Buy X" side of BXGY (Buy X, Get Y) — for example, "buy 2 of A, get B discounted" — directly in code.
prerequisites field added.Product Discount Functions could express "which product to discount and by how much," but couldn't hold prerequisites like "only if the customer has bought XX."
You can attach prerequisites to a discount candidate. The BXGY logic — "apply this discount only when cart line X has quantity items" — is now fully expressible inside the Function.
BXGY = Buy X, Get Y. A promotional pattern where "buying a specified quantity of one product (Buy X) discounts another product (Get Y)." Visualized directly from the definition:
On product discount candidates, prerequisites field has been added. Each prerequisite is defined as cartLinePrerequisite and holds two values.
| Field | Meaning | Article description |
|---|---|---|
id |
The identifier of the cart line used as the prerequisite | The identifier for the cart line used as the prerequisite. |
quantity |
The quantity required on that cart line in order to qualify for the discount | The number of items from that cart line required to qualify for the discount. |
prerequisites / cartLinePrerequisite / id / quantity). Theexact schema, types, and required/optional distinctions are not stated in the article. Before implementation, verify in the Discount Functions documentation.* The diagram above is id/quantity a conceptual flow assembled from the meaning. The actual evaluation timing and behavior with multiple prerequisites are not stated in the article.
| Item | Existing Product Discount Function | After adding prerequisites |
|---|---|---|
| Specifying discount targets | Yes Which products are discounted and by how much | Yes Same as above |
| "Must have purchased ○○" condition | No Candidates cannot carry prerequisites | Yes prerequisites Declared with |
| BXGY's "Buy X" expression | No | Yes cartLinePrerequisite Defined with |
| Condition unit | — | Cart line (id) + required quantity (quantity) |
| Target Function type | — | Product discount candidates |
Product discount candidates now have prerequisites added. The way discounts themselves are returned is unchanged — the only difference is that prerequisites can now be attached.Prerequisites can now be "attached"Diff.
Each prerequisite is represented as cartLinePrerequisite , holding two values:id(the cart line identifier) and quantity(the required quantity).
Discount target (Get Y) = the candidate itself; prerequisite (Buy X) =prerequisites. Since the two are linked at the candidate level, you can set different conditions per candidate.
Behavior for multiple prerequisites (AND/OR), handling of excess quantities, target API versions, etc. are not specified in the article.Verify in the docs before implementing.
The article directs readers to "see the Discount Functions documentation for details." Field types, required/optional status, and sample implementations live there. Treat the diagrams and code on this page as conceptual overviews only.
prerequisites(Buy X = main product), so the discount applies automatically only when the main product is purchased.id Set the main product cart line inquantity and the required quantity in. Check the docs for the evaluation spec when multiple conditions apply.quantity with a threshold (e.g., 3) set on cartLinePrerequisite of the target cart line as a discount candidate, so the discount applies only when the threshold is reached.