Пример #1
0
 /**
  * Initialize item option
  *
  * @param \Magento\Sales\Model\Quote\Item\Option $option
  * @param \Magento\Sales\Model\Quote\Item $quoteItem
  * @param int $qty
  *
  * @return \Magento\Framework\Object
  * @throws \Magento\Framework\Model\Exception
  */
 public function initialize(\Magento\Sales\Model\Quote\Item\Option $option, \Magento\Sales\Model\Quote\Item $quoteItem, $qty)
 {
     $optionValue = $option->getValue();
     $optionQty = $qty * $optionValue;
     $increaseOptionQty = ($quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty) * $optionValue;
     $qtyForCheck = $this->quoteItemQtyList->getQty($option->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseOptionQty);
     $stockItem = $this->getStockItem($option, $quoteItem);
     $result = $stockItem->checkQuoteItemQty($optionQty, $qtyForCheck, $optionValue);
     if (!is_null($result->getItemIsQtyDecimal())) {
         $option->setIsQtyDecimal($result->getItemIsQtyDecimal());
     }
     if ($result->getHasQtyOptionUpdate()) {
         $option->setHasQtyOptionUpdate(true);
         $quoteItem->updateQtyOption($option, $result->getOrigQty());
         $option->setValue($result->getOrigQty());
         /**
          * if option's qty was updates we also need to update quote item qty
          */
         $quoteItem->setData('qty', intval($qty));
     }
     if (!is_null($result->getMessage())) {
         $option->setMessage($result->getMessage());
         $quoteItem->setMessage($result->getMessage());
     }
     if (!is_null($result->getItemBackorders())) {
         $option->setBackorders($result->getItemBackorders());
     }
     $stockItem->unsIsChildItem();
     return $result;
 }