fix(medusa): Price selection strategy bug with customer groups without customers (#4578)

* change up condition for joining price lists

* add changeset

* naming

* update tests
This commit is contained in:
Philip Korsholm authored and GitHub committed 2023-07-24 11:10:17 +02:00
1 parent a0a041e5c9
commit c9989529ed
8 files changed
+200 -22

No files matched your search

@@ -1,6 +1,7 @@
import { NextFunction, Request, Response } from "express"
import { MedusaError } from "medusa-core-utils"
import { Logger } from "../../types/global"
import { MedusaError } from "medusa-core-utils"
import { formatException } from "../../utils"
const QUERY_RUNNER_RELEASED = "QueryRunnerAlreadyReleasedError"
@@ -1,4 +1,3 @@
import partition from "lodash/partition"
import {
Brackets,
In,
@@ -7,16 +6,18 @@ import {
ObjectLiteral,
WhereExpressionBuilder,
} from "typeorm"
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity"
import { dataSource } from "../loaders/database"
import { MoneyAmount } from "../models"
import {
PriceListPriceCreateInput,
PriceListPriceUpdateInput,
} from "../types/price-list"
import { MoneyAmount } from "../models"
import { ProductVariantPrice } from "../types/product-variant"
import { isString } from "../utils"
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity"
import { dataSource } from "../loaders/database"
import { groupBy } from "lodash"
import { isString } from "../utils"
import partition from "lodash/partition"
type Price = Partial<
Omit<MoneyAmount, "created_at" | "updated_at" | "deleted_at">
@@ -316,12 +317,9 @@ export const MoneyAmountRepository = dataSource
"cgc",
"cgc.customer_group_id = cgroup.id"
)
.andWhere(
"(cgc.customer_group_id is null OR cgc.customer_id = :customer_id)",
{
customer_id,
}
)
.andWhere("(cgroup.id is null OR cgc.customer_id = :customer_id)", {
customer_id,
})
} else {
qb.leftJoin("price_list.customer_groups", "cgroup").andWhere(
"cgroup.id is null"
@@ -1,16 +1,17 @@
import { ICacheService } from "@medusajs/types"
import { isDefined } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import {
AbstractPriceSelectionStrategy,
PriceSelectionContext,
PriceSelectionResult,
PriceType,
} from "../interfaces"
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
import { MoneyAmountRepository } from "../repositories/money-amount"
import { TaxServiceRate } from "../types/tax-service"
import { EntityManager } from "typeorm"
import { FlagRouter } from "../utils/flag-router"
import { ICacheService } from "@medusajs/types"
import { MoneyAmountRepository } from "../repositories/money-amount"
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
import { TaxServiceRate } from "../types/tax-service"
import { isDefined } from "medusa-core-utils"
class PriceSelectionStrategy extends AbstractPriceSelectionStrategy {
protected manager_: EntityManager