From 93d7a93b2806d7e7660a6702c9e9b60d01dfe936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Lindstr=C3=B8m=20Hansen?= Date: Tue, 5 Aug 2025 13:10:29 +0200 Subject: [PATCH] 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> --- .changeset/khaki-buses-look.md | 5 +++++ .../evaluate-rule-value-condition.spec.ts | 10 ++++++++++ .../promotion/src/utils/validations/promotion-rule.ts | 5 ++++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/khaki-buses-look.md diff --git a/.changeset/khaki-buses-look.md b/.changeset/khaki-buses-look.md new file mode 100644 index 0000000000..d88b627e28 --- /dev/null +++ b/.changeset/khaki-buses-look.md @@ -0,0 +1,5 @@ +--- +"@medusajs/promotion": patch +--- + +chore(promotion): in operator work as In insted of equal logic diff --git a/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/evaluate-rule-value-condition.spec.ts b/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/evaluate-rule-value-condition.spec.ts index 760fda29ff..1a3a4a138b 100644 --- a/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/evaluate-rule-value-condition.spec.ts +++ b/packages/modules/promotion/integration-tests/__tests__/services/promotion-module/evaluate-rule-value-condition.spec.ts @@ -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" diff --git a/packages/modules/promotion/src/utils/validations/promotion-rule.ts b/packages/modules/promotion/src/utils/validations/promotion-rule.ts index dd6716c9c9..a71a5141af 100644 --- a/packages/modules/promotion/src/utils/validations/promotion-rule.ts +++ b/packages/modules/promotion/src/utils/validations/promotion-rule.ts @@ -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}`))