Example #1
0
 /**
  * Adding new item to quote
  *
  * @param   \Magento\Sales\Model\Quote\Item $item
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 public function addItem(\Magento\Sales\Model\Quote\Item $item)
 {
     /**
      * Temporary workaround for purchase process: it is too dangerous to purchase more than one nominal item
      * or a mixture of nominal and non-nominal items, although technically possible.
      *
      * The problem is that currently it is implemented as sequential submission of nominal items and order,
      * by one click. It makes logically impossible to make the process of the purchase failsafe.
      * Proper solution is to submit items one by one with customer confirmation each time.
      */
     if ($item->isNominal() && $this->hasItems() || $this->hasNominalItems()) {
         throw new \Magento\Framework\Model\Exception(__('Sorry, but items with payment agreements must be ordered one at a time To continue, please remove or buy the other items in your cart, then order this item by itself.'));
     }
     $item->setQuote($this);
     if (!$item->getId()) {
         $this->getItemsCollection()->addItem($item);
         $this->_eventManager->dispatch('sales_quote_add_item', array('quote_item' => $item));
     }
     return $this;
 }