You are here

class BuildZonesEventSubscriber in Commerce Core 8.2

Provides a test event subscriber that alters the Germany tax rates.

Hierarchy

  • class \Drupal\commerce_tax_test\EventSubscriber\BuildZonesEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of BuildZonesEventSubscriber

1 string reference to 'BuildZonesEventSubscriber'
commerce_tax_test.services.yml in modules/tax/tests/modules/commerce_tax_test/commerce_tax_test.services.yml
modules/tax/tests/modules/commerce_tax_test/commerce_tax_test.services.yml
1 service uses BuildZonesEventSubscriber
commerce_tax_test.build_zones_subscriber in modules/tax/tests/modules/commerce_tax_test/commerce_tax_test.services.yml
Drupal\commerce_tax_test\EventSubscriber\BuildZonesEventSubscriber

File

modules/tax/tests/modules/commerce_tax_test/src/EventSubscriber/BuildZonesEventSubscriber.php, line 13

Namespace

Drupal\commerce_tax_test\EventSubscriber
View source
class BuildZonesEventSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      TaxEvents::BUILD_ZONES => 'onBuildZones',
    ];
  }

  /**
   * Alters the Germany tax rates.
   *
   * @param \Drupal\commerce_tax\Event\BuildZonesEvent $event
   *   The build zones event.
   */
  public function onBuildZones(BuildZonesEvent $event) {
    $plugin = $event
      ->getPlugin();
    if ($plugin
      ->getPluginId() !== 'european_union_vat') {
      return;
    }
    $zones = $event
      ->getZones();
    $germany_zone = $zones['de']
      ->toArray();

    // Add a "fake" standard rate percentage of 25% from January 1st, 2041.
    foreach ($germany_zone['rates'] as &$rate) {
      if ($rate['id'] !== 'standard') {
        continue;
      }
      $rate['percentages'][] = [
        'number' => '0.25',
        'start_date' => '2041-01-01',
      ];
    }
    $zones['de'] = new TaxZone($germany_zone);
    $event
      ->setZones($zones);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BuildZonesEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
BuildZonesEventSubscriber::onBuildZones public function Alters the Germany tax rates.