Skip to main content

Overview

Promotions within Spree are used to provide discounts to orders, offer free shipping or to add potential additional items at no extra cost (eg. samples). Promotions are one of the most complex areas within Spree, as there are a large number of moving parts to consider. Although this guide will explain Promotions from a developer’s perspective, if you are new to this area you can learn a lot from the Admin > Promotions tab where you can set up new Promotions, edit rules & actions, etc. Promotions can be activated in three different ways:
  • When a user adds a product to their cart (automatic promotions, eg. free shipping with a threshold)
  • When a user enters a coupon code during the checkout process
  • When a user visits a page within the Spree store (path-based promotions, eg. a promotion that offers a discount on a specific page)
Promotions for these individual ways are activated through their corresponding PromotionHandler class, once they’ve been checked for eligibility. Promotions relate to two other main components: 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. Here is a table showcasing the attributes of the Spree::Promotion model along with a description for each attribute and example values:
AttributeDescriptionExample Value
nameThe name of the promotionSummer Sale
descriptionA brief description of the promotionDiscounts for summer
expires_atThe expiration date and time of the promotion2025-09-01 23:59:59
starts_atThe start date and time of the promotion2025-06-01 00:00:00
codeA code that users can enter to apply the promotionSUMMER2023
usage_limitThe total number of times the promotion can be used500
match_policyThe policy for how promotion rules are matchedall
pathThe specific path that activates the promotion/summer-sale
per_code_usage_limitThe number of times a single code can be used1
Path-based promotions will only work when the Spree::PromotionHandler::Page class is used, as in Spree::ContentController from spree_rails_frontend gem

Actions

There are four actions that come with Spree:

When a CreateAdjustment action is undertaken, an adjustment is automatically applied to the order, unless the promotion has already applied an adjustment to the order.

Once the adjustment has been applied to the order, its eligibility is re-checked every time the order is saved, by way of the 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.

An adjustment to order from a promotion depends on the calculators. For more information about calculators, please see the Calculators guide.

When a 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 item.

The eligibility of the item for this promotion is re-checked whenever the item is updated. Its eligibility is based on the rules of the promotion.

An adjustment to order from a promotion depends on the calculators. For more information about calculators, please see the Calculators guide.

When a FreeShipping 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.

When a 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.

Rules

Here’s a list of all the rules that come with Spree:
The user’s order is their first.
The order’s total is greater than (or equal to) a given value.
An order contains a specific product.
The order is by a specific user. Only customers who have an account can use this rule.
The user is logged in.
Can be used only once per customer. Only customers who have an account can use this rule.
Order includes product(s) associated with Taxons that are selected for this rule.
Checks if Order’s ship address country matches the selected country, eg. US-only Orders
Rules are used by Spree to determine if a promotion is applicable to an order and can be matched in one of two ways: all of the rules must match, or one rule must match. This is determined by the match_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.

Extending Promotions

Please follow our extending Promotions guide to learn how to create custom promotion rules and actions.