Browse Source

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

Martijn 7 months ago
parent
commit
8977d9fdac

+ 2 - 9
packages/core/src/config/tax/address-based-tax-zone-strategy.spec.ts

@@ -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';
 
@@ -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');
     });
 

+ 3 - 2
packages/core/src/config/tax/address-based-tax-zone-strategy.ts

@@ -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.
  *
@@ -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) {