Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Only use shipping address for tax zone determination #3367

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { RequestContext, Zone, Channel, Order } from '@vendure/core';
import { describe, it, expect } from 'vitest';

import { Logger } from '../logger/vendure-logger';
import { RequestContext, Zone, Channel, Order } from '../../';

import { AddressBasedTaxZoneStrategy } from './address-based-tax-zone-strategy';

Expand All @@ -18,18 +17,12 @@ describe('AddressBasedTaxZoneStrategy', () => {
{ name: 'DE Zone', members: [{ code: 'DE' }] } as Zone,
];

it('Determines zone based on billing address country', () => {
it('Determines zone based on shipping address country', () => {
const order = {
billingAddress: { countryCode: 'US' },
shippingAddress: { countryCode: 'DE' },
} as Order;
const result = strategy.determineTaxZone(ctx, zones, channel, order);
expect(result.name).toBe('US Zone');
});

it('Determines zone based on shipping address if no billing address set', () => {
const order = { shippingAddress: { countryCode: 'DE' } } as Order;
const result = strategy.determineTaxZone(ctx, zones, channel, order);
expect(result.name).toBe('DE Zone');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const loggerCtx = 'AddressBasedTaxZoneStrategy';
/**
* @description
* Address based {@link TaxZoneStrategy} which tries to find the applicable {@link Zone} based on the
* country of the billing address, or else the country of the shipping address of the Order.
* 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.
*
Expand Down Expand Up @@ -38,7 +39,7 @@ const loggerCtx = 'AddressBasedTaxZoneStrategy';
*/
export class AddressBasedTaxZoneStrategy implements TaxZoneStrategy {
determineTaxZone(ctx: RequestContext, zones: Zone[], channel: Channel, order?: Order): Zone {
const countryCode = order?.billingAddress?.countryCode ?? order?.shippingAddress?.countryCode;
const countryCode = order?.shippingAddress?.countryCode;
if (order && countryCode) {
const zone = zones.find(z => z.members?.find(member => member.code === countryCode));
if (zone) {
Expand Down