Price Tiers and Rules
In this Pricing Module guide, you'll learn about tired prices, price rules for price sets and price lists, and how to add rules to a price.
Tiered Pricing#
Each price, represented by the Price data model, has two optional properties that can be used to create tiered prices:
min_quantity
: The minimum quantity that must be in the cart for the price to be applied.max_quantity
: The maximum quantity that can be in the cart for the price to be applied.
This is useful to set tiered pricing for resources like product variants and shipping options.
For example, you can set a variant's price to:
$10
by default.$8
when the customer adds10
or more of the variant to the cart.$6
when the customer adds20
or more of the variant to the cart.
These price definitions would look like this:
How to Create Tiered Prices?#
When you create prices, you can specify a min_quantity
and max_quantity
for each price. This allows you to create tiered pricing, where the price changes based on the quantity of items in the cart.
For example:
In this example, you create a product with a variant whose default price is $10
. You also add two tiered prices that set the price to $8
when the quantity is between 10
and 19
, and to $6
when the quantity is 20
or more.
How are Tiered Prices Applied?#
The price calculation mechanism considers the cart's items as a context when choosing the best price to apply.
For example, consider the customer added the variant_1
product variant (created in the workflow snippet of the above section) to their cart with a quantity of 15
.
The price calculation mechanism will choose the second price, which is $8
, because the quantity of 15
is between 10
and 19
.
Price Rule#
You can also restrict prices by advanced rules, such as a customer's group, zip code, or a cart's total.
Each rule of a price is represented by the PriceRule data model.
The Price
data model has a rules_count
property, which indicates how many rules, represented by PriceRule
, are applied to the price.
For exmaple, you create a price restricted to 10557
zip codes.
A price can have multiple price rules.
For example, a price can be restricted by a region and a zip code.
Price List Rules#
Rules applied to a price list are represented by the PriceListRule data model.
The rules_count
property of a PriceList
indicates how many rules are applied to it.
How to Create Prices with Rules?#
When you create prices, you can specify rules for each price. This allows you to create complex pricing strategies based on different contexts.
For example:
In this example, you create a shipping option whose default price is $10
. When the total of the cart or order using this shipping option is greater than $100
, the shipping option's price becomes free.
How is the Price Rule Applied?#
The price calculation mechanism considers a price applicable when the resource that this price is in matches the specified rules.
For example, a cart object has an item_total
property. So, if a shipping option has the following price:
The shipping option's price is applied when the cart's item_total
is greater than or equal to $100
.
You can also apply the rule on nested relations and properties. For example, to apply a shipping option's price based on the customer's group, you can apply a rule on the customer.group.id
attribute:
In this example, the price is only applied if a cart's customer belongs to the customer group of ID cusgrp_123
.