k.commerce.discount
Discounts.
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
KScript API (k.api.get / k.api.post), server-side <script env="server"> | Configure discount codes or automatic discounts in the commerce admin | List configured discount rules, display coupon codes, and inspect eligibility conditions |
k.commerce.discount provides read access to configured discount codes and automatic discounts.
Quick Start
js
k.api.get(() => {
const discounts = k.commerce.discount.list()
return { count: discounts.length, items: discounts.slice(0, 3) }
})list()
Get all discounts configured in the store. No parameters.
Active Window Filtering
list() returns all configured discount rules (including not-yet-started and expired rules) without filtering by startDate or endDate. Filter by those dates in your code if you only need currently active discounts.
Returns: Discount[]
js
k.api.get(() => {
const discounts = k.commerce.discount.list()
return { count: discounts.length, items: discounts.slice(0, 3) }
})Structure
Discount property
| Property | Description | Type |
|---|---|---|
id | Discount ID | string |
code | Offer discount code | string |
title | Discount name | string |
startDate | Discount start time | string |
endDate | Discount end time | string |
condition | Discount conditions | DiscountCondition |
method | Discount methods | "DiscountCode" | "AutomaticDiscount" |
type | Offer discount type | "ProductAmountOff" | "OrderAmountOff" | "FreeShipping" |
value | Discount value | number |
isPercent | Is it a percentage discount? | boolean |
priority | Discount priority | number |
isExclusion | Are they mutually exclusive? | boolean |
codeUsageLimit | Code usage restrictions | number | null |
createdAt | Creation time | string |
updatedAt | Update time | string |
DiscountCondition Property
| Property | Description | Type |
|---|---|---|
isAny | Any one of the conditions need to be met, otherwise all conditions need to be met | boolean |
items | List of conditional items | ConditionItem[] |
ConditionItem Property
| Property | Description | Type |
|---|---|---|
option | Condition options | string |
method | Conditional method | string |
value | Condition value | string |
TypeScript Definitions
ts
interface KDiscount {
list(): Discount[];
}Related Docs
- k.commerce - E-commerce module overview
- cart - Shopping Cart
- order - Order Management