fix(pricing): calculate pricing repository query (#9265)
**What** - fix wrong parentheses nesting when generating calculate pricing query - filter out deleted price lists - use built in DB values for time comparison ---   --- TODO: - [x] check after price list start/end_date is modified, PL prices are not retrieved properly anymore --- FIXES CC-518
This commit is contained in:
1 parent
69f6645716
commit
d721282600
1 file changed
+21
-11
@@ -54,7 +54,6 @@ export class PricingRepository
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
const date = new Date().toISOString()
|
|
||||||
// Gets all the price set money amounts where rules match for each of the contexts
|
// Gets all the price set money amounts where rules match for each of the contexts
|
||||||
// that the price set is configured for
|
// that the price set is configured for
|
||||||
const priceSubQueryKnex = knex({
|
const priceSubQueryKnex = knex({
|
||||||
@@ -97,23 +96,34 @@ export class PricingRepository
|
|||||||
)
|
)
|
||||||
|
|
||||||
priceSubQueryKnex.orWhere((q) => {
|
priceSubQueryKnex.orWhere((q) => {
|
||||||
for (const [key, value] of Object.entries(context)) {
|
const nullPLq = q.whereNull("price.price_list_id")
|
||||||
q.orWhere({
|
nullPLq.andWhere((q) => {
|
||||||
"pr.attribute": key,
|
for (const [key, value] of Object.entries(context)) {
|
||||||
"pr.value": value,
|
q.orWhere({
|
||||||
})
|
"pr.attribute": key,
|
||||||
}
|
"pr.value": value,
|
||||||
q.orWhere("price.rules_count", "=", 0)
|
})
|
||||||
q.whereNull("price.price_list_id")
|
}
|
||||||
|
q.orWhere("price.rules_count", "=", 0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
priceSubQueryKnex.orWhere((q) => {
|
priceSubQueryKnex.orWhere((q) => {
|
||||||
q.whereNotNull("price.price_list_id")
|
q.whereNotNull("price.price_list_id")
|
||||||
|
.whereNull("pl.deleted_at")
|
||||||
.andWhere(function () {
|
.andWhere(function () {
|
||||||
this.whereNull("pl.starts_at").orWhere("pl.starts_at", "<=", date)
|
this.whereNull("pl.starts_at").orWhere(
|
||||||
|
"pl.starts_at",
|
||||||
|
"<=",
|
||||||
|
knex.fn.now()
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.andWhere(function () {
|
.andWhere(function () {
|
||||||
this.whereNull("pl.ends_at").orWhere("pl.ends_at", ">=", date)
|
this.whereNull("pl.ends_at").orWhere(
|
||||||
|
"pl.ends_at",
|
||||||
|
">=",
|
||||||
|
knex.fn.now()
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.andWhere(function () {
|
.andWhere(function () {
|
||||||
this.andWhere(function () {
|
this.andWhere(function () {
|
||||||
|
|||||||
Reference in new issue
Block a user