You are here

protected function Order::getItemIndex in Commerce Core 8.2

Gets the index of the given order item.

Parameters

\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The order item.

Return value

int|bool The index of the given order item, or FALSE if not found.

2 calls to Order::getItemIndex()
Order::hasItem in modules/order/src/Entity/Order.php
Checks whether the order has a given order item.
Order::removeItem in modules/order/src/Entity/Order.php
Removes an order item.

File

modules/order/src/Entity/Order.php, line 318

Class

Order
Defines the order entity class.

Namespace

Drupal\commerce_order\Entity

Code

protected function getItemIndex(OrderItemInterface $order_item) {
  $values = $this
    ->get('order_items')
    ->getValue();
  $order_item_ids = array_map(function ($value) {
    return $value['target_id'];
  }, $values);
  return array_search($order_item
    ->id(), $order_item_ids);
}