Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductQty.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Quote\Model\Quote\Item as QuoteItem;
10 
15 {
22  public function getProductQty($relatedItems)
23  {
24  $items = [];
25  foreach ($relatedItems as $item) {
26  $productId = $item->getProductId();
27  if (!$productId) {
28  continue;
29  }
30  $children = $item->getChildrenItems();
31  if ($children) {
32  foreach ($children as $childItem) {
33  $this->_addItemToQtyArray($childItem, $items);
34  }
35  } else {
36  $this->_addItemToQtyArray($item, $items);
37  }
38  }
39  return $items;
40  }
41 
49  protected function _addItemToQtyArray(QuoteItem $quoteItem, &$items)
50  {
51  $productId = $quoteItem->getProductId();
52  if (!$productId) {
53  return;
54  }
55  if (isset($items[$productId])) {
56  $items[$productId] += $quoteItem->getTotalQty();
57  } else {
58  $items[$productId] = $quoteItem->getTotalQty();
59  }
60  }
61 }
$quoteItem
Definition: quote.php:38
$children
Definition: actions.phtml:11
_addItemToQtyArray(QuoteItem $quoteItem, &$items)
Definition: ProductQty.php:49
$items