You are here

protected function OrderHasProductsCondition::doEvaluate in Ubercart 8.4

Checks that the order has the selected combination of products.

Parameters

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

\Drupal\node\NodeInterface[] $products: TRUE if the product is required to be in the order.

bool $required: TRUE if the product is required to be in the order.

bool $forbidden: TRUE if the product is forbidden to be in the order.

Return value

bool TRUE if the order has the selected combination of products.

File

uc_order/src/Plugin/Condition/OrderHasProductsCondition.php, line 90

Class

OrderHasProductsCondition
Provides 'Order has specific product(s)' condition.

Namespace

Drupal\uc_order\Plugin\Condition

Code

protected function doEvaluate(OrderInterface $order, array $products, $required, $forbidden) {
  $order_products = [];
  foreach ($order->products as $product) {
    $order_products[] = $product->model;
  }
  $required_products = array_intersect($products, $order_products);
  if ($required) {
    $required_check = $required_products == $products;
  }
  else {
    $required_check = (bool) count($required_products);
  }
  if ($forbidden) {
    $forbidden_products = array_diff($order_products, $products);
    $forbidden_check = (bool) count($forbidden_products);
  }
  else {
    $forbidden_check = FALSE;
  }
  return $required_check && !$forbidden_check;
}