Overview
Lunar provides a discount system that supports multiple discount types out of the box, including amount-off (percentage or fixed) and buy-x-get-y promotions. Discounts can be scoped to specific channels, customer groups, collections, brands, and individual products or variants.Relationships
Scopes
Creating a Discount
Discount Status
TheDiscount model provides a status attribute that returns the current state of the discount based on its dates and usage.
Resetting the Discount Cache
For performance reasons, applicable discounts are cached per request. To reset this cache (for example, after adding a discount code to a cart), callresetDiscounts() on the Discounts facade:
Validating Coupons
TheDiscounts facade provides a method to validate whether a coupon code is valid:
config/lunar/discounts.php configuration file:
Discountable
TheDiscountable model links products, product variants, or collections to a discount. Each entry has a type that determines its role.
The
type field determines how the discountable relates to the discount:
condition— The product or variant must be in the cart for the discount to activate.exclusion— The product or variant is excluded from the discount.limitation— The discount only applies to these products or variants.reward— These products or variants are given as the reward (used by BuyXGetY).
Relationships
Built-in Discount Types
Lunar ships with two discount types. Both extendLunar\DiscountTypes\AbstractDiscountType.
AmountOff
data column stores the discount configuration:
Percentage discount:
BuyXGetY
discountableConditions relationship, and reward products through the discountableRewards relationship. Both relationships accept products, product variants, or collections.
Collection conditions and rewards Added in 1.5
ABuyXGetY discount can match against an entire collection rather than listing every product or variant individually. The match logic walks each cart line’s product, checks the collections it belongs to, and compares those against the collections attached as conditions or rewards.
Custom Discount Types
Custom discount types can be created by extendingLunar\DiscountTypes\AbstractDiscountType:
Discounts facade, typically in a service provider:
Discounts Facade
TheLunar\Facades\Discounts facade provides methods for managing and applying discounts: