PromotionHandlerclass, once they've been checked for eligibility.
rules. When a promotion is activated, the actions for the promotion are performed, passing in the payload from the
fire_eventcall that triggered the activator becoming active. Rules are used to determine if a promotion meets certain criteria in order to be applicable.
pathconfigured for it, the promotion will only be activated if the payload's code or path match the promotion's. The
codeattribute is used for promotion codes, where a user must enter a code to receive the promotion, and the
pathattribute is used to apply a promotion once a user has visited a specific path.
usage_limitattribute set, which restricts how many times the promotion can be used.
CreateAdjustmentaction is undertaken, an adjustment is automatically applied to the order, unless the promotion has already applied an adjustment to the order.
Promotion#eligible?method, which uses
Promotion#eligible_rulesto determine if the promotion is still eligible based on its rules. For how this process works, please see the rules section below.
CreateItemAdjustmentsaction is undertaken, an adjustment is automatically applied to each item within the order unless the action has already been performed on that line item
FreeShippingaction is undertaken, all shipments within the order have their prices negated. Just like with prior actions, the eligibility of this promotion is checked again whenever a shipment changes.
CreateLineItemaction is undertaken, a series of line items are automatically added to the order, which may alter the order's price. The promotion with an action to add a line item can also have another action to add an adjustment to the order to nullify the cost of adding the product to the order.
Spree::PromotionAction, like this:
promotionmethod within any
FirstOrder: The user's order is their first.
ItemTotal: The order's total is greater than (or equal to) a given value.
Product: An order contains a specific product.
UserThe order is by a specific user.
UserLoggedIn: The user is logged in.
One Use Per User: Can be used only once per customer.
Taxon(s): Order includes product(s) with taxons that you associate to this rule.
Country: Ship Address country used for this Order matches the selected Country, eg. US-only Orders
match_policyattribute on the
Promotionobject. As you will see in the Admin, you can set the match_policy to be "any" or "all" of the rules associated with the Promotion. When set to "any" the Promotion will be considered eligible if any one of the rules applies, when set to "all" it will be eligible only if all the rules apply.
Spree::PromotionRule, like this:
eligible?method should then return
falseto indicate if the promotion should be eligible for an order. You can retrieve promotion information by calling
actionable?to return true if the specified line item meets the criteria for promotion. It should return
falseto indicate if this line item can have a line item adjustment carried out on it.
eligible?should return true if the order contains one of the products eligible for promotion, and
actionable?should return true when the line item specified is one of the specific products for this promotion.
config/locales/en.ymland add the following to support our new example rule: