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 adds 10 or more of the variant to the cart.
  • $6 when the customer adds 20 or more of the variant to the cart.

These price definitions would look like this:

Example Prices
1[2  // default price3  {4    "amount": 10,5    "currency_code": "usd",6  },7  {8    "amount": 8,9    "currency_code": "usd",10    "min_quantity": 10,11    "max_quantity": 19,12  },13  {14    "amount": 6,15    "currency_code": "usd",16    "min_quantity": 20,17  },18],

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:

Note: For most use cases where you're building customizations in the Medusa application, it's highly recommended to use Medusa's workflows rather than using the Pricing Module directly. Medusa's workflows already implement extensive functionalities that you can re-use in your custom flows, with reliable roll-back mechanism.

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.

Note: If there are other rules applied to the price, they may affect the price calculation. Keep reading to learn about other price rules, and refer to the Price Calculation guide for more details on the calculation mechanism.

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 diagram showcasing the relation between the PriceRule and Price

A price can have multiple price rules.

For example, a price can be restricted by a region and a zip code.

A diagram showcasing the relation between the PriceRule and Price with multiple rules.

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.

A diagram showcasing the relation between the PriceSet, PriceList, Price, RuleType, and PriceListRuleValue

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:

Note: For most use cases where you're building customizations in the Medusa application, it's highly recommended to use Medusa's workflows rather than using the Pricing Module directly. Medusa's workflows already implement extensive functionalities that you can re-use in your custom flows, with reliable roll-back mechanism.

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:

Code
1{2  "currency_code": "usd",3  "amount": 0,4  "rules": {5    "item_total": {6      "operator": "gte",7      "value": 100,8    }9  }10}

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:

Code
1{2  "currency_code": "usd",3  "amount": 0,4  "rules": {5    "customer.group.id": {6      "operator": "eq",7      "value": "cusgrp_123"8    }9  }10}

In this example, the price is only applied if a cart's customer belongs to the customer group of ID cusgrp_123.

Note: These same rules apply to product variant prices as well, or any other resource that has a price.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break