Determines which promotions (Reward objects used for checkout/cart offers) a purchaser or cart currently qualifies for, and resolves a promotion's stored configuration - entry codes, discount and gift settings, quiz and upload options - from the reward.properties file held against the reward. Consumed by cart pricing, checkout rules and points rule evaluation to check promotion eligibility and to read a promotion's details as a PromotionBean before applying its discount or gift behaviour.
Methods
promotions() · promotions(Boolean open, Date now) · availablePromotions(Date now, BaseEntity customer) · availablePromotions(Date now, BaseEntity customer, Boolean open) · isElligbleParticipant(BaseEntity participant, Reward promotion) · matchesParticipantSelector(Reward promo, BaseEntity entity) · matchesParticipantSelector(List<KSelectorItem> sels, Organisation entity) · participantSelectors(Reward promo) · isMatchingPromoCode(String code, Reward promotion) · getPromoEntryCodes(Reward reward) · promotionDetails(Reward reward) · loadRewardProps(Reward reward) · loadRewardProps(DirectoryNode rewardNode) · getTerms(Reward reward) · qualifiesForCheckoutPromotion(PromotionBean promoDetails, Cart cart) · countItemsForCheckoutPromotion(PromotionBean promoDetails, Cart cart) · calcFreeGiftQuantity(PromotionBean promoDetails, Cart cart)
promotions()
Returns: List<Reward>
All promotions defined for the current organisation, regardless of whether they are open or finished.
promotions(Boolean open, Date now)
Returns: PromotionsList
Finds the promotions defined for the current organisation, optionally filtered by whether they are finished as at the given date.
| Parameter | Description |
|---|---|
open | if null, all promotions are returned; if true, only promotions not finished as at now are returned; if false, only promotions finished as at now are returned |
now | the date to evaluate the open filter against |
availablePromotions(Date now, BaseEntity customer)
Returns: PromotionsList
Finds the currently open promotions the given customer is eligible to participate in. Equivalent to calling the 3-argument overload with open set to true.
| Parameter | Description |
|---|---|
now | the date used to evaluate whether a promotion is open |
customer | the profile or organisation to check eligibility for |
availablePromotions(Date now, BaseEntity customer, Boolean open)
Returns: PromotionsList
Finds the promotions defined for the current organisation that match the given date and eligibility criteria. When customer is null, only promotions with no organisation criteria and open group/org membership are returned; otherwise a promotion is included only if the customer is an eligible participant, as determined by isElligbleParticipant.
| Parameter | Description |
|---|---|
now | the date used to evaluate the open filter |
customer | the profile or organisation to check eligibility for, or null to check only date and having no organisation criteria |
open | if null, promotions are not filtered by date; if true, only promotions open as at now are included; if false, only promotions not open as at now are included |
isElligbleParticipant(BaseEntity participant, Reward promotion)
Returns: boolean
Determines whether a profile or organisation is eligible to participate in a promotion. A profile is eligible if the promotion's group criteria include the profile and, when the promotion has organisation criteria, one of the profile's primary organisations matches the promotion's organisation type and participant selectors. An organisation is eligible if the promotion's organisation criteria include it directly.
| Parameter | Description |
|---|---|
participant | the profile or organisation to check |
promotion | the promotion to check eligibility for |
matchesParticipantSelector(Reward promo, BaseEntity entity)
Returns: boolean
Checks whether an organisation matches a promotion's configured participant selectors. Always returns false for a profile entity, since participant selectors apply only to organisations.
| Parameter | Description |
|---|---|
promo | the promotion whose participant selectors are checked |
entity | the organisation to check, or a profile, which never matches |
matchesParticipantSelector(List<KSelectorItem> sels, Organisation entity)
Returns: boolean
Checks whether an organisation falls within one of a set of organisation selectors. An empty selector list matches everything.
| Parameter | Description |
|---|---|
sels | the parsed participant selectors to check against |
entity | the organisation to check |
participantSelectors(Reward promo)
Returns: List<KSelectorItem>
Parses a promotion's raw participant selector configuration into structured selector items.
| Parameter | Description |
|---|---|
promo | the promotion to read participant selectors from |
isMatchingPromoCode(String code, Reward promotion)
Returns: boolean
Checks whether the given code matches one of the promotion's configured entry codes.
| Parameter | Description |
|---|---|
code | the code entered by the user |
promotion | the promotion whose entry codes are checked |
getPromoEntryCodes(Reward reward)
Returns: String
Reads the raw, delimiter-separated entry codes configured for a promotion, if a code is required to activate it.
| Parameter | Description |
|---|---|
reward | the promotion to read entry codes from |
promotionDetails(Reward reward)
Returns: PromotionBean
Loads a promotion's configured details, read from the reward.properties file stored against the reward.
| Parameter | Description |
|---|---|
reward | the promotion to load details for |
loadRewardProps(Reward reward)
Returns: Properties
Loads the raw reward.properties file for a promotion, creating its rewards directory if it does not already exist.
| Parameter | Description |
|---|---|
reward | the promotion to load properties for |
loadRewardProps(DirectoryNode rewardNode)
Returns: Properties
Loads the reward.properties file from a reward's directory node.
| Parameter | Description |
|---|---|
rewardNode | the directory node holding the promotion's files, or null |
getTerms(Reward reward)
Returns: String
Reads the terms and conditions HTML file stored against a promotion.
| Parameter | Description |
|---|---|
reward | the promotion to read terms for |
qualifiesForCheckoutPromotion(PromotionBean promoDetails, Cart cart)
Returns: boolean
Checks whether a cart contains enough qualifying items for a checkout promotion to apply.
| Parameter | Description |
|---|---|
promoDetails | the promotion's details, including its qualifying product categories |
cart | the cart to check |
countItemsForCheckoutPromotion(PromotionBean promoDetails, Cart cart)
Returns: BigDecimal
Counts the quantity of items in a cart that qualify for a checkout promotion. If the promotion has no qualifying categories configured, the cart's total item quantity is returned; otherwise only items in one of the qualifying categories are counted.
| Parameter | Description |
|---|---|
promoDetails | the promotion's details, including its qualifying product categories |
cart | the cart to count qualifying items in |
calcFreeGiftQuantity(PromotionBean promoDetails, Cart cart)
Returns: BigDecimal
Calculates the quantity of a free gift a cart has earned under a checkout promotion, based on the quantity of qualifying items in the cart, capped at the promotion's configured maximum gift quantity.
| Parameter | Description |
|---|---|
promoDetails | the promotion's details, including its qualifying categories and maximum gift quantity |
cart | the cart to calculate the free gift quantity for |