You are here

protected function OrderProductHasAttributeOption::doEvaluate in Ubercart 8.4

Determines if a product in the order has the selected attribute option.

Parameters

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

int $option_id: The option identifier.

Return value

bool TRUE if a product in the given order has the selected option.

File

uc_attribute/src/Plugin/Condition/OrderProductHasAttributeOption.php, line 103

Class

OrderProductHasAttributeOption
Provides 'Order has a product with a particular attribute option' condition.

Namespace

Drupal\uc_attribute\Plugin\Condition

Code

protected function doEvaluate(OrderInterface $order, $option_id) {
  $option = uc_attribute_option_load($option_id);
  $attribute = uc_attribute_load($option->aid);
  foreach ($order->products as $product) {
    if (!isset($product->data['attributes'])) {
      continue;
    }
    $attributes = $product->data['attributes'];

    // Once the order is made, the attribute data is changed to just the
    // names. So if we can't find the attribute by ID, check the names.
    if (is_int(key($attributes))) {
      if (isset($attributes[$option_id])) {
        return TRUE;
      }
    }
    elseif (isset($attributes[$attribute->name][$option_id])) {
      return TRUE;
    }
  }
  return FALSE;
}