You are here

public function Shipping::applies in Commerce Shipping 8.2

Checks whether the tax type applies to the given order.

Parameters

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

Return value

bool TRUE if the tax type applies, FALSE otherwise.

Overrides TaxTypeBase::applies

File

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

Class

Shipping
Provides the Shipping tax type.

Namespace

Drupal\commerce_shipping\Plugin\Commerce\TaxType

Code

public function applies(OrderInterface $order) {
  if (!$this->shippingOrderManager
    ->isShippable($order)) {
    return FALSE;
  }

  /** @var \Drupal\commerce_shipping\Entity\ShipmentInterface[] $shipments */
  $shipments = $order
    ->get('shipments')
    ->referencedEntities();
  if (empty($shipments)) {
    return FALSE;
  }
  $store_filter = $this->configuration['store_filter'];
  if ($store_filter != 'none') {
    $match = in_array($order
      ->getStore()
      ->uuid(), $this->configuration['stores']);
    $match = $store_filter == 'include' ? $match : !$match;
    if (!$match) {
      return FALSE;
    }
  }
  return TRUE;
}