UNPKG

@vendure/core

Version:

A modern, headless ecommerce framework

51 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AddressBasedTaxZoneStrategy = void 0; const vendure_logger_1 = require("../logger/vendure-logger"); const loggerCtx = 'AddressBasedTaxZoneStrategy'; /** * @description * Address based {@link TaxZoneStrategy} which tries to find the applicable {@link Zone} based on the * country of the shipping address of the Order. * This is useful for shops that do cross-border B2C orders and use the One-Stop-Shop (OSS) VAT scheme. * * Returns the default {@link Channel}'s default tax zone if no applicable zone is found. * * :::info * * This is configured via `taxOptions.taxZoneStrategy = new AddressBasedTaxZoneStrategy()` in * your VendureConfig. * * ::: * * @example * ```ts * import { VendureConfig, AddressBasedTaxZoneStrategy } from '\@vendure/core'; * * export const config: VendureConfig = { * // other options... * taxOptions: { * taxZoneStrategy: new AddressBasedTaxZoneStrategy(), // [!code highlight] * }, * }; * ``` * * @since 3.1.0 * @docsCategory tax */ class AddressBasedTaxZoneStrategy { determineTaxZone(ctx, zones, channel, order) { var _a; const countryCode = (_a = order === null || order === void 0 ? void 0 : order.shippingAddress) === null || _a === void 0 ? void 0 : _a.countryCode; if (order && countryCode) { const zone = zones.find(z => { var _a; return (_a = z.members) === null || _a === void 0 ? void 0 : _a.find(member => member.code === countryCode); }); if (zone) { return zone; } vendure_logger_1.Logger.debug(`No tax zone found for country ${countryCode}. Returning default ${channel.defaultTaxZone.name} for order ${order.code}`, loggerCtx); } return channel.defaultTaxZone; } } exports.AddressBasedTaxZoneStrategy = AddressBasedTaxZoneStrategy; //# sourceMappingURL=address-based-tax-zone-strategy.js.map