Promotions
Code-based discounts, their conditions and effects, promotion codes, and cart usage
A promotion is a discount rule: who gets it (conditions), what it does (effects), how it
combines with others (stacking, priority) and how often it can be used. Its activation is
fixed when it is made: { type: "codes" } applies through its promotion codes, which a buyer
enters, and { type: "automatic" } applies to every cart while it is active, inside its schedule
and under its limit, and its conditions hold, without a code. An automatic promotion has no codes
(adding one is refused with 409 PROMOTION_CODE.AUTOMATIC_PROMOTION). A promotion is a discount,
not stored value.
Effects
import type { PromotionEffect } from "arky-sdk";
const effects: PromotionEffect[] = [
{
type: "item_percentage",
id: crypto.randomUUID(),
target: { type: "categories", category_ids: [accessoriesCategoryId] },
basis_points: 1_000,
},
{
type: "delivery_fixed",
id: crypto.randomUUID(),
amounts: [
{ amount: 500, currency: "eur" },
{ amount: 1_000, currency: "bam" },
],
},
];
- Effects are
item_percentage,item_fixed,order_percentage,order_fixed,delivery_percentage,delivery_fixedandbuy_x_get_y. Each has an id the app picks, unique within its promotion. - Item effects name a target: products, product variants, booking services,
package_offerings(buying a package of those offerings),packages(buying that package),listed_in_packages(everything priced from them), categories, or all eligible items. item_fixedtakes its amount off each matching unit (scope: { type: "per_unit" }) or once, split across the matching units (scope: { type: "once_per_order" }). Order effects work once across all lines that take promotions, and delivery effects once across the cart’s deliveries.buy_x_get_yrepeats as often as the cart allows: each timebuy.quantitymatching units andget.quantityreward units are there, the cheapest reward units get its percentage off.- Percentages are basis points:
100is 1%,10_000is 100%. Fixed amounts list one amount per currency, each currency once, in integer minor units. - Effects apply in three rounds: every applied promotion’s item effects, then their order effects,
then their delivery effects. Within a round, promotions go from the highest
prioritydown, and each works on what earlier discounts left, so a line never goes below zero. - Only lines priced from the cart’s package take promotions. Offer lines and a package line that switches or amends a member take none, and neither does a renewal order. A promotion on a package or offering reduces the package line, never again the lines it generates.
Conditions
All conditions must hold together: signed_in, customer (verified customers only),
package, package_offering, company, company_location, market,
sales_channel, minimum_subtotal and item_quantity. A package condition holds for the
buyer’s packages that count, not for the package the cart shops in, so money off for a club’s
members in the normal shop is a promotion with a package condition, optionally with a
customer_limit that caps each buyer’s uses, counted per email. A company condition holds for the
company’s own carts and its locations’. minimum_subtotal lists one amount per currency and holds when the lines that take
promotions add up to it, at their prices before any discount and without separately added tax.
item_quantity names a target, like an item effect, with min_quantity and an optional
max_quantity, both included: it holds when the cart’s units matching the target, counted across
its lines before any discount, fall in that range. Quantity discounts are a code whose
item_quantity condition and item effect name the same goods, such as at least 20 cartons of milk
for 15% off those cartons; ranges such as 20 to 49 and 50 and more are two promotions.
All the fixed amounts and the minimum of one promotion list the same currencies. A promotion with fixed amounts or a minimum applies only in carts whose currency they list; a promotion with only percentages applies in any currency.
A condition or target that lists records lists at least one: a create with an empty list, or an
update that adds or changes such a condition or effect, is refused with 409 PROMOTION.EMPTY_LIST.
Deleting a category or erasing a customer can still empty a list later; an empty list matches
nothing, so a promotion never opens up to everyone.
Create, Read, Update, Delete
/v1/stores/{store_id}/promotions sdk.eshop.promotion.create() /v1/stores/{store_id}/promotions sdk.eshop.promotion.find() /v1/stores/{store_id}/promotions/{id} sdk.eshop.promotion.update() /v1/stores/{store_id}/promotions/{id}?expected_updated_at= sdk.eshop.promotion.delete() /v1/stores/{store_id}/promotion-codes sdk.eshop.promotionCode.create() /v1/stores/{store_id}/promotion-codes sdk.eshop.promotionCode.find() /v1/stores/{store_id}/promotion-codes/by-code/{code} sdk.eshop.promotionCode.getByCode() import { epochMilliseconds } from "arky-sdk/utils";
const promotion = await sdk.eshop.promotion.create({
store_id: storeId,
id: crypto.randomUUID(),
key: "summer-20",
blocks: [{ id: crypto.randomUUID(), key: "name", type: "localized_text", value: { en: "Summer sale" } }],
activation: { type: "codes" },
conditions: [{ type: "minimum_subtotal", amounts: [{ amount: 5_000, currency: "eur" }] }],
effects: [{ type: "order_percentage", id: crypto.randomUUID(), basis_points: 2_000 }],
stacking: { type: "stop_after" },
priority: 10,
limit: { type: "limited", max_uses: 1_000 },
customer_limit: { type: "limited", max_uses: 1 },
schedule: {
type: "scheduled",
starts_at: epochMilliseconds(Date.UTC(2026, 5, 1)),
ends_at: epochMilliseconds(Date.UTC(2026, 8, 1)),
},
status: { type: "active" },
});
const code = await sdk.eshop.promotionCode.create({
store_id: storeId,
id: crypto.randomUUID(),
promotion_id: promotion.id,
code: "SUMMER20",
limit: { type: "unlimited" },
status: { type: "active" },
});
const freeShipping = await sdk.eshop.promotion.create({
store_id: storeId,
id: crypto.randomUUID(),
key: "free-shipping-over-50",
blocks: [{ id: crypto.randomUUID(), key: "name", type: "localized_text", value: { en: "Free shipping over €50" } }],
activation: { type: "automatic" },
conditions: [{ type: "minimum_subtotal", amounts: [{ amount: 5_000, currency: "eur" }] }],
effects: [{ type: "delivery_percentage", id: crypto.randomUUID(), basis_points: 10_000 }],
stacking: { type: "continue" },
priority: 5,
limit: { type: "unlimited" },
customer_limit: { type: "unlimited" },
schedule: { type: "always" },
status: { type: "active" },
});
- The key is unique in the store (
409 PROMOTION.KEY_TAKEN), and so is thepriority(409 PROMOTION.PRIORITY_TAKEN). A code is unique in the store (409 PROMOTION_CODE.CODE_TAKEN). blockshold what a storefront or an email shows for the promotion, such as its name and terms. Every email that carries an order lists each promotion the order applied with its currentblocksatorder.promotions, read when the email is made and never stored on the order.scheduleis{ type: "always" }or{ type: "scheduled", starts_at, ends_at }, whereends_atmay benullfor “from then on”. Codes share their promotion’s dates.limitcaps a promotion’s uses in all, and a code’s, as{ type: "limited", max_uses }or{ type: "unlimited" }. A promotion is eligible while it isactive, inside its schedule and under itslimit, and its conditions hold; a promotion with codes also needs the cart to carry one of its active codes under that code’s ownlimit. An eligible promotion applies only when one of its effects takes something off this cart.customer_limitcaps a promotion’s uses per email in the same shape. A limited one counts a signed-in customer by their verified email and a guest by the checkout’s contact email, so a guest checkout using such a code needs one. An automatic promotion with a limitedcustomer_limitapplies only when the checkout carries an email still under it, and never refuses a checkout.- A promotion or code with a
limitedlimit takes its use when checkout is accepted, in the same write as the order, so its cap is never passed. One with anunlimitedlimit keeps no counter on its record: its uses are counted a moment after checkout and read back as itsuses. Whether a promotion or a code has a cap is fixed when it is made (409 PROMOTION.MAX_USES_FIXED); an edit may change a limited cap’smax_uses. An edit may changecustomer_limiteither way. A stopped promotion, or one that takes nothing off, takes no use. An order the buyer never pays gives its uses back once all its lines end expired or payment failed; any other cancellation gives nothing back. A use changes onlyuses, never the promotion’s or the code’supdated_at, so an edit loaded before it still saves. - A store holds at most 100 active automatic promotions (
409 PROMOTION.AUTOMATIC_LIMIT), and switching one on is refused when the store’s active automatic promotions together would pass what one quote evaluates (409 PROMOTION.EVALUATION_LIMIT), because a shopper can’t take an automatic promotion off a cart. - An update sends the
expected_updated_atit read and the complete conditions and effects. - A code can be deleted while only carts name it; deleting takes it off those carts. A promotion can be deleted while only its own codes name it; a promotion an order names is archived instead.
- Webhooks post
promotion.created,promotion.updated,promotion.deleted,promotion_code.createdandpromotion_code.deleted. Uses taken or given back don’t postpromotion.updated.
In The Cart
The storefront sets the codes on the cart and reads the discount from the quote:
const cart = arky.eshop.cart({ buyer: { type: "customer" }, package_id: shopPackage.id });
const kept = cart.promotion_codes.get().map((entry) => entry.code);
await cart.setPromotionCodes({ promotion_codes: [...kept, "SUMMER20"] });
const quote = await cart.quote({ contact_email: "[email protected]" });
const notApplied = quote.promotion_codes.filter((entry) => entry.state !== "applied");
console.log(quote.totals.discount, quote.promotions, notApplied);
- Codes and automatic promotions sit in one order by their unique
priority.stackingsays what a promotion does to those below it:continuelets them apply, and astop_afterpromotion that takes money off stops every promotion below it, their item, order and delivery effects alike; one that takes nothing off stops none. Checkout never compares discounts: the order decides. - A cart may hold several codes, and nothing is refused for stacking.
setPromotionCodesreplaces the whole list, so pass the codes you keep plus the new one. The quote lists every code the cart holds inpromotion_codes, each with itsstate:applied,stopped(a promotion above it stopped it) ornot_applied(its conditions don’t hold, it takes nothing off this cart, or another code of the same promotion applied first). Show “code not applied” for the last two: they spend no use and stay in the cart, applying as soon as the cart lets them. The cart store’spromotion_codesatom holds the same list. - A code whose promotion has a limited
customer_limitcounts a guest by the contact email, so a guest’s quote sendscontact_emailonce it is known; without it such a code’s quote is refused with409 CART.PROMOTION_EMAIL_REQUIRED. The checkout flow sends it aftersetContact. - Storefront code never computes its own discounted total. The quote and checkout check each
promotion against the cart, and the order keeps each promotion it applied with its key and its
activation: thecodeit applied through, orautomatic.
To show a promotion’s name or terms on the storefront, read its blocks by id:
/v1/storefront/promotions/{id} arky.eshop.promotion.get() const shown = await arky.eshop.promotion.get({ id: quote.promotions[0].promotion_id });
The storefront reads an active or archived promotion’s id, key and blocks only, never its
conditions or counters.