Ejemplo n.º 1
0
 /**
  * Gets the index of the given line item.
  *
  * @param \Drupal\commerce_order\Entity\LineItemInterface $line_item
  *   The line item.
  *
  * @return int|bool
  *   The index of the given line item, or FALSE if not found.
  */
 protected function getLineItemIndex(LineItemInterface $line_item)
 {
     $values = $this->get('line_items')->getValue();
     $line_item_ids = array_map(function ($value) {
         return $value['target_id'];
     }, $values);
     return array_search($line_item->id(), $line_item_ids);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function updateLineItem(OrderInterface $cart, LineItemInterface $line_item)
 {
     /** @var \Drupal\commerce_order\Entity\LineItemInterface $original_line_item */
     $original_line_item = $this->lineItemStorage->loadUnchanged($line_item->id());
     $line_item->save();
     $event = new CartLineItemUpdateEvent($cart, $line_item, $original_line_item);
     $this->eventDispatcher->dispatch(CartEvents::CART_LINE_ITEM_UPDATE, $event);
 }