You are here

class CanadianSalesTax in Commerce Core 8.2

Provides the Canadian sales tax type.

Plugin annotation


@CommerceTaxType(
  id = "canadian_sales_tax",
  label = "Canadian sales tax",
)

Hierarchy

Expanded class hierarchy of CanadianSalesTax

File

modules/tax/src/Plugin/Commerce/TaxType/CanadianSalesTax.php, line 19

Namespace

Drupal\commerce_tax\Plugin\Commerce\TaxType
View source
class CanadianSalesTax extends LocalTaxTypeBase {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);
    $form['rates'] = $this
      ->buildRateSummary();
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  protected function matchesAddress(StoreInterface $store) {
    return $store
      ->getAddress()
      ->getCountryCode() == 'CA';
  }

  /**
   * {@inheritdoc}
   */
  protected function matchesRegistrations(StoreInterface $store) {
    $store_registrations = $store
      ->get('tax_registrations')
      ->getValue();
    $store_registrations = array_column($store_registrations, 'value');
    return in_array('CA', $store_registrations);
  }

  /**
   * {@inheritdoc}
   */
  protected function resolveZones(OrderItemInterface $order_item, ProfileInterface $customer_profile) {
    $customer_address = $customer_profile
      ->get('address')
      ->first();
    if ($customer_address
      ->getCountryCode() != 'CA') {
      return [];
    }
    return parent::resolveZones($order_item, $customer_profile);
  }

  /**
   * {@inheritdoc}
   */
  public function buildZones() {
    $zones = [];
    $zones['ca'] = new TaxZone([
      'id' => 'ca',
      'label' => $this
        ->t('- Federal -'),
      'display_label' => $this
        ->t('GST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'AB',
        ],
        [
          'country_code' => 'CA',
          'administrative_area' => 'BC',
        ],
        [
          'country_code' => 'CA',
          'administrative_area' => 'MB',
        ],
        [
          'country_code' => 'CA',
          'administrative_area' => 'NT',
        ],
        [
          'country_code' => 'CA',
          'administrative_area' => 'NU',
        ],
        [
          'country_code' => 'CA',
          'administrative_area' => 'QC',
        ],
        [
          'country_code' => 'CA',
          'administrative_area' => 'SK',
        ],
        [
          'country_code' => 'CA',
          'administrative_area' => 'YT',
        ],
      ],
      'rates' => [
        [
          'id' => 'gst',
          'label' => $this
            ->t('GST'),
          'percentages' => [
            [
              'number' => '0.05',
              'start_date' => '2008-01-01',
            ],
          ],
          'default' => TRUE,
        ],
      ],
    ]);
    $zones['bc'] = new TaxZone([
      'id' => 'bc',
      'label' => $this
        ->t('British Columbia'),
      'display_label' => $this
        ->t('PST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'BC',
        ],
      ],
      'rates' => [
        [
          'id' => 'pst',
          'label' => $this
            ->t('PST'),
          'percentages' => [
            [
              'number' => '0.07',
              'start_date' => '2013-04-01',
            ],
          ],
        ],
      ],
    ]);
    $zones['mb'] = new TaxZone([
      'id' => 'mb',
      'label' => $this
        ->t('Manitoba'),
      'display_label' => $this
        ->t('PST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'MB',
        ],
      ],
      'rates' => [
        [
          'id' => 'pst',
          'label' => $this
            ->t('PST'),
          'percentages' => [
            [
              'number' => '0.08',
              'start_date' => '2013-07-01',
              'end_date' => '2023-06-30',
            ],
          ],
        ],
      ],
    ]);
    $zones['nb'] = new TaxZone([
      'id' => 'nb',
      'label' => $this
        ->t('New Brunswick'),
      'display_label' => $this
        ->t('HST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'NB',
        ],
      ],
      'rates' => [
        [
          'id' => 'hst',
          'label' => $this
            ->t('HST'),
          'percentages' => [
            [
              'number' => '0.15',
              'start_date' => '2016-07-01',
            ],
          ],
        ],
      ],
    ]);
    $zones['nl'] = new TaxZone([
      'id' => 'nl',
      'label' => $this
        ->t('Newfoundland'),
      'display_label' => $this
        ->t('HST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'NL',
        ],
      ],
      'rates' => [
        [
          'id' => 'hst',
          'label' => $this
            ->t('HST'),
          'percentages' => [
            [
              'number' => '0.15',
              'start_date' => '2016-07-01',
            ],
          ],
        ],
      ],
    ]);
    $zones['ns'] = new TaxZone([
      'id' => 'ns',
      'label' => $this
        ->t('Nova Scotia'),
      'display_label' => $this
        ->t('HST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'NS',
        ],
      ],
      'rates' => [
        [
          'id' => 'hst',
          'label' => $this
            ->t('HST'),
          'percentages' => [
            [
              'number' => '0.15',
              'start_date' => '2010-07-01',
            ],
          ],
        ],
      ],
    ]);
    $zones['on'] = new TaxZone([
      'id' => 'on',
      'label' => $this
        ->t('Ontario'),
      'display_label' => $this
        ->t('HST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'ON',
        ],
      ],
      'rates' => [
        [
          'id' => 'hst',
          'label' => $this
            ->t('HST'),
          'percentages' => [
            [
              'number' => '0.13',
              'start_date' => '2010-07-01',
            ],
          ],
        ],
      ],
    ]);
    $zones['pe'] = new TaxZone([
      'id' => 'pe',
      'label' => $this
        ->t('Prince Edward Island'),
      'display_label' => $this
        ->t('HST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'PE',
        ],
      ],
      'rates' => [
        [
          'id' => 'hst',
          'label' => $this
            ->t('HST'),
          'percentages' => [
            [
              'number' => '0.14',
              'start_date' => '2013-04-01',
              'end_date' => '2016-09-30',
            ],
            [
              'number' => '0.15',
              'start_date' => '2016-10-01',
            ],
          ],
        ],
      ],
    ]);
    $zones['qc'] = new TaxZone([
      'id' => 'qc',
      'label' => $this
        ->t('Quebec'),
      'display_label' => $this
        ->t('QST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'QC',
        ],
      ],
      'rates' => [
        [
          'id' => 'qst',
          'label' => $this
            ->t('QST'),
          'percentages' => [
            [
              'number' => '0.09975',
              'start_date' => '2013-01-01',
            ],
          ],
        ],
      ],
    ]);
    $zones['sk'] = new TaxZone([
      'id' => 'sk',
      'label' => $this
        ->t('Saskatchewan'),
      'display_label' => $this
        ->t('PST'),
      'territories' => [
        [
          'country_code' => 'CA',
          'administrative_area' => 'SK',
        ],
      ],
      'rates' => [
        [
          'id' => 'pst',
          'label' => $this
            ->t('PST'),
          'percentages' => [
            [
              'number' => '0.05',
              'start_date' => '2013-04-01',
              'end_date' => '2017-03-22',
            ],
            [
              'number' => '0.06',
              'start_date' => '2017-03-23',
            ],
          ],
        ],
      ],
    ]);
    return $zones;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CanadianSalesTax::buildConfigurationForm public function Form constructor. Overrides TaxTypeBase::buildConfigurationForm
CanadianSalesTax::buildZones public function Builds the tax zones. Overrides LocalTaxTypeBase::buildZones
CanadianSalesTax::matchesAddress protected function Checks whether the tax type matches the store's billing address. Overrides LocalTaxTypeBase::matchesAddress
CanadianSalesTax::matchesRegistrations protected function Checks whether the tax type matches the store's tax registrations. Overrides LocalTaxTypeBase::matchesRegistrations
CanadianSalesTax::resolveZones protected function Resolves the tax zones for the given order item and customer profile. Overrides LocalTaxTypeBase::resolveZones
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
LocalTaxTypeBase::$chainRateResolver protected property The chain tax rate resolver.
LocalTaxTypeBase::$matchedZones protected property The matched zones.
LocalTaxTypeBase::$rounder protected property The rounder.
LocalTaxTypeBase::$zones protected property The zones.
LocalTaxTypeBase::applies public function Checks whether the tax type applies to the given order. Overrides TaxTypeBase::applies
LocalTaxTypeBase::apply public function Applies the tax type to the given order. Overrides TaxTypeInterface::apply
LocalTaxTypeBase::buildRateSummary protected function Builds the summary of all available tax rates.
LocalTaxTypeBase::checkRegistrations protected function Checks whether the store is registered to collect taxes in the given zone.
LocalTaxTypeBase::create public static function Creates an instance of the plugin. Overrides TaxTypeBase::create 1
LocalTaxTypeBase::getMatchingZones public function Gets the tax zones which match the given address. Overrides LocalTaxTypeInterface::getMatchingZones
LocalTaxTypeBase::getZones public function Gets the tax zones. Overrides LocalTaxTypeInterface::getZones
LocalTaxTypeBase::resolveRates protected function Resolves the tax rates for the given order item and customer profile.
LocalTaxTypeBase::shouldRound public function Gets whether tax should be rounded at the order item level. Overrides LocalTaxTypeInterface::shouldRound 1
LocalTaxTypeBase::__construct public function Constructs a new LocalTaxTypeBase object. Overrides TaxTypeBase::__construct 1
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TaxTypeBase::$entityId Deprecated protected property The ID of the parent config entity.
TaxTypeBase::$entityTypeManager protected property The entity type manager.
TaxTypeBase::$eventDispatcher protected property The event dispatcher.
TaxTypeBase::$parentEntity protected property The parent config entity.
TaxTypeBase::$profiles protected property A cache of prepared customer profiles, keyed by order ID.
TaxTypeBase::buildCustomerProfile protected function Builds a customer profile for the given order.
TaxTypeBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
TaxTypeBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 1
TaxTypeBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
TaxTypeBase::getLabel public function Gets the tax type label. Overrides TaxTypeInterface::getLabel
TaxTypeBase::getTaxableType protected function Gets the taxable type for the given order item.
TaxTypeBase::getWeight public function Gets the tax type weight. Overrides TaxTypeInterface::getWeight
TaxTypeBase::isDisplayInclusive public function Gets whether the tax type is display inclusive. Overrides TaxTypeInterface::isDisplayInclusive
TaxTypeBase::resolveCustomerProfile protected function Resolves the customer profile for the given order item.
TaxTypeBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration 1
TaxTypeBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 1
TaxTypeBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 1
TaxTypeBase::__sleep public function Overrides DependencySerializationTrait::__sleep
TaxTypeBase::__wakeup public function Overrides DependencySerializationTrait::__wakeup