fix(promotion): don't evaluate rule condition if conditions to evaluate is empty (#10795)
This commit is contained in:
1 parent
95b61bf2da
commit
f7ffa3540f
3 files changed
+43
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/promotion": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(promotion): don't evaluate rule condition if conditions to evaluate is empty
|
||||||
+34
@@ -132,6 +132,40 @@ moduleIntegrationTestRunner({
|
|||||||
code: "PROMOTION_TEST",
|
code: "PROMOTION_TEST",
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const resultWithoutCustomer = await service.computeActions(
|
||||||
|
["PROMOTION_TEST"],
|
||||||
|
{
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
id: "item_cotton_tshirt",
|
||||||
|
quantity: 1,
|
||||||
|
subtotal: 100,
|
||||||
|
product_category: {
|
||||||
|
id: "catg_cotton",
|
||||||
|
},
|
||||||
|
product: {
|
||||||
|
id: "prod_tshirt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "item_cotton_sweater",
|
||||||
|
quantity: 5,
|
||||||
|
subtotal: 750,
|
||||||
|
product_category: {
|
||||||
|
id: "catg_cotton",
|
||||||
|
},
|
||||||
|
product: {
|
||||||
|
id: "prod_sweater",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(JSON.parse(JSON.stringify(resultWithoutCustomer))).toEqual(
|
||||||
|
[]
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should compute the correct item amendments when there are multiple promotions to apply", async () => {
|
it("should compute the correct item amendments when there are multiple promotions to apply", async () => {
|
||||||
|
|||||||
@@ -115,6 +115,10 @@ export function evaluateRuleValueCondition(
|
|||||||
ruleValuesToCheck = [ruleValuesToCheck]
|
ruleValuesToCheck = [ruleValuesToCheck]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ruleValuesToCheck.length) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return ruleValuesToCheck.every((ruleValueToCheck: string) => {
|
return ruleValuesToCheck.every((ruleValueToCheck: string) => {
|
||||||
if (operator === "in" || operator === "eq") {
|
if (operator === "in" || operator === "eq") {
|
||||||
return ruleValues.some((ruleValue) => ruleValue === ruleValueToCheck)
|
return ruleValues.some((ruleValue) => ruleValue === ruleValueToCheck)
|
||||||
|
|||||||
Reference in new issue
Block a user