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
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\commerce_tax\Plugin\Commerce\TaxType\TaxTypeBase implements TaxTypeInterface, ContainerFactoryPluginInterface
- class \Drupal\commerce_tax\Plugin\Commerce\TaxType\LocalTaxTypeBase implements LocalTaxTypeInterface
- class \Drupal\commerce_tax\Plugin\Commerce\TaxType\CanadianSalesTax
- class \Drupal\commerce_tax\Plugin\Commerce\TaxType\LocalTaxTypeBase implements LocalTaxTypeInterface
- class \Drupal\commerce_tax\Plugin\Commerce\TaxType\TaxTypeBase implements TaxTypeInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CanadianSalesTax
File
- modules/
tax/ src/ Plugin/ Commerce/ TaxType/ CanadianSalesTax.php, line 19
Namespace
Drupal\commerce_tax\Plugin\Commerce\TaxTypeView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CanadianSalesTax:: |
public | function |
Form constructor. Overrides TaxTypeBase:: |
|
CanadianSalesTax:: |
public | function |
Builds the tax zones. Overrides LocalTaxTypeBase:: |
|
CanadianSalesTax:: |
protected | function |
Checks whether the tax type matches the store's billing address. Overrides LocalTaxTypeBase:: |
|
CanadianSalesTax:: |
protected | function |
Checks whether the tax type matches the store's tax registrations. Overrides LocalTaxTypeBase:: |
|
CanadianSalesTax:: |
protected | function |
Resolves the tax zones for the given order item and customer profile. Overrides LocalTaxTypeBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
LocalTaxTypeBase:: |
protected | property | The chain tax rate resolver. | |
LocalTaxTypeBase:: |
protected | property | The matched zones. | |
LocalTaxTypeBase:: |
protected | property | The rounder. | |
LocalTaxTypeBase:: |
protected | property | The zones. | |
LocalTaxTypeBase:: |
public | function |
Checks whether the tax type applies to the given order. Overrides TaxTypeBase:: |
|
LocalTaxTypeBase:: |
public | function |
Applies the tax type to the given order. Overrides TaxTypeInterface:: |
|
LocalTaxTypeBase:: |
protected | function | Builds the summary of all available tax rates. | |
LocalTaxTypeBase:: |
protected | function | Checks whether the store is registered to collect taxes in the given zone. | |
LocalTaxTypeBase:: |
public static | function |
Creates an instance of the plugin. Overrides TaxTypeBase:: |
1 |
LocalTaxTypeBase:: |
public | function |
Gets the tax zones which match the given address. Overrides LocalTaxTypeInterface:: |
|
LocalTaxTypeBase:: |
public | function |
Gets the tax zones. Overrides LocalTaxTypeInterface:: |
|
LocalTaxTypeBase:: |
protected | function | Resolves the tax rates for the given order item and customer profile. | |
LocalTaxTypeBase:: |
public | function |
Gets whether tax should be rounded at the order item level. Overrides LocalTaxTypeInterface:: |
1 |
LocalTaxTypeBase:: |
public | function |
Constructs a new LocalTaxTypeBase object. Overrides TaxTypeBase:: |
1 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TaxTypeBase:: |
protected | property | The ID of the parent config entity. | |
TaxTypeBase:: |
protected | property | The entity type manager. | |
TaxTypeBase:: |
protected | property | The event dispatcher. | |
TaxTypeBase:: |
protected | property | The parent config entity. | |
TaxTypeBase:: |
protected | property | A cache of prepared customer profiles, keyed by order ID. | |
TaxTypeBase:: |
protected | function | Builds a customer profile for the given order. | |
TaxTypeBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
TaxTypeBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
1 |
TaxTypeBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
TaxTypeBase:: |
public | function |
Gets the tax type label. Overrides TaxTypeInterface:: |
|
TaxTypeBase:: |
protected | function | Gets the taxable type for the given order item. | |
TaxTypeBase:: |
public | function |
Gets the tax type weight. Overrides TaxTypeInterface:: |
|
TaxTypeBase:: |
public | function |
Gets whether the tax type is display inclusive. Overrides TaxTypeInterface:: |
|
TaxTypeBase:: |
protected | function | Resolves the customer profile for the given order item. | |
TaxTypeBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
1 |
TaxTypeBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
1 |
TaxTypeBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
TaxTypeBase:: |
public | function |
Overrides DependencySerializationTrait:: |
|
TaxTypeBase:: |
public | function |
Overrides DependencySerializationTrait:: |