Example #1
0
 public function testUpdateQuoteItemsWithConfiguredOption()
 {
     $qty = 100000000;
     $items = array(1 => array('qty' => 10, 'configured' => true, 'action' => false));
     $itemMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Item', array(), array(), '', false);
     $itemMock->expects($this->once())->method('getQty')->will($this->returnValue($qty));
     $quoteMock = $this->getMock('Magento\\Sales\\Model\\Quote', array(), array(), '', false);
     $quoteMock->expects($this->once())->method('updateItem')->will($this->returnValue($itemMock));
     $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
     $expectedInfo = $items[1];
     $expectedInfo['qty'] = $qty;
     $this->itemUpdater->expects($this->once())->method('update')->with($this->equalTo($itemMock), $this->equalTo($expectedInfo));
     $this->adminOrderCreate->setRecollect(false);
     $this->adminOrderCreate->updateQuoteItems($items);
 }
Example #2
0
 /**
  * Update quantity of order quote items
  *
  * @param array $items
  * @return $this
  * @throws \Exception|\Magento\Framework\Model\Exception
  */
 public function updateQuoteItems($items)
 {
     if (!is_array($items)) {
         return $this;
     }
     try {
         foreach ($items as $itemId => $info) {
             if (!empty($info['configured'])) {
                 $item = $this->getQuote()->updateItem($itemId, $this->objectFactory->create($info));
                 $info['qty'] = (double) $item->getQty();
             } else {
                 $item = $this->getQuote()->getItemById($itemId);
                 if (!$item) {
                     continue;
                 }
                 $info['qty'] = (double) $info['qty'];
             }
             $this->quoteItemUpdater->update($item, $info);
             if ($item && !empty($info['action'])) {
                 $this->moveQuoteItem($item, $info['action'], $item->getQty());
             }
         }
     } catch (\Magento\Framework\Model\Exception $e) {
         $this->recollectCart();
         throw $e;
     } catch (\Exception $e) {
         $this->_logger->logException($e);
     }
     $this->recollectCart();
     return $this;
 }