docs: document how prices are stored in Medusa (#13362)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-09-01 10:10:28 +03:00
1 parent c71ad3ff61
commit 72675c59ec
6 files changed
+67 -31

No files matched your search

+28 -10
View File
@@ -22794,6 +22794,14 @@ In Medusa v2, the price selection process is now implemented in the [Pricing Mod
If your use case is complex and these rules are not enough, you can create a new [module](https://docs.medusajs.com/learn/fundamentals/modules/index.html.md) with the necessary logic, then use that module in your custom workflows.
## Prices are Stored in Base Units
In Medusa v1, prices were stored in the smallest currency unit. For example, a price of $10.00 was stored as `1000` (cents).
In Medusa v2, prices are stored in the base unit. For example, a price of $10.00 is stored as `10` (dollars).
Learn more in the [Pricing Concepts](https://docs.medusajs.com/resources/commerce-modules/pricing/concepts/index.html.md) guide.
### Gift Card Features
Medusa v1 has gift card features out-of-the-box.
@@ -32182,11 +32190,21 @@ View the full flow of the webhook event processing in the [processPaymentWorkflo
In this document, you’ll learn about the main concepts in the Pricing Module.
## Price Data Model
The [Price](https://docs.medusajs.com/references/pricing/models/Price/index.html.md) data model represents a specific price for a resource. For example, the price of a product variant in the USD currency.
The `Price` data model has an `amount` property that represents the monetary value of the price. It's stored as an integer in base units. For example, `$20.00` is stored as `20`.
The `Price` data model belongs to other data models like `PriceSet` and `PriceList` to provide a variety of pricing features, as explained below.
***
## Price Set
A [PriceSet](https://docs.medusajs.com/references/pricing/models/PriceSet/index.html.md) represents a collection of prices that are linked to a resource (for example, a product or a shipping option).
A [PriceSet](https://docs.medusajs.com/references/pricing/models/PriceSet/index.html.md) represents a collection of prices that are linked to a resource (for example, a product variant or a shipping option).
Each of these prices are represented by the [Price data module](https://docs.medusajs.com/references/pricing/models/Price/index.html.md).
Each of these prices is represented by the [Price data model](https://docs.medusajs.com/references/pricing/models/Price/index.html.md).
![A diagram showcasing the relation between the price set and price](https://res.cloudinary.com/dza7lstvk/image/upload/v1709648650/Medusa%20Resources/price-set-money-amount_xeees0.jpg)
@@ -32622,27 +32640,27 @@ const priceSet = await pricingModuleService.createPriceSets({
prices: [
// default price
{
amount: 500,
amount: 5,
currency_code: "EUR",
rules: {},
},
// prices with rules
{
amount: 400,
amount: 4,
currency_code: "EUR",
rules: {
region_id: "reg_123",
},
},
{
amount: 450,
amount: 4.5,
currency_code: "EUR",
rules: {
city: "krakow",
},
},
{
amount: 500,
amount: 5,
currency_code: "EUR",
rules: {
city: "warsaw",
@@ -32650,7 +32668,7 @@ const priceSet = await pricingModuleService.createPriceSets({
},
},
{
amount: 200,
amount: 2,
currency_code: "EUR",
min_quantity: 100,
},
@@ -32707,7 +32725,7 @@ const price = await pricingModuleService.calculatePrices(
items: [
{
id: "item_1",
quantity: 200,
quantity: 2,
// assuming the price set belongs to this variant
variant_id: "variant_1",
// ...
@@ -32738,12 +32756,12 @@ const priceList = pricingModuleService.createPriceLists([{
type: "sale",
prices: [
{
amount: 400,
amount: 4,
currency_code: "EUR",
price_set_id: priceSet.id,
},
{
amount: 450,
amount: 4.5,
currency_code: "EUR",
price_set_id: priceSet.id,
},