Introduction
🎯 What does this module do?
The Discounts module lets you manage and apply discounts to products and orders - from percentage-based promotions to fixed-amount reductions - supporting coupon codes, category discounts, and customer-specific offers throughout your e-commerce store.
Think of it as your promotions engine - define discount rules in OneEntry admin panel, apply them to products or entire orders, validate coupon codes at checkout, and automate pricing adjustments for your customers.
📖 Simple Explanation
Every e-commerce store needs flexible discounting:
- 🏷️ Percentage Discounts - 10% off selected products
- 💰 Fixed Discounts - $5 off orders over $50
- 🎟️ Coupon Codes - Promo codes for specific campaigns
- 📦 Category Discounts - Discounts on entire product categories
- 👤 Customer Discounts - Special pricing for specific customers or groups
- 📅 Time-limited Offers - Sales with defined start and end dates
Issues without discounts management:
- 🔒 Inflexible pricing - Need code changes for every promotion
- 📊 Hard to track - No centralized discount management
- 🔄 No automation - Manual price updates for each sale
The Discounts solution:
Benefits:
- 🔒 Flexible promotions - Create and manage discounts in admin panel
- 📊 Centralized control - All discounts in one place
- 🔄 Automated application - Discounts applied automatically at checkout
- 🎟️ Coupon validation - Real-time coupon code verification
✨ Key Concepts
What is a Discount?
A Discount is a pricing rule that reduces the cost of products or orders:
- Discount Type - Percentage (e.g., 20%) or fixed amount (e.g., $10)
- Discount Value - The amount or percentage to reduce
- Marker - Unique identifier for filtering and referencing
- Validity Period - Optional start and end dates
- Coupon Code - Optional promo code for customer-triggered discounts
Discount Structure
Each discount has this structure:
{
id: 1,
identifier: 'summer_sale',
localizeInfos: {
title: 'Summer Sale'
},
discountType: 'percentage',
discountValue: 20,
isActive: true,
validFrom: '2025-06-01T00:00:00.000Z',
validTo: '2025-08-31T23:59:59.999Z',
}
Discount Types
| Type | Description | Example |
|---|---|---|
| percentage | Reduce price by a percentage | 20% off all summer items |
| fixed | Reduce price by a fixed amount | $10 off orders over $50 |
Common Discount Operations
| Operation | Description | Example Use Case |
|---|---|---|
| Get All Discounts | List all available discounts | Admin discount management |
| Get Discount by Marker | Fetch a specific discount | Display discount badge |
| Validate Coupon | Check if a coupon code is valid | Checkout coupon field |
Why Use Discounts Module?
| Benefit | Description |
|---|---|
| Automated Promotions | No manual price editing for each sale |
| Coupon Management | Create, distribute, and validate promo codes |
| Flexible Rules | Percentage, fixed, category, or customer discounts |
| Time-bound Offers | Schedule campaigns with start/end dates |
| Multi-Language Support | Discount names localized per language |
📋 What You Need to Know
Discounts are Created in Admin Panel
You cannot create discounts via the SDK - they're created in the OneEntry admin panel.
Creation Process:
- Provide a Name - Discount designation (required)
- Provide a Marker - Unique identifier (required)
- Select Discount Type - Percentage or fixed amount
- Set Discount Value - The reduction amount
- Optionally set Validity Period - Start and end dates
Coupon Validation
Use validateDiscountsCoupon() at checkout to verify coupon codes in real time before applying them to an order.
💡 Important Notes
Discounts are Created in Admin Panel
The Discounts module handles:
- ✅ Fetching all active discounts
- ✅ Retrieving a specific discount by marker
- ✅ Validating coupon codes at checkout
- ❌ Does NOT create or modify discounts (use admin panel)
Your responsibility:
- Display discount badges on product listings
- Apply coupon input fields at checkout
- Show discount totals in cart/order summary
📊 Quick Reference Table
| Method | Description |
|---|---|
| getAllDiscounts() | Get all discounts |
| getDiscountByMarker() | Get a single discount by marker |
| validateDiscountsCoupon() | Validate a discount coupon code |
❓ Common Questions (FAQ)
How do I apply a discount at checkout?
Fetch the discount using getDiscountByMarker() or validate a coupon code with validateDiscountsCoupon(). Use the returned discount value to calculate the reduced price on the client side before creating the order.
Can a discount have an expiration date?
Yes! Discounts can have optional validFrom and validTo fields. Check these fields when displaying discounts to ensure they are currently active.
How do I show discount badges on products?
Fetch all discounts with getAllDiscounts(), then match discounts to products based on your business logic. Render a badge using the discount's localizeInfos.title and discountValue.
What happens if a coupon code is invalid?
validateDiscountsCoupon() returns false if the coupon does not exist or has expired. Show an appropriate error message to the customer.
🎓 Best Practices
- Cache discounts on load - They change infrequently; avoid repeated API calls
- Validate coupons server-side - Always verify before applying to an order
- Show discount clearly - Display original and discounted prices together
- Handle expired discounts - Check
validTobefore displaying a discount - Use descriptive markers -
summer_sale_2025, notdiscount1 - Localize discount names - Use
localizeInfosfor multi-language support
More information about the module's user interface https://doc.oneentry.cloud/docs/category/discounts
Definition of the Discounts module
const { Discounts } = defineOneEntry( "your-project-url", { "token": "your-app-token" });
🔗 Related Documentation
- Products Module - Manage products that discounts are applied to
- Orders Module - Create orders with discounts applied
- Payments Module - Process payments for discounted orders
- Locales Module - Multi-language discount names