Discounts
Discount and coupon collections
Discounts
discounts
Stores discount codes (coupons/promotions).
| Field | Type | Description | Required |
|---|---|---|---|
code | text | Discount code (unique per tenant, indexed) | ✓ |
title | text | Discount name | ✓ |
type | select | Discount type | ✓ |
value | number | Discount value (except tiered) | |
tiers | array | Tiered discount rules (tiered only: minAmount, discountType, value) | |
minOrderAmount | number | Minimum order amount | |
maxDiscountAmount | number | Maximum discount amount | |
startsAt | date | Start date | |
endsAt | date | End date | |
usageLimit | number | Total usage limit | |
usageCount | number | Usage count (read-only, default: 0) | |
perCustomerLimit | number | Per-customer usage limit | |
isActive | checkbox | Active flag (default: true) | |
applicableProducts | relationship[] | Applicable products (products) | |
applicableCategories | relationship[] | Applicable categories (product-categories) |
Discount Types:
| Value | Description |
|---|---|
percentage | Percentage discount (e.g., 10%) |
fixed_amount | Fixed amount discount (e.g., $5) |
free_shipping | Free shipping |
tiered | Tiered discount (varies by order amount) |
// Create a discount
const discount = await client.from('discounts').create({
code: 'WELCOME10',
title: 'New member 10% off',
type: 'percentage',
value: 10,
minOrderAmount: 30000,
maxDiscountAmount: 10000,
isActive: true
})
// Find discount by code
const response = await client.from('discounts').find({
where: {
code: { equals: 'WELCOME10' },
isActive: { equals: true }
}
})
// List active discounts
const response = await client.from('discounts').find({
where: {
isActive: { equals: true },
endsAt: { greater_than: new Date().toISOString() }
}
})