Skip to content

Commit

Permalink
docs: update docs changes for rules_count from number_rules (#5855)
Browse files Browse the repository at this point in the history
* chore: add docs changes for rules_count from number_rules

* change diagrams

* undo linting

* fix lint error

---------

Co-authored-by: Shahed nasser <[email protected]>
  • Loading branch information
riqwan and shahednasser authored Dec 14, 2023
1 parent a6c8490 commit ae53a66
Showing 2 changed files with 30 additions and 26 deletions.
16 changes: 8 additions & 8 deletions www/apps/docs/content/experimental/pricing/concepts.md
Original file line number Diff line number Diff line change
@@ -24,37 +24,37 @@ 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.

![A diagram showcasing the relation between the PriceRule, PriceSet, MoneyAmount, RuleType, and PriceSetMoneyAmount](https://res.cloudinary.com/dza7lstvk/image/upload/v1700573982/Medusa%20Docs/Diagrams/price-rule-1_mcnnts.jpg)
![A diagram showcasing the relation between the PriceRule, PriceSet, MoneyAmount, RuleType, and PriceSetMoneyAmount](https://res.cloudinary.com/dza7lstvk/image/upload/v1702395550/Medusa%20Docs/Diagrams/price-rule-1_h7mdwg.jpg)

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.

Each money amount within the price set can have different values for the same rule type.

For example, this diagram showcases two money amounts having different values for the same rule type:

![A diagram showcasing the relation between the PriceRule, PriceSet, MoneyAmount, RuleType, and PriceSetMoneyAmount with two money amounts.](https://res.cloudinary.com/dza7lstvk/image/upload/v1700574156/Medusa%20Docs/Diagrams/price-rule-2_ejxale.jpg)
![A diagram showcasing the relation between the PriceRule, PriceSet, MoneyAmount, RuleType, and PriceSetMoneyAmount with two money amounts.](https://res.cloudinary.com/dza7lstvk/image/upload/v1702395596/Medusa%20Docs/Diagrams/price-rule-2_x5be7v.jpg)

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`.

![A diagram showcasing the relation between the PriceRule, PriceSet, MoneyAmount, RuleType, and PriceSetMoneyAmount with multiple rules.](https://res.cloudinary.com/dza7lstvk/image/upload/v1700574174/Medusa%20Docs/Diagrams/price-rule-3_j4kdfu.jpg)
![A diagram showcasing the relation between the PriceRule, PriceSet, MoneyAmount, RuleType, and PriceSetMoneyAmount with multiple rules.](https://res.cloudinary.com/dza7lstvk/image/upload/v1702395641/Medusa%20Docs/Diagrams/price-rule-3_uvwjj5.jpg)

### PriceSetRuleType

The `PriceSetRuleType` entity indicates what rules the money amounts can have within a price set. It creates a relation between the `PriceSet` and `RuleType` entities.

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`.

![A diagram showcasing the relation between the PriceSet, PriceRule, MoneyAmount, PriceSetMoneyAmount, RuleType, and PriceSetRuleType](https://res.cloudinary.com/dza7lstvk/image/upload/v1700573984/Medusa%20Docs/Diagrams/price-set-rule-type_e1l0ef.jpg)
![A diagram showcasing the relation between the PriceSet, PriceRule, MoneyAmount, PriceSetMoneyAmount, RuleType, and PriceSetRuleType](https://res.cloudinary.com/dza7lstvk/image/upload/v1702395692/Medusa%20Docs/Diagrams/price-set-rule-type_tmxbdw.jpg)

---

@@ -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.

![A diagram showcasing the relation between the PriceSet, PriceList, MoneyAmount, PriceSetMoneyAmount, RuleType, and PriceListRuleValue](https://res.cloudinary.com/dza7lstvk/image/upload/v1700574138/Medusa%20Docs/Diagrams/price-list_mtcanv.jpg)
![A diagram showcasing the relation between the PriceSet, PriceList, MoneyAmount, PriceSetMoneyAmount, RuleType, and PriceListRuleValue](https://res.cloudinary.com/dza7lstvk/image/upload/v1702395768/Medusa%20Docs/Diagrams/price-list_bjbknv.jpg)

---

40 changes: 22 additions & 18 deletions www/apps/docs/content/experimental/pricing/prices-calculation.mdx
Original file line number Diff line number Diff line change
@@ -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,
},
}
```

2 comments on commit ae53a66

@vercel
Copy link

@vercel vercel bot commented on ae53a66 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

api-reference – ./www/apps/api-reference

api-reference-git-develop-medusajs.vercel.app
docs.medusajs.com
api-reference-delta.vercel.app
api-reference-medusajs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on ae53a66 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

medusa-docs – ./www/apps/docs

medusa-docs.vercel.app
medusa-docs-medusajs.vercel.app
medusa-docs-git-develop-medusajs.vercel.app

Please sign in to comment.