PromotionHandler
class, once they've been checked for eligibility.actions
and rules
. When a promotion is activated, the actions for the promotion are performed, passing in the payload from the fire_event
call that triggered the activator becoming active. Rules are used to determine if a promotion meets certain criteria in order to be applicable.code
or a path
configured for it, the promotion will only be activated if the payload's code or path match the promotion's. The code
attribute is used for promotion codes, where a user must enter a code to receive the promotion, and the path
attribute is used to apply a promotion once a user has visited a specific path.usage_limit
attribute set, which restricts how many times the promotion can be used.CreateAdjustment
action 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_rules
to determine if the promotion is still eligible based on its rules. For how this process works, please see the rules section below.CreateItemAdjustments
action is undertaken, an adjustment is automatically applied to each item within the order unless the action has already been performed on that line itemFreeShipping
action 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.CreateLineItem
action 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:promotion
method within any Spree::PromotionAction
.config/initializers/spree.rb
:config/locales/en.yml
: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.User
The 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 Ordersmatch_policy
attribute on the Promotion
object. 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 true
or false
to indicate if the promotion should be eligible for an order. You can retrieve promotion information by calling promotion
.actionable?
to return true if the specified line item meets the criteria for promotion. It should return true
or false
to 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/initializers/spree.rb
:app/models/spree/promotion/rules/my_promotion_rule.rb
app/views/spree/admin/promotions/rules/_my_promotion_rule.html.erb
.config/locales/en.yml
and add the following to support our new example rule: