fix(medusa): MoneyAmountRepository#findManyForVariantInRegion sql statement for constraint related to price_list (#1462)
This commit is contained in:
committed by
GitHub
parent
2260c2d09e
commit
3c75a65792
@@ -126,21 +126,17 @@ export class MoneyAmountRepository extends Repository<MoneyAmount> {
|
||||
const date = new Date()
|
||||
|
||||
const qb = this.createQueryBuilder("ma")
|
||||
.leftJoinAndSelect(
|
||||
"ma.price_list",
|
||||
"price_list",
|
||||
"ma.price_list_id = price_list.id "
|
||||
)
|
||||
.leftJoinAndSelect("ma.price_list", "price_list")
|
||||
.where({ variant_id: variant_id })
|
||||
.andWhere("(ma.price_list_id is null or price_list.status = 'active')")
|
||||
.andWhere(
|
||||
"(price_list is null or price_list.ends_at is null OR price_list.ends_at > :date) ",
|
||||
"(price_list.ends_at is null OR price_list.ends_at > :date)",
|
||||
{
|
||||
date: date.toUTCString(),
|
||||
}
|
||||
)
|
||||
.andWhere(
|
||||
"(price_list is null or price_list.starts_at is null OR price_list.starts_at < :date)",
|
||||
"(price_list.starts_at is null OR price_list.starts_at < :date)",
|
||||
{
|
||||
date: date.toUTCString(),
|
||||
}
|
||||
@@ -155,23 +151,19 @@ export class MoneyAmountRepository extends Repository<MoneyAmount> {
|
||||
)
|
||||
)
|
||||
} else if (!customer_id && !include_discount_prices) {
|
||||
qb.andWhere("price_list IS null")
|
||||
qb.andWhere("price_list.id IS null")
|
||||
}
|
||||
|
||||
if (customer_id) {
|
||||
qb.leftJoin("price_list.customer_groups", "cgroup")
|
||||
.leftJoin(
|
||||
"customer_group_customers",
|
||||
"cgc",
|
||||
"cgc.customer_group_id = cgroup.id"
|
||||
)
|
||||
.andWhere("(cgc is null OR cgc.customer_id = :customer_id)", {
|
||||
.leftJoin("customer_group_customers", "cgc", "cgc.customer_group_id = cgroup.id")
|
||||
.andWhere("(cgc.customer_group_id is null OR cgc.customer_id = :customer_id)", {
|
||||
customer_id,
|
||||
})
|
||||
} else {
|
||||
qb.leftJoin("price_list.customer_groups", "cgroup").andWhere(
|
||||
"cgroup.id is null"
|
||||
)
|
||||
qb
|
||||
.leftJoin("price_list.customer_groups", "cgroup")
|
||||
.andWhere("cgroup.id is null")
|
||||
}
|
||||
return await qb.getManyAndCount()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user