コード例 #1
0
 public function testInitWithNonDecimalQty()
 {
     $quoteItemMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Item', ['getStockId', 'getIsQtyDecimal', '__wakeup'], [], '', false);
     $this->productMock->expects($this->once())->method('getId')->will($this->returnSelf());
     $this->productMock->expects($this->never())->method('setIsQtyDecimal');
     $this->productMock->expects($this->once())->method('setCartQty')->will($this->returnSelf());
     $this->configMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(10));
     $this->configMock->expects($this->once())->method('setQty')->will($this->returnSelf());
     $this->quoteMock->expects($this->once())->method('addProduct')->will($this->returnValue($quoteItemMock));
     $this->assertInstanceOf('Magento\\Quote\\Model\\Quote\\Item', $this->model->init($this->quoteMock, $this->productMock, $this->configMock));
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function init(\Magento\Quote\Model\Quote $quote, \Magento\Catalog\Model\Product $product, \Magento\Framework\DataObject $config)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'init');
     if (!$pluginInfo) {
         return parent::init($quote, $product, $config);
     } else {
         return $this->___callPlugins('init', func_get_args(), $pluginInfo);
     }
 }
コード例 #3
0
ファイル: Create.php プロジェクト: whoople/magento2-testing
 /**
  * Add product to current order quote
  * $product can be either product id or product model
  * $config can be either buyRequest config, or just qty
  *
  * @param int|\Magento\Catalog\Model\Product $product
  * @param array|float|int|\Magento\Framework\DataObject $config
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function addProduct($product, $config = 1)
 {
     if (!is_array($config) && !$config instanceof \Magento\Framework\DataObject) {
         $config = ['qty' => $config];
     }
     $config = new \Magento\Framework\DataObject($config);
     if (!$product instanceof \Magento\Catalog\Model\Product) {
         $productId = $product;
         $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->setStore($this->getSession()->getStore())->setStoreId($this->getSession()->getStoreId())->load($product);
         if (!$product->getId()) {
             throw new \Magento\Framework\Exception\LocalizedException(__('We could not add a product to cart by the ID "%1".', $productId));
         }
     }
     $item = $this->quoteInitializer->init($this->getQuote(), $product, $config);
     if (is_string($item)) {
         throw new \Magento\Framework\Exception\LocalizedException(__($item));
     }
     $item->checkData();
     $this->setRecollect(true);
     return $this;
 }