Example #1
0
 /**
  * Init stock item
  *
  * @param \Magento\Quote\Model\Quote\Item\Option $option
  * @param \Magento\Quote\Model\Quote\Item $quoteItem
  *
  * @return \Magento\CatalogInventory\Model\Stock\Item
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getStockItem(\Magento\Quote\Model\Quote\Item\Option $option, \Magento\Quote\Model\Quote\Item $quoteItem)
 {
     $stockItem = $this->stockRegistry->getStockItem($option->getProduct()->getId(), $quoteItem->getStore()->getWebsiteId());
     if (!$stockItem->getItemId()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The stock item for Product in option is not valid.'));
     }
     /**
      * define that stock item is child for composite product
      */
     $stockItem->setIsChildItem(true);
     /**
      * don't check qty increments value for option product
      */
     $stockItem->setSuppressCheckQtyIncrements(true);
     return $stockItem;
 }
Example #2
0
 /**
  * Adds stock item qty to $items (creates new entry or increments existing one)
  * $items is array with following structure:
  * array(
  *  $productId  => array(
  *      'qty'   => $qty,
  *      'item'  => $stockItems|null
  *  )
  * )
  *
  * @param QuoteItem $quoteItem
  * @param array &$items
  * @return void
  */
 protected function _addItemToQtyArray(QuoteItem $quoteItem, &$items)
 {
     $productId = $quoteItem->getProductId();
     if (!$productId) {
         return;
     }
     if (isset($items[$productId])) {
         $items[$productId] += $quoteItem->getTotalQty();
     } else {
         $stockItem = null;
         if ($quoteItem->getProduct()) {
             /** @var Item $stockItem */
             $stockItem = $this->stockRegistry->getStockItem($quoteItem->getProduct()->getId(), $quoteItem->getStore()->getWebsiteId());
         }
         $items[$productId] = $quoteItem->getTotalQty();
     }
 }