From a4d43115fef7656d9de64ea47b31a7d943b84f07 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Tue, 27 Oct 2020 14:31:06 +0100 Subject: [PATCH] feat(core): Pass RequestContext to TaxZoneStrategy functions BREAKING CHANGE: The TaxZoneStrategy `determineTaxZone()` function signature has changed: the first argument is now the RequestContext of the current request. --- packages/core/src/config/tax/default-tax-zone-strategy.ts | 3 ++- packages/core/src/config/tax/tax-zone-strategy.ts | 3 ++- .../src/service/helpers/order-calculator/order-calculator.ts | 2 +- packages/core/src/service/services/product-variant.service.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/src/config/tax/default-tax-zone-strategy.ts b/packages/core/src/config/tax/default-tax-zone-strategy.ts index 7cc7f1411f..a00f1356f9 100644 --- a/packages/core/src/config/tax/default-tax-zone-strategy.ts +++ b/packages/core/src/config/tax/default-tax-zone-strategy.ts @@ -1,3 +1,4 @@ +import { RequestContext } from '../../api/common/request-context'; import { Channel, Order, Zone } from '../../entity'; import { TaxZoneStrategy } from './tax-zone-strategy'; @@ -9,7 +10,7 @@ import { TaxZoneStrategy } from './tax-zone-strategy'; * @docsCategory tax */ export class DefaultTaxZoneStrategy implements TaxZoneStrategy { - determineTaxZone(zones: Zone[], channel: Channel, order?: Order): Zone { + determineTaxZone(ctx: RequestContext, zones: Zone[], channel: Channel, order?: Order): Zone { return channel.defaultTaxZone; } } diff --git a/packages/core/src/config/tax/tax-zone-strategy.ts b/packages/core/src/config/tax/tax-zone-strategy.ts index 2580cd3abd..c915afec69 100644 --- a/packages/core/src/config/tax/tax-zone-strategy.ts +++ b/packages/core/src/config/tax/tax-zone-strategy.ts @@ -1,3 +1,4 @@ +import { RequestContext } from '../../api/common/request-context'; import { InjectableStrategy } from '../../common/types/injectable-strategy'; import { Channel, Order, Zone } from '../../entity'; @@ -8,5 +9,5 @@ import { Channel, Order, Zone } from '../../entity'; * @docsCategory tax */ export interface TaxZoneStrategy extends InjectableStrategy { - determineTaxZone(zones: Zone[], channel: Channel, order?: Order): Zone | undefined; + determineTaxZone(ctx: RequestContext, zones: Zone[], channel: Channel, order?: Order): Zone | undefined; } diff --git a/packages/core/src/service/helpers/order-calculator/order-calculator.ts b/packages/core/src/service/helpers/order-calculator/order-calculator.ts index 839c315576..88e03781da 100644 --- a/packages/core/src/service/helpers/order-calculator/order-calculator.ts +++ b/packages/core/src/service/helpers/order-calculator/order-calculator.ts @@ -42,7 +42,7 @@ export class OrderCalculator { ): Promise { const { taxZoneStrategy } = this.configService.taxOptions; const zones = this.zoneService.findAll(ctx); - const activeTaxZone = taxZoneStrategy.determineTaxZone(zones, ctx.channel, order); + const activeTaxZone = taxZoneStrategy.determineTaxZone(ctx, zones, ctx.channel, order); let taxZoneChanged = false; if (!activeTaxZone) { throw new InternalServerError(`error.no-active-tax-zone`); diff --git a/packages/core/src/service/services/product-variant.service.ts b/packages/core/src/service/services/product-variant.service.ts index 014a19b1f8..f8edb5e3b6 100644 --- a/packages/core/src/service/services/product-variant.service.ts +++ b/packages/core/src/service/services/product-variant.service.ts @@ -399,7 +399,7 @@ export class ProductVariantService { } const { taxZoneStrategy } = this.configService.taxOptions; const zones = this.zoneService.findAll(ctx); - const activeTaxZone = taxZoneStrategy.determineTaxZone(zones, ctx.channel); + const activeTaxZone = taxZoneStrategy.determineTaxZone(ctx, zones, ctx.channel); if (!activeTaxZone) { throw new InternalServerError(`error.no-active-tax-zone`); }