Skip to content

Commit

Permalink
feat(core): Pass RequestContext to TaxZoneStrategy functions
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The TaxZoneStrategy `determineTaxZone()`
function signature has changed: the first argument is now the
RequestContext of the current request.
  • Loading branch information
michaelbromley committed Oct 27, 2020
1 parent 05e6f9e commit a4d4311
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/config/tax/default-tax-zone-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RequestContext } from '../../api/common/request-context';
import { Channel, Order, Zone } from '../../entity';

import { TaxZoneStrategy } from './tax-zone-strategy';
Expand All @@ -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;
}
}
3 changes: 2 additions & 1 deletion packages/core/src/config/tax/tax-zone-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RequestContext } from '../../api/common/request-context';
import { InjectableStrategy } from '../../common/types/injectable-strategy';
import { Channel, Order, Zone } from '../../entity';

Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class OrderCalculator {
): Promise<OrderItem[]> {
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`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand Down

0 comments on commit a4d4311

Please sign in to comment.