private function EventTrackerService::calculateTax in Commerce Google Tag Manager 8.2
Same name and namespace in other branches
- 8 src/EventTrackerService.php \Drupal\commerce_google_tag_manager\EventTrackerService::calculateTax()
Calculate the tax costs from the given order.
Parameters
\Drupal\commerce_order\Entity\OrderInterface $order: The order containing potential tax.
Return value
float The tax costs.
1 call to EventTrackerService::calculateTax()
- EventTrackerService::purchase in src/
EventTrackerService.php - Track a purchase of the given order entity.
File
- src/
EventTrackerService.php, line 426
Class
- EventTrackerService
- Track different events from Google's Enhanced Ecommerce.
Namespace
Drupal\commerce_google_tag_managerCode
private function calculateTax(OrderInterface $order) {
$tax_adjustments = array_filter($order
->collectAdjustments(), function (Adjustment $adjustment) {
return $adjustment
->getType() === 'tax' && !empty($adjustment
->getSourceId());
});
$total = 0;
/** @var \Drupal\commerce_order\Adjustment $tax_adjustment */
foreach ($tax_adjustments as $tax_adjustment) {
$total += (double) $tax_adjustment
->getAmount()
->getNumber();
}
return $total;
}