fix(promotion): don't evaluate rule condition if conditions to evaluate is empty (#10795)
This commit is contained in:
5
.changeset/selfish-coats-drop.md
Normal file
5
.changeset/selfish-coats-drop.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/promotion": patch
|
||||
---
|
||||
|
||||
fix(promotion): don't evaluate rule condition if conditions to evaluate is empty
|
||||
@@ -132,6 +132,40 @@ moduleIntegrationTestRunner({
|
||||
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 () => {
|
||||
|
||||
@@ -115,6 +115,10 @@ export function evaluateRuleValueCondition(
|
||||
ruleValuesToCheck = [ruleValuesToCheck]
|
||||
}
|
||||
|
||||
if (!ruleValuesToCheck.length) {
|
||||
return false
|
||||
}
|
||||
|
||||
return ruleValuesToCheck.every((ruleValueToCheck: string) => {
|
||||
if (operator === "in" || operator === "eq") {
|
||||
return ruleValues.some((ruleValue) => ruleValue === ruleValueToCheck)
|
||||
|
||||
Reference in New Issue
Block a user