Made in operator work as In insted of equal logic (#13078)

Changed the In operator to actually work like an In instead of being same logic as Equals. This means that in promotions you can add a rule to apply when a product is in a category or multiple different. Before the logic had to match all the products categories to apply, which doesnt really make sense when you have nested category structure on products. The logic also applies to tags where you can make a rule apply based on a tag before it also had to match all tags on a product to apply.

Issue:

https://github.com/medusajs/medusa/issues/12669

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
Mikkel Lindstrøm Hansen
2025-08-05 13:10:29 +02:00
committed by GitHub
parent 02dd83f59a
commit 93d7a93b28
3 changed files with 19 additions and 1 deletions

View File

@@ -18,6 +18,16 @@ moduleIntegrationTestRunner({
})
})
describe("in", () => {
const operator = "in"
it("should evaluate conditions accurately", async () => {
expect(testFunc(["1", "2"], operator, [2])).toEqual(true)
expect(testFunc(["2"], operator, ["2"])).toEqual(true)
expect(testFunc(["2"], operator, ["22"])).toEqual(false)
})
})
describe("ne", () => {
const operator = "ne"

View File

@@ -117,11 +117,14 @@ export function evaluateRuleValueCondition(
}
switch (operator) {
case "in":
case "eq": {
const ruleValueSet = new Set(ruleValues)
return valuesToCheck.every((val) => ruleValueSet.has(`${val}`))
}
case "in": {
const ruleValueSet = new Set(ruleValues)
return valuesToCheck.some((val) => ruleValueSet.has(`${val}`))
}
case "ne": {
const ruleValueSet = new Set(ruleValues)
return valuesToCheck.every((val) => !ruleValueSet.has(`${val}`))