Browse Source

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.
Michael Bromley 5 years ago
parent
commit
a4d43115fe

+ 2 - 1
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 { Channel, Order, Zone } from '../../entity';
 
 
 import { TaxZoneStrategy } from './tax-zone-strategy';
 import { TaxZoneStrategy } from './tax-zone-strategy';
@@ -9,7 +10,7 @@ import { TaxZoneStrategy } from './tax-zone-strategy';
  * @docsCategory tax
  * @docsCategory tax
  */
  */
 export class DefaultTaxZoneStrategy implements TaxZoneStrategy {
 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;
         return channel.defaultTaxZone;
     }
     }
 }
 }

+ 2 - 1
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 { InjectableStrategy } from '../../common/types/injectable-strategy';
 import { Channel, Order, Zone } from '../../entity';
 import { Channel, Order, Zone } from '../../entity';
 
 
@@ -8,5 +9,5 @@ import { Channel, Order, Zone } from '../../entity';
  * @docsCategory tax
  * @docsCategory tax
  */
  */
 export interface TaxZoneStrategy extends InjectableStrategy {
 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;
 }
 }

+ 1 - 1
packages/core/src/service/helpers/order-calculator/order-calculator.ts

@@ -42,7 +42,7 @@ export class OrderCalculator {
     ): Promise<OrderItem[]> {
     ): Promise<OrderItem[]> {
         const { taxZoneStrategy } = this.configService.taxOptions;
         const { taxZoneStrategy } = this.configService.taxOptions;
         const zones = this.zoneService.findAll(ctx);
         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;
         let taxZoneChanged = false;
         if (!activeTaxZone) {
         if (!activeTaxZone) {
             throw new InternalServerError(`error.no-active-tax-zone`);
             throw new InternalServerError(`error.no-active-tax-zone`);

+ 1 - 1
packages/core/src/service/services/product-variant.service.ts

@@ -399,7 +399,7 @@ export class ProductVariantService {
         }
         }
         const { taxZoneStrategy } = this.configService.taxOptions;
         const { taxZoneStrategy } = this.configService.taxOptions;
         const zones = this.zoneService.findAll(ctx);
         const zones = this.zoneService.findAll(ctx);
-        const activeTaxZone = taxZoneStrategy.determineTaxZone(zones, ctx.channel);
+        const activeTaxZone = taxZoneStrategy.determineTaxZone(ctx, zones, ctx.channel);
         if (!activeTaxZone) {
         if (!activeTaxZone) {
             throw new InternalServerError(`error.no-active-tax-zone`);
             throw new InternalServerError(`error.no-active-tax-zone`);
         }
         }