Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pricing): add null conditions for deleted at during price calculations #10896

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading