You are here

protected function ShippingMethodCondition::doEvaluate in Ubercart 8.4

Checks an order's shipping method.

Parameters

\Drupal\uc_order\OrderInterface $order: The order.

string $method: Name of shipping method.

Return value

bool TRUE if the order was placed with the selected shipping method.

File

shipping/uc_quote/src/Plugin/Condition/ShippingMethodCondition.php, line 102

Class

ShippingMethodCondition
Provides an 'Order shipping method' condition.

Namespace

Drupal\uc_quote\Plugin\Condition

Code

protected function doEvaluate(OrderInterface $order, $method) {

  // Check the easy way first.
  if (!empty($order->quote)) {
    return $order->quote['method'] == $method;
  }

  // Otherwise, look harder.
  if (!empty($order->line_items)) {
    $methods = $this->moduleHandler
      ->invokeAll('uc_shipping_method');
    $accessorials = $methods[$method]['quote']['accessorials'];
    foreach ($order->line_items as $line_item) {
      if ($line_item['type'] == 'shipping' && in_array($line_item['title'], $accessorials)) {
        return TRUE;
      }
    }
  }
  return FALSE;
}