docs: update docs changes for rules_count from number_rules (#5855)
* chore: add docs changes for rules_count from number_rules * change diagrams * undo linting * fix lint error --------- Co-authored-by: Shahed nasser <shahednasser@gmail.com>
This commit is contained in:
@@ -24,15 +24,15 @@ A `PriceSet` represents a collection of money amounts that are linked to a resou
|
||||
|
||||
### Rule Type
|
||||
|
||||
Each money amount within a price set can be a price that’s applied for different conditions. These conditions are represented as rule types.
|
||||
Each money amount within a price set can be a price that’s applied for different conditions. These conditions are represented as rule types.
|
||||
|
||||
A `RuleType` defines custom conditions. Each rule type has a unique `rule_attribute`, referenced in rule values, such as when setting a rule of a money amount.
|
||||
|
||||
### Price Rule
|
||||
|
||||
Each rule of a money amount within a price set is represented by the `PriceRule` entity, which holds the value of a rule type. The `PriceSetMoneyAmount` has a `number_rules` attribute, which indicates how many rules, represented by `PriceRule`, are applied to the money amount.
|
||||
Each rule of a money amount within a price set is represented by the `PriceRule` entity, which holds the value of a rule type. The `PriceSetMoneyAmount` has a `rules_count` attribute, which indicates how many rules, represented by `PriceRule`, are applied to the money amount.
|
||||
|
||||

|
||||

|
||||
|
||||
For example, you can create a `zip_code` rule type. Then, a money amount within the price set can have the rule value `zip_code: 10557`, indicating that the money amount can only be applied within the `10557` zip code.
|
||||
|
||||
@@ -40,13 +40,13 @@ Each money amount within the price set can have different values for the same ru
|
||||
|
||||
For example, this diagram showcases two money amounts having different values for the same rule type:
|
||||
|
||||

|
||||

|
||||
|
||||
Each money amount can have multiple rules applied to it as well.
|
||||
|
||||
For example, a money amount can have the rules `zip_code` and `region_id` applied to it. In this case, the value of each rule is represented by a `PriceRule`.
|
||||
|
||||

|
||||

|
||||
|
||||
### PriceSetRuleType
|
||||
|
||||
@@ -54,7 +54,7 @@ The `PriceSetRuleType` entity indicates what rules the money amounts can have wi
|
||||
|
||||
For example, to use the `zip_code` rule type on a money amount in a price set, the rule type must first be enabled on the price set through the `PriceSetRuleType`.
|
||||
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
@@ -64,11 +64,11 @@ A `PriceList` is a group of prices only enabled if their rules are satisfied. A
|
||||
|
||||
Its associated prices are represented by the `PriceSetMoneyAmount` entity, which is used to store the money amounts of a price set.
|
||||
|
||||
Each rule that can be applied to a price list is represented by the `PriceListRule` entity. The `number_rules` attribute of a `PriceList` indicates how many rules are applied to it.
|
||||
Each rule that can be applied to a price list is represented by the `PriceListRule` entity. The `rules_count` attribute of a `PriceList` indicates how many rules are applied to it.
|
||||
|
||||
Each rule of a price list can have more than one value, representing its values by the `PriceListRuleValue` entity.
|
||||
|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
import Tabs from "@theme/Tabs"
|
||||
import TabItem from "@theme/TabItem"
|
||||
|
||||
# Prices Calculation
|
||||
|
||||
@@ -20,11 +20,11 @@ The context is an object passed to the method. It must contain at least the `cur
|
||||
For example:
|
||||
|
||||
```ts
|
||||
import {
|
||||
import {
|
||||
initialize as initializePricingModule,
|
||||
} from "@medusajs/pricing"
|
||||
async function calculatePrice(
|
||||
priceSetId: string,
|
||||
priceSetId: string,
|
||||
currencyCode: string
|
||||
) {
|
||||
const pricingService = await initializePricingModule()
|
||||
@@ -45,11 +45,11 @@ The context object can also contain any custom rules, with the key being the `ru
|
||||
For example:
|
||||
|
||||
```ts
|
||||
import {
|
||||
import {
|
||||
initialize as initializePricingModule,
|
||||
} from "@medusajs/pricing"
|
||||
async function calculatePrice(
|
||||
priceSetId: string,
|
||||
priceSetId: string,
|
||||
currencyCode: string
|
||||
) {
|
||||
const pricingService = await initializePricingModule()
|
||||
@@ -93,7 +93,7 @@ For each price set, the method selects two money amounts:
|
||||
- If no rules are provided in the context other than the `currency_code`, the default money amount is selected as the original price. The default money amount is a money amount having no rules applied to it.
|
||||
- Otherwise, if a money amount exists in any price set with the same rules provided in the context, it's selected as the original price.
|
||||
- If no money amount exists with the same rules as the context, all money amounts satisfying any combination of the provided rules are retrieved.
|
||||
- The money amounts are sorted in descending order by the associated `PriceSetMoneyAmount`'s `number_rules`, the `default_priority` of the rule types, and the `priority` of the associated `PriceRule`. The `priority` attribute has a higher precedence than the `default_priority`.
|
||||
- The money amounts are sorted in descending order by the associated `PriceSetMoneyAmount`'s `rules_count`, the `default_priority` of the rule types, and the `priority` of the associated `PriceRule`. The `priority` attribute has a higher precedence than the `default_priority`.
|
||||
- The highest money amount sorted is selected as the original price since it's considered the best price.
|
||||
|
||||
---
|
||||
@@ -107,15 +107,17 @@ const price = {
|
||||
id: priceSetId,
|
||||
is_calculated_price_price_list:
|
||||
!!calculatedPrice?.price_list_id,
|
||||
calculated_amount: parseInt(calculatedPrice?.amount || "") ||
|
||||
null,
|
||||
calculated_amount: parseInt(
|
||||
calculatedPrice?.amount || ""
|
||||
) || null,
|
||||
|
||||
is_original_price_price_list: !!originalPrice?.price_list_id,
|
||||
original_amount: parseInt(originalPrice?.amount || "") ||
|
||||
null,
|
||||
is_original_price_price_list:
|
||||
!!originalPrice?.price_list_id,
|
||||
original_amount: parseInt(
|
||||
originalPrice?.amount || ""
|
||||
) || null,
|
||||
|
||||
currency_code: calculatedPrice?.currency_code ||
|
||||
null,
|
||||
currency_code: calculatedPrice?.currency_code || null,
|
||||
|
||||
calculated_price: {
|
||||
money_amount_id: calculatedPrice?.id || null,
|
||||
@@ -133,10 +135,12 @@ const price = {
|
||||
money_amount_id: originalPrice?.id || null,
|
||||
price_list_id: originalPrice?.price_list_id || null,
|
||||
price_list_type: originalPrice?.price_list_type || null,
|
||||
min_quantity: parseInt(originalPrice?.min_quantity || "") ||
|
||||
null,
|
||||
max_quantity: parseInt(originalPrice?.max_quantity || "") ||
|
||||
null,
|
||||
min_quantity: parseInt(
|
||||
originalPrice?.min_quantity || ""
|
||||
) || null,
|
||||
max_quantity: parseInt(
|
||||
originalPrice?.max_quantity || ""
|
||||
) || null,
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user