Skip to content

Commit

Permalink
fix(pricing): add null conditions for deleted at during price calcula…
Browse files Browse the repository at this point in the history
…tions (#10896)
  • Loading branch information
riqwan authored Jan 9, 2025
1 parent 6747a15 commit 3fec01a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/nasty-poets-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/pricing": patch
---

fix(pricing): add null conditions for deleted at during price calculations
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,74 @@ moduleIntegrationTestRunner<IPricingModuleService>({
},
])
})

it("should not return price list prices when price is deleted", async () => {
const [priceList] = await createPriceLists(
service,
{},
{ region_id: ["DE", "PL"] },
[
{
amount: 111,
currency_code: "PLN",
price_set_id: "price-set-PLN",
rules: {
region_id: "DE",
},
},
]
)

const priceSetsResult1 = await service.calculatePrices(
{ id: ["price-set-EUR", "price-set-PLN"] },
{
context: {
currency_code: "PLN",
region_id: "DE",
customer_group_id: "vip-customer-group-id",
company_id: "medusa-company-id",
},
}
)

expect(priceSetsResult1).toEqual([
expect.objectContaining({
id: "price-set-PLN",
is_calculated_price_price_list: true,
calculated_amount: 111,
is_original_price_price_list: false,
original_amount: 400,
}),
])

const test = await service.softDeletePrices(
priceList.prices.map((p) => p.id)
)

console.log("test -- ", JSON.stringify(test, null, 4))

const priceSetsResult2 = await service.calculatePrices(
{ id: ["price-set-EUR", "price-set-PLN"] },
{
context: {
currency_code: "PLN",
region_id: "DE",
customer_group_id: "vip-customer-group-id",
company_id: "medusa-company-id",
},
}
)

expect(priceSetsResult2).toEqual([
expect.objectContaining({
id: "price-set-PLN",
is_calculated_price_price_list: false,
calculated_amount: 400,
is_original_price_price_list: false,
original_amount: 400,
}),
])
})
})

describe("Tax inclusivity", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/pricing/src/repositories/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class PricingRepository
min_quantity: "price.min_quantity",
max_quantity: "price.max_quantity",
currency_code: "price.currency_code",
deleted_at: "price.deleted_at",
price_set_id: "price.price_set_id",
rules_count: "price.rules_count",
price_list_id: "price.price_list_id",
Expand Down Expand Up @@ -268,7 +269,7 @@ export class PricingRepository
.join(priceSubQueryKnex.as("price"), "price.price_set_id", "ps.id")
.whereIn("ps.id", pricingFilters.id)
.andWhere("price.currency_code", "=", currencyCode)

.whereNull("price.deleted_at")
.orderBy([
{ column: "price.has_price_list", order: "asc" },
{ column: "all_rules_count", order: "desc" },
Expand Down

0 comments on commit 3fec01a

Please sign in to comment.