-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pricing, types): add price rule operators to price calculations (#…
…10350) what: - adds price rule operators when doing price calculations - rules now accepts a key where the value can be an array of objects `({ operator: string, value: number })` - validation for available types of operator and value to be a number ``` await service.createPriceSets({ prices: [ { amount: 50, currency_code: "usd", rules: { region_id: "de", cart_total: [ { operator: "gte", value: 400 }, { operator: "lte", value: 500 }, ] }, }, ] }) ``` - price calculations will now account for the operators - lte, gte, lt, gt when the price context is a number RESOLVES CMRC-747
- Loading branch information
Showing
8 changed files
with
462 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@medusajs/pricing": patch | ||
"@medusajs/types": patch | ||
--- | ||
|
||
feat(pricing, types): add price rule operators to price calculations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/modules/pricing/integration-tests/__fixtures__/price-rule/operators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { RuleWithOperator } from "@medusajs/types" | ||
|
||
export const withOperator = ( | ||
border, | ||
min = 400, | ||
max = 800 | ||
): RuleWithOperator[] => { | ||
if (border === "betweenEquals") { | ||
return [ | ||
{ operator: "gte", value: min }, | ||
{ operator: "lte", value: max }, | ||
] | ||
} else if (border === "between") { | ||
return [ | ||
{ operator: "gt", value: min }, | ||
{ operator: "lt", value: max }, | ||
] | ||
} else if (border === "excludingMin") { | ||
return [ | ||
{ operator: "gt", value: min }, | ||
{ operator: "lte", value: max }, | ||
] | ||
} else if (border === "excludingMax") { | ||
return [ | ||
{ operator: "gte", value: min }, | ||
{ operator: "lt", value: max }, | ||
] | ||
} else if (border === "gt") { | ||
return [{ operator: "gt", value: min }] | ||
} else if (border === "lt") { | ||
return [{ operator: "lt", value: min }] | ||
} else if (border === "lte") { | ||
return [{ operator: "lte", value: min }] | ||
} else if (border === "gte") { | ||
return [{ operator: "gte", value: min }] | ||
} else { | ||
return [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.