fix(promotion): don't evaluate rule condition if conditions to evaluate is empty (#10795)

This commit is contained in:
Riqwan Thamir
2025-01-06 09:31:58 +01:00
committed by GitHub
parent 95b61bf2da
commit f7ffa3540f
3 changed files with 43 additions and 0 deletions

View File

@@ -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 () => {

View File

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