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
2025-03-13 18:09:46 +01:00
committed by GitHub
parent 3063d6e601
commit 67b308c8eb
3 changed files with 29 additions and 22 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/promotion": patch
---
fix(promotion): percentage value is accounted for in buyget promotions

View File

@@ -4443,9 +4443,9 @@ moduleIntegrationTestRunner({
},
],
application_method: {
type: "fixed",
type: "percentage",
target_type: "items",
value: 1000,
value: 100,
allocation: "each",
max_quantity: 1,
apply_to_quantity: 1,
@@ -4623,11 +4623,11 @@ moduleIntegrationTestRunner({
],
campaign_id: undefined,
application_method: {
type: "fixed",
type: "percentage",
target_type: "items",
allocation: "each",
max_quantity: 1,
value: 1000,
value: 100,
apply_to_quantity: 4,
buy_rules_min_quantity: 1,
target_rules: [
@@ -4764,9 +4764,9 @@ moduleIntegrationTestRunner({
buyXGetXPromotion = await createDefaultPromotion(service, {
type: PromotionType.BUYGET,
application_method: {
type: "fixed",
type: "percentage",
target_type: "items",
value: 2000,
value: 100,
allocation: "each",
max_quantity: 2,
apply_to_quantity: 2,
@@ -4827,13 +4827,13 @@ moduleIntegrationTestRunner({
const buyXGetXPromotionBulk1 = await createDefaultPromotion(
service,
{
code: "BUY50GET1000",
code: "BUY50GET100",
type: PromotionType.BUYGET,
campaign_id: null,
application_method: {
type: "fixed",
type: "percentage",
target_type: "items",
value: 20000,
value: 100,
allocation: "each",
max_quantity: 1000,
apply_to_quantity: 1000,
@@ -4863,9 +4863,9 @@ moduleIntegrationTestRunner({
type: PromotionType.BUYGET,
campaign_id: null,
application_method: {
type: "fixed",
type: "percentage",
target_type: "items",
value: 20000,
value: 20,
allocation: "each",
max_quantity: 20,
apply_to_quantity: 20,
@@ -4910,11 +4910,11 @@ moduleIntegrationTestRunner({
action: "addItemAdjustment",
item_id: "item_cotton_tshirt",
amount: 2500,
code: "BUY50GET1000",
code: "BUY50GET100",
},
{
action: "addItemAdjustment",
amount: 50,
amount: 10,
code: "BUY10GET20",
item_id: "item_cotton_tshirt",
},
@@ -4925,13 +4925,13 @@ moduleIntegrationTestRunner({
const buyXGetXPromotionBulk1 = await createDefaultPromotion(
service,
{
code: "BUY50GET1000",
code: "BUY50GET100",
type: PromotionType.BUYGET,
campaign_id: null,
application_method: {
type: "fixed",
type: "percentage",
target_type: "items",
value: 20000,
value: 100,
allocation: "each",
max_quantity: 1000,
apply_to_quantity: 1000,
@@ -4961,9 +4961,9 @@ moduleIntegrationTestRunner({
type: PromotionType.BUYGET,
campaign_id: null,
application_method: {
type: "fixed",
type: "percentage",
target_type: "items",
value: 20000,
value: 20,
allocation: "each",
max_quantity: 20,
apply_to_quantity: 20,
@@ -5018,18 +5018,18 @@ moduleIntegrationTestRunner({
action: "addItemAdjustment",
item_id: "item_cotton_tshirt2",
amount: 1225,
code: "BUY50GET1000",
code: "BUY50GET100",
},
{
action: "addItemAdjustment",
item_id: "item_cotton_tshirt",
amount: 1275,
code: "BUY50GET1000",
code: "BUY50GET100",
},
{
action: "addItemAdjustment",
item_id: "item_cotton_tshirt2",
amount: 50,
amount: 10,
code: "BUY10GET20",
},
])

View File

@@ -200,10 +200,12 @@ export function getComputedActionsForBuyGet(
const appliedPromoValue =
methodIdPromoValueMap.get(item.id) ?? MathBN.convert(0)
const multiplier = MathBN.min(targetItem.quantity, remainingQtyToApply)
const amount = MathBN.mult(
const applicableAmount = MathBN.mult(
MathBN.div(item.subtotal, item.quantity),
multiplier
)
const applicablePercentage = promotion.application_method?.value ?? 100
const amount = MathBN.mult(applicableAmount, applicablePercentage).div(100)
const newRemainingQtyToApply = MathBN.sub(remainingQtyToApply, multiplier)