diff --git a/.changeset/nasty-poets-pretend.md b/.changeset/nasty-poets-pretend.md new file mode 100644 index 0000000000000..32c4dd9417a71 --- /dev/null +++ b/.changeset/nasty-poets-pretend.md @@ -0,0 +1,5 @@ +--- +"@medusajs/pricing": patch +--- + +fix(pricing): add null conditions for deleted at during price calculations diff --git a/packages/modules/pricing/integration-tests/__tests__/services/pricing-module/calculate-price.spec.ts b/packages/modules/pricing/integration-tests/__tests__/services/pricing-module/calculate-price.spec.ts index 998f3a04dc64f..0b7b877d2e9a6 100644 --- a/packages/modules/pricing/integration-tests/__tests__/services/pricing-module/calculate-price.spec.ts +++ b/packages/modules/pricing/integration-tests/__tests__/services/pricing-module/calculate-price.spec.ts @@ -1814,6 +1814,74 @@ moduleIntegrationTestRunner({ }, ]) }) + + 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", () => { diff --git a/packages/modules/pricing/src/repositories/pricing.ts b/packages/modules/pricing/src/repositories/pricing.ts index 70ad954ce7dca..300ab11b6e0a1 100644 --- a/packages/modules/pricing/src/repositories/pricing.ts +++ b/packages/modules/pricing/src/repositories/pricing.ts @@ -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", @@ -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" },