Example #1
0
 public function testSetProductWithQuoteAndStockItem()
 {
     $productMock = $this->generateProductMock(self::PRODUCT_ID, self::PRODUCT_TYPE, self::PRODUCT_SKU, self::PRODUCT_NAME, self::PRODUCT_WEIGHT, self::PRODUCT_TAX_CLASS_ID, self::PRODUCT_COST);
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with('sales_quote_item_set_product', ['product' => $productMock, 'quote_item' => $this->model]);
     $isQtyDecimal = true;
     $this->stockItemDoMock->expects($this->once())->method('getStockId')->will($this->returnValue(99));
     $this->stockItemDoMock->expects($this->once())->method('getIsQtyDecimal')->will($this->returnValue($isQtyDecimal));
     $storeId = 15;
     $customerGroupId = 11;
     $quoteMock = $this->getMockBuilder('Magento\\Sales\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getStoreId', 'getCustomerGroupId', '__wakeup'])->getMock();
     $quoteMock->expects($this->once())->method('getStoreId')->will($this->returnValue($storeId));
     $quoteMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($customerGroupId));
     $this->model->setQuote($quoteMock);
     $productMock->expects($this->once())->method('setStoreId')->with($storeId);
     $productMock->expects($this->once())->method('setCustomerGroupId')->with($customerGroupId);
     $this->model->setProduct($productMock);
     $this->assertEquals($productMock, $this->model->getProduct());
     $this->assertEquals(self::PRODUCT_ID, $this->model->getProductId());
     $this->assertEquals(self::PRODUCT_TYPE, $this->model->getRealProductType());
     $this->assertEquals(self::PRODUCT_SKU, $this->model->getSku());
     $this->assertEquals(self::PRODUCT_NAME, $this->model->getName());
     $this->assertEquals(self::PRODUCT_WEIGHT, $this->model->getWeight());
     $this->assertEquals(self::PRODUCT_TAX_CLASS_ID, $this->model->getTaxClassId());
     $this->assertEquals(self::PRODUCT_COST, $this->model->getBaseCost());
     $this->assertEquals($isQtyDecimal, $this->model->getIsQtyDecimal());
 }
Example #2
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;
 }