diff --git a/packages/modules/pricing/src/repositories/pricing.ts b/packages/modules/pricing/src/repositories/pricing.ts index 55865d308a..6fa8c34490 100644 --- a/packages/modules/pricing/src/repositories/pricing.ts +++ b/packages/modules/pricing/src/repositories/pricing.ts @@ -54,7 +54,6 @@ export class PricingRepository return [] } - const date = new Date().toISOString() // Gets all the price set money amounts where rules match for each of the contexts // that the price set is configured for const priceSubQueryKnex = knex({ @@ -97,23 +96,34 @@ export class PricingRepository ) priceSubQueryKnex.orWhere((q) => { - for (const [key, value] of Object.entries(context)) { - q.orWhere({ - "pr.attribute": key, - "pr.value": value, - }) - } - q.orWhere("price.rules_count", "=", 0) - q.whereNull("price.price_list_id") + const nullPLq = q.whereNull("price.price_list_id") + nullPLq.andWhere((q) => { + for (const [key, value] of Object.entries(context)) { + q.orWhere({ + "pr.attribute": key, + "pr.value": value, + }) + } + q.orWhere("price.rules_count", "=", 0) + }) }) priceSubQueryKnex.orWhere((q) => { q.whereNotNull("price.price_list_id") + .whereNull("pl.deleted_at") .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 () { - this.whereNull("pl.ends_at").orWhere("pl.ends_at", ">=", date) + this.whereNull("pl.ends_at").orWhere( + "pl.ends_at", + ">=", + knex.fn.now() + ) }) .andWhere(function () { this.andWhere(function () {