public function PercentageTaxRate::calculateTax in Ubercart 8.4
Returns the amount of tax for the order.
Parameters
\Drupal\uc_order\OrderInterface $order: The order that is being processed.
Return value
\Drupal\uc_tax\TaxLineItem
Overrides TaxRatePluginBase::calculateTax
File
- uc_tax/
src/ Plugin/ Ubercart/ TaxRate/ PercentageTaxRate.php, line 90
Class
- PercentageTaxRate
- Defines the fixed percentage tax rate.
Namespace
Drupal\uc_tax\Plugin\Ubercart\TaxRateCode
public function calculateTax(OrderInterface $order) {
$rate = $this->configuration['rate'];
$jurisdiction = $this->configuration['jurisdiction'];
$field = $this->configuration['field'];
foreach ($order->products as $product) {
if (isset($product->nid->entity->{$field}->value)) {
$product_rate = $product->nid->entity->{$field}->value * $product->qty->value;
}
else {
$product_rate = $this->configuration['rate'] * $product->qty->value;
}
$rate += $product->price->value * floatval($product_rate) / 100;
}
return [
$rate,
];
}