Exemple #1
0
 /**
  * @param string $field
  * @param StockItem $dataObject
  * @return mixed|null|string
  */
 public function getConfigFieldValue($field, StockItem $dataObject)
 {
     if ($dataObject->getStockId()) {
         if ($this->getDoFieldData('use_config_' . $field, $dataObject) == 0) {
             return $this->getDoFieldData($field, $dataObject);
         }
     }
     return $this->getDefaultConfigValue($field);
 }
Exemple #2
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());
 }
Exemple #3
0
 public function testBuildWithCurrentProductStockItem()
 {
     $expectedData = array('use_config_min_qty' => 1, 'use_config_min_sale_qty' => 1, 'use_config_max_sale_qty' => 1, 'use_config_backorders' => 1, 'use_config_notify_stock_qty' => 1, 'use_config_enable_qty_inc' => 'use_config_enable_qty_inc', 'enable_qty_increments' => 'enable_qty_increments', 'use_config_qty_increments' => 'use_config_qty_increments', 'qty_increments' => 'qty_increments');
     $this->stockItemServiceMock->expects($this->once())->method('getStockItem')->will($this->returnValue($this->stockItemDoMock));
     $this->stockItemDoMock->expects($this->any())->method('getStockId')->will($this->returnValue(50));
     $this->stockItemDoMock->expects($this->any())->method('isUseConfigEnableQtyInc')->will($this->returnValue('use_config_enable_qty_inc'));
     $this->stockItemDoMock->expects($this->any())->method('isEnableQtyIncrements')->will($this->returnValue('enable_qty_increments'));
     $this->stockItemDoMock->expects($this->any())->method('isUseConfigQtyIncrements')->will($this->returnValue('use_config_qty_increments'));
     $this->stockItemDoMock->expects($this->any())->method('getQtyIncrements')->will($this->returnValue('qty_increments'));
     $this->duplicateMock->expects($this->once())->method('setStockData')->with($expectedData);
     $this->model->build($this->productMock, $this->duplicateMock);
 }
Exemple #4
0
 /**
  * @param \Magento\CatalogInventory\Service\V1\Data\StockItem $stockItemDo
  * @return $this
  */
 public function saveStockItem($stockItemDo)
 {
     $stockItem = $this->stockItemRegistry->retrieve($stockItemDo->getProductId());
     $stockItem->setData($stockItemDo->__toArray());
     $stockItem->save();
     $this->stockItemRegistry->erase($stockItemDo->getProductId());
     return $this;
 }