fix(promotion): percentage value is accounted for in buyget promotions (#11799)

what:

- allows percentage value to be considered for buy get percentage

FIXES https://github.com/medusajs/medusa/issues/11259
This commit is contained in:
Riqwan Thamir authored and GitHub committed 2025-03-13 17:09:46 +00:00
1 parent 3063d6e601
commit 67b308c8eb
3 files changed
+29 -22

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/promotion": patch
---
fix(promotion): percentage value is accounted for in buyget promotions
@@ -4443,9 +4443,9 @@ moduleIntegrationTestRunner({
}, },
], ],
application_method: { application_method: {
type: "fixed", type: "percentage",
target_type: "items", target_type: "items",
value: 1000, value: 100,
allocation: "each", allocation: "each",
max_quantity: 1, max_quantity: 1,
apply_to_quantity: 1, apply_to_quantity: 1,
@@ -4623,11 +4623,11 @@ moduleIntegrationTestRunner({
], ],
campaign_id: undefined, campaign_id: undefined,
application_method: { application_method: {
type: "fixed", type: "percentage",
target_type: "items", target_type: "items",
allocation: "each", allocation: "each",
max_quantity: 1, max_quantity: 1,
value: 1000, value: 100,
apply_to_quantity: 4, apply_to_quantity: 4,
buy_rules_min_quantity: 1, buy_rules_min_quantity: 1,
target_rules: [ target_rules: [
@@ -4764,9 +4764,9 @@ moduleIntegrationTestRunner({
buyXGetXPromotion = await createDefaultPromotion(service, { buyXGetXPromotion = await createDefaultPromotion(service, {
type: PromotionType.BUYGET, type: PromotionType.BUYGET,
application_method: { application_method: {
type: "fixed", type: "percentage",
target_type: "items", target_type: "items",
value: 2000, value: 100,
allocation: "each", allocation: "each",
max_quantity: 2, max_quantity: 2,
apply_to_quantity: 2, apply_to_quantity: 2,
@@ -4827,13 +4827,13 @@ moduleIntegrationTestRunner({
const buyXGetXPromotionBulk1 = await createDefaultPromotion( const buyXGetXPromotionBulk1 = await createDefaultPromotion(
service, service,
{ {
code: "BUY50GET1000", code: "BUY50GET100",
type: PromotionType.BUYGET, type: PromotionType.BUYGET,
campaign_id: null, campaign_id: null,
application_method: { application_method: {
type: "fixed", type: "percentage",
target_type: "items", target_type: "items",
value: 20000, value: 100,
allocation: "each", allocation: "each",
max_quantity: 1000, max_quantity: 1000,
apply_to_quantity: 1000, apply_to_quantity: 1000,
@@ -4863,9 +4863,9 @@ moduleIntegrationTestRunner({
type: PromotionType.BUYGET, type: PromotionType.BUYGET,
campaign_id: null, campaign_id: null,
application_method: { application_method: {
type: "fixed", type: "percentage",
target_type: "items", target_type: "items",
value: 20000, value: 20,
allocation: "each", allocation: "each",
max_quantity: 20, max_quantity: 20,
apply_to_quantity: 20, apply_to_quantity: 20,
@@ -4910,11 +4910,11 @@ moduleIntegrationTestRunner({
action: "addItemAdjustment", action: "addItemAdjustment",
item_id: "item_cotton_tshirt", item_id: "item_cotton_tshirt",
amount: 2500, amount: 2500,
code: "BUY50GET1000", code: "BUY50GET100",
}, },
{ {
action: "addItemAdjustment", action: "addItemAdjustment",
amount: 50, amount: 10,
code: "BUY10GET20", code: "BUY10GET20",
item_id: "item_cotton_tshirt", item_id: "item_cotton_tshirt",
}, },
@@ -4925,13 +4925,13 @@ moduleIntegrationTestRunner({
const buyXGetXPromotionBulk1 = await createDefaultPromotion( const buyXGetXPromotionBulk1 = await createDefaultPromotion(
service, service,
{ {
code: "BUY50GET1000", code: "BUY50GET100",
type: PromotionType.BUYGET, type: PromotionType.BUYGET,
campaign_id: null, campaign_id: null,
application_method: { application_method: {
type: "fixed", type: "percentage",
target_type: "items", target_type: "items",
value: 20000, value: 100,
allocation: "each", allocation: "each",
max_quantity: 1000, max_quantity: 1000,
apply_to_quantity: 1000, apply_to_quantity: 1000,
@@ -4961,9 +4961,9 @@ moduleIntegrationTestRunner({
type: PromotionType.BUYGET, type: PromotionType.BUYGET,
campaign_id: null, campaign_id: null,
application_method: { application_method: {
type: "fixed", type: "percentage",
target_type: "items", target_type: "items",
value: 20000, value: 20,
allocation: "each", allocation: "each",
max_quantity: 20, max_quantity: 20,
apply_to_quantity: 20, apply_to_quantity: 20,
@@ -5018,18 +5018,18 @@ moduleIntegrationTestRunner({
action: "addItemAdjustment", action: "addItemAdjustment",
item_id: "item_cotton_tshirt2", item_id: "item_cotton_tshirt2",
amount: 1225, amount: 1225,
code: "BUY50GET1000", code: "BUY50GET100",
}, },
{ {
action: "addItemAdjustment", action: "addItemAdjustment",
item_id: "item_cotton_tshirt", item_id: "item_cotton_tshirt",
amount: 1275, amount: 1275,
code: "BUY50GET1000", code: "BUY50GET100",
}, },
{ {
action: "addItemAdjustment", action: "addItemAdjustment",
item_id: "item_cotton_tshirt2", item_id: "item_cotton_tshirt2",
amount: 50, amount: 10,
code: "BUY10GET20", code: "BUY10GET20",
}, },
]) ])
@@ -200,10 +200,12 @@ export function getComputedActionsForBuyGet(
const appliedPromoValue = const appliedPromoValue =
methodIdPromoValueMap.get(item.id) ?? MathBN.convert(0) methodIdPromoValueMap.get(item.id) ?? MathBN.convert(0)
const multiplier = MathBN.min(targetItem.quantity, remainingQtyToApply) const multiplier = MathBN.min(targetItem.quantity, remainingQtyToApply)
const amount = MathBN.mult( const applicableAmount = MathBN.mult(
MathBN.div(item.subtotal, item.quantity), MathBN.div(item.subtotal, item.quantity),
multiplier multiplier
) )
const applicablePercentage = promotion.application_method?.value ?? 100
const amount = MathBN.mult(applicableAmount, applicablePercentage).div(100)
const newRemainingQtyToApply = MathBN.sub(remainingQtyToApply, multiplier) const newRemainingQtyToApply = MathBN.sub(remainingQtyToApply, multiplier)