You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: www/apps/book/public/llms-full.txt
+70-35Lines changed: 70 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -32562,7 +32562,7 @@ Each of these prices is represented by the [Price data model](#price-data-model)
32562
32562
32563
32563
A [PriceList](https://docs.medusajs.com/references/pricing/models/PriceList/index.html.md) is a group of prices that are only enabled when their conditions and rules are satisfied. For example, you can apply special prices to customers in the VIP group.
32564
32564
32565
-
When the conditions are met, the prices in the price list override the default prices in a price set.
32565
+
When the conditions are met, the prices in the price list can override the default prices in a price set. Learn more in the [Price Calculation](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/pricing/price-calculation/index.html.md) guide.
32566
32566
32567
32567
A price list has optional `start_date` and `end_date` properties that indicate the date range in which a price list can be applied.
32568
32568
@@ -32909,17 +32909,19 @@ Learn more about workflows in [this documentation](https://docs.medusajs.com/doc
32909
32909
32910
32910
# Prices Calculation
32911
32911
32912
-
In this document, you'll learn how prices are calculated when you use the [calculatePrices method](https://docs.medusajs.com/references/pricing/calculatePrices/index.html.md) of the Pricing Module's main service.
32912
+
In this guide, you'll learn how prices are calculated when you use the [calculatePrices method](https://docs.medusajs.com/references/pricing/calculatePrices/index.html.md) of the Pricing Module's main service.
32913
32913
32914
32914
## calculatePrices Method
32915
32915
32916
-
The [calculatePrices method](https://docs.medusajs.com/references/pricing/calculatePrices/index.html.md) accepts as parameters the ID of one or more price sets and a context.
32916
+
The [calculatePrices method](https://docs.medusajs.com/references/pricing/calculatePrices/index.html.md) accepts the ID of one or more price sets and a context as parameters.
32917
32917
32918
-
It returns a price object with the best matching price for each price set.
32918
+
It returns a price object with the best-matching price for each price set.
32919
+
32920
+
The `calculatePrices` method is useful for retrieving the prices of a product variant or a shipping option that matches a specific context, such as a currency code, in your backend customizations.
32919
32921
32920
32922
### Calculation Context
32921
32923
32922
-
The calculation context is an optional object passed as a second parameter to the `calculatePrices` method. It accepts rules to restrict the selected prices in the price set.
32924
+
The calculation context is an optional object passed as the second parameter to the `calculatePrices` method. It accepts rules as key-value pairs to restrict the selected prices in the price set.
@@ -32943,19 +32945,19 @@ For each price set, the `calculatePrices` method selects two prices:
32943
32945
32944
32946
- A calculated price: Either a price that belongs to a price list and best matches the specified context, or the same as the original price.
32945
32947
- An original price, which is either:
32946
-
- The same price as the calculated price if the price list it belongs to is of type `override`;
32947
-
- Or a price that doesn't belong to a price list and best matches the specified context.
32948
+
- The same price as the calculated price if it belongs to a price list of type `override`;
32949
+
- Otherwise, a price that doesn't belong to a price list and [best matches](#original-price-selection-logic) the specified context.
32948
32950
32949
-
Both prices are returned in an object that has the following properties:
32951
+
Both prices are returned in an object with the following properties:
32950
32952
32951
32953
- id: (\`string\`) The ID of the price set from which the price was selected.
32952
32954
- is\_calculated\_price\_price\_list: (\`boolean\`) Whether the calculated price belongs to a price list.
32953
32955
- calculated\_amount: (\`number\`) The amount of the calculated price, or \`null\` if there isn't a calculated price. This is the amount shown to the customer.
32954
32956
- is\_original\_price\_price\_list: (\`boolean\`) Whether the original price belongs to a price list.
32955
-
- original\_amount: (\`number\`) The amount of the original price, or \`null\` if there isn't an original price. This amount is useful to compare with the \`calculated\_amount\`, such as to check for discounted value.
32957
+
- original\_amount: (\`number\`) The amount of the original price, or \`null\` if there isn't an original price. This amount is useful for comparing with the \`calculated\_amount\`, such as to check for a discounted value.
32956
32958
- currency\_code: (\`string\`) The currency code of the calculated price, or \`null\` if there isn't a calculated price.
32957
-
- is\_calculated\_price\_tax\_inclusive: (\`boolean\`) Whether the calculated price is tax inclusive. Learn more about tax-inclusivity in \[this document]\(../tax-inclusive-pricing/page.mdx)
32958
-
- is\_original\_price\_tax\_inclusive: (\`boolean\`) Whether the original price is tax inclusive. Learn more about tax-inclusivity in \[this document]\(../tax-inclusive-pricing/page.mdx)
32959
+
- is\_calculated\_price\_tax\_inclusive: (\`boolean\`) Whether the calculated price is tax inclusive. Learn more about taxinclusivity in \[this document]\(../tax-inclusive-pricing/page.mdx)
32960
+
- is\_original\_price\_tax\_inclusive: (\`boolean\`) Whether the original price is tax inclusive. Learn more about taxinclusivity in \[this document]\(../tax-inclusive-pricing/page.mdx)
32959
32961
- calculated\_price: (\`object\`) The calculated price's price details.
32960
32962
32961
32963
- id: (\`string\`) The ID of the price.
@@ -32964,9 +32966,9 @@ Both prices are returned in an object that has the following properties:
32964
32966
32965
32967
- price\_list\_type: (\`string\`) The price list's type. For example, \`sale\`.
32966
32968
32967
-
- min\_quantity: (\`number\`) The price's min quantity condition.
32969
+
- min\_quantity: (\`number\`) The price's minimum quantity condition.
32968
32970
32969
-
- max\_quantity: (\`number\`) The price's max quantity condition.
32971
+
- max\_quantity: (\`number\`) The price's maximum quantity condition.
32970
32972
- original\_price: (\`object\`) The original price's price details.
32971
32973
32972
32974
- id: (\`string\`) The ID of the price.
@@ -32975,51 +32977,65 @@ Both prices are returned in an object that has the following properties:
32975
32977
32976
32978
- price\_list\_type: (\`string\`) The price list's type. For example, \`sale\`.
32977
32979
32978
-
- min\_quantity: (\`number\`) The price's min quantity condition.
32980
+
- min\_quantity: (\`number\`) The price's minimum quantity condition.
32981
+
32982
+
- max\_quantity: (\`number\`) The price's maximum quantity condition.
32983
+
32984
+
### Original Price Selection Logic
32979
32985
32980
-
- max\_quantity: (\`number\`) The price's max quantity condition.
32986
+
When the calculated price isn't from a price list of type `override`, the original price is selected based on the following logic:
32987
+
32988
+

32989
+
32990
+
1. If the context doesn't have any rules, select the default price (the price without any rules).
32991
+
2. If the context has rules and there's a price that matches all the rules, select that price.
32992
+
3. If the context has rules and there's no price that matches all the rules:
32993
+
- Find all the prices whose rules match at least one rule in the context.
32994
+
- Sort the matched prices by the number of matched rules in descending order.
32995
+
- Select the first price in the sorted list (the one that matches the most rules).
32981
32996
32982
32997
***
32983
32998
32984
32999
## Examples
32985
33000
32986
-
Consider the following price set:
33001
+
Consider the following price set, which has a default price, prices with rules, and tiered pricing:
Copy file name to clipboardExpand all lines: www/apps/resources/app/commerce-modules/pricing/concepts/page.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ Each of these prices is represented by the [Price data model](#price-data-model)
30
30
31
31
A [PriceList](/references/pricing/models/PriceList) is a group of prices that are only enabled when their conditions and rules are satisfied. For example, you can apply special prices to customers in the VIP group.
32
32
33
-
When the conditions are met, the prices in the price list override the default prices in a price set.
33
+
When the conditions are met, the prices in the price list can override the default prices in a price set. Learn more in the [Price Calculation](../price-calculation/page.mdx) guide.
34
34
35
35
A price list has optional `start_date` and `end_date` properties that indicate the date range in which a price list can be applied.
0 commit comments