public function TaxZone::__construct in Commerce Core 8.2
Constructs a new TaxZone instance.
Parameters
array $definition: The definition.
File
- modules/
tax/ src/ TaxZone.php, line 54
Class
- TaxZone
- Represents a tax zone.
Namespace
Drupal\commerce_taxCode
public function __construct(array $definition) {
foreach ([
'id',
'label',
'display_label',
'territories',
'rates',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $required_property));
}
}
foreach ([
'territories',
'rates',
] as $property) {
if (!is_array($definition[$property])) {
throw new \InvalidArgumentException(sprintf('The property "%s" must be an array.', $property));
}
}
$this->id = $definition['id'];
$this->label = $definition['label'];
$this->displayLabel = $definition['display_label'];
foreach ($definition['territories'] as $territory_definition) {
$this->territories[] = new ZoneTerritory($territory_definition);
}
foreach ($definition['rates'] as $rate_definition) {
$tax_rate = new TaxRate($rate_definition);
$this->rates[$tax_rate
->getId()] = $tax_rate;
}
}