Commit 1c86a783 authored by Jonathan Sacksick's avatar Jonathan Sacksick Committed by Jonathan Sacksick
Browse files

Issue #3263578 by jsacksick, agoradesign, dwkitchen: Changed logic in...

Issue #3263578 by jsacksick, agoradesign, dwkitchen: Changed logic in LocalTaxTypeBase::checkRegistrations() causes regressions with zones having multiple territories with inclusive postal codes.
parent 8d17ea3a
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -97,9 +97,23 @@ class EuropeanUnionVat extends LocalTaxTypeBase {
      // when the total yearly transactions breach the defined threshold.
      // See http://www.vatlive.com/eu-vat-rules/vat-registration-threshold/
      $resolved_zones = $store_zones;
      $customer_zone = reset($customer_zones);
      if ($this->checkRegistrations($store, $customer_zone)) {
        $resolved_zones = $customer_zones;

      // Check if the store is registered to pay taxes in the destination zone.
      $store_registration_countries = array_column($store->get('tax_registrations')->getValue(), 'value');
      $store_registration_countries = array_combine($store_registration_countries, $store_registration_countries);
      foreach ($customer_zones as $zone) {
        [$zone_country_code] = explode('_', $zone->getId());
        $zone_country_code = strtoupper($zone_country_code);
        // Skip territories that are not in a country where the store is
        // registered.
        if (!isset($store_registration_countries[$zone_country_code])) {
          continue;
        }
        foreach ($zone->getTerritories() as $territory) {
          if ($territory->match($customer_address)) {
            return $customer_zones;
          }
        }
      }
    }

+38 −0
Original line number Diff line number Diff line
@@ -215,6 +215,44 @@ class EuropeanUnionVatTest extends OrderKernelTestBase {
    $adjustment = reset($adjustments);
    $this->assertCount(1, $adjustments);
    $this->assertEquals('european_union_vat|fr_h|standard', $adjustment->getSourceId());

    // German customer, AT store registered in AT, physical product.
    $order = $this->buildOrder('DE', 'AT', '', ['AT']);
    $this->assertTrue($plugin->applies($order));
    $plugin->apply($order);
    $adjustments = $order->collectAdjustments();
    $adjustment = reset($adjustments);
    $this->assertCount(1, $adjustments);
    $this->assertEquals('european_union_vat|at|standard', $adjustment->getSourceId());

    // Austrian customer in Mittelberg, AT store registered in AT,
    // physical product.
    $order = $this->buildOrder('DE', 'AT', '', ['AT']);
    $billing_profile = $order->getBillingProfile();
    $billing_profile->set('address', [
      'country_code' => 'AT',
      'postal_code' => '6991',
    ]);
    $billing_profile->save();
    $plugin->apply($order);
    $adjustments = $order->collectAdjustments();
    $adjustment = reset($adjustments);
    $this->assertCount(1, $adjustments);
    $this->assertEquals('european_union_vat|at|standard', $adjustment->getSourceId());

    // German customer in Büsingen, DE store registered in DE,
    // physical product.
    // EU VAT does not apply as customer is in Switzerland for VAT.
    $order = $this->buildOrder('DE', 'DE', '', ['DE']);
    $billing_profile = $order->getBillingProfile();
    $billing_profile->set('address', [
      'country_code' => 'DE',
      'postal_code' => '78266',
    ]);
    $billing_profile->save();
    $plugin->apply($order);
    $adjustments = $order->collectAdjustments();
    $this->assertCount(0, $adjustments);
  }

  /**
+15 −0
Original line number Diff line number Diff line
@@ -59,6 +59,21 @@ class SwissVatTest extends EuropeanUnionVatTest {
    $plugin->apply($order);
    $adjustments = $order->collectAdjustments();
    $this->assertCount(0, $adjustments);

    // German customer in Büsingen, CH store registered in CH,
    // physical product.
    $order = $this->buildOrder('DE', 'CH', '', ['CH']);
    $billing_profile = $order->getBillingProfile();
    $billing_profile->set('address', [
      'country_code' => 'DE',
      'postal_code' => '78266',
    ]);
    $billing_profile->save();
    $plugin->apply($order);
    $adjustments = $order->collectAdjustments();
    $adjustment = reset($adjustments);
    $this->assertCount(1, $adjustments);
    $this->assertEquals('swiss_vat|ch|standard', $adjustment->getSourceId());
  }

  /**