You are here

public function Shipping::apply in Commerce Shipping 8.2

Applies the tax type to the given order.

Taxes should be added on the order item level, to make returns and refunds easier. This is true even for taxes that are only shown at the order level, such as sales taxes.

Parameters

\Drupal\commerce_order\Entity\OrderInterface $order: The order.

Overrides TaxTypeInterface::apply

File

src/Plugin/Commerce/TaxType/Shipping.php, line 204

Class

Shipping
Provides the Shipping tax type.

Namespace

Drupal\commerce_shipping\Plugin\Commerce\TaxType

Code

public function apply(OrderInterface $order) {
  $tax_adjustments = $order
    ->collectAdjustments([
    'tax',
  ]);

  // Filter-out adjustments with an unknown percentage or source ID,
  // usually indicative of a remote tax type.
  $tax_adjustments = array_filter($tax_adjustments, function (Adjustment $adjustment) {
    $percentage = $adjustment
      ->getPercentage();
    $source_id = $adjustment
      ->getSourceId();
    return isset($percentage) && substr_count($source_id, '|') === 2;
  });
  if (empty($tax_adjustments)) {
    return;
  }
  if ($this->configuration['strategy'] == 'default') {
    $this
      ->applyDefault($order, $tax_adjustments);
  }
  elseif ($this->configuration['strategy'] == 'highest') {
    $this
      ->applyHighest($order, $tax_adjustments);
  }
  elseif ($this->configuration['strategy'] == 'proportional') {
    $this
      ->applyProportional($order, $tax_adjustments);
  }
}