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