public function testVerifyStock()
 {
     $productId = 143;
     $qty = 2.5;
     $result = true;
     $stockItemModel = $this->getStockItemModel($productId);
     $stockItemModel->expects($this->once())->method('verifyStock')->with($qty)->will($this->returnValue($result));
     $this->assertEquals($result, $this->model->verifyStock($productId, $qty));
 }
예제 #2
0
 /**
  * Stock item saving.
  *
  * @return $this
  */
 protected function _saveStockItem()
 {
     /** @var $stockResource \Magento\CatalogInventory\Model\Resource\Stock\Item */
     $stockResource = $this->_stockResItemFac->create();
     $entityTable = $stockResource->getMainTable();
     while ($bunch = $this->_dataSourceModel->getNextBunch()) {
         $stockData = array();
         $productIdsToReindex = array();
         // Format bunch to stock data rows
         foreach ($bunch as $rowNum => $rowData) {
             if (!$this->isRowAllowedToImport($rowData, $rowNum)) {
                 continue;
             }
             // only SCOPE_DEFAULT can contain stock data
             if (self::SCOPE_DEFAULT != $this->getRowScope($rowData)) {
                 continue;
             }
             $row = array();
             $row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['entity_id'];
             $productIdsToReindex[] = $row['product_id'];
             $row['stock_id'] = \Magento\CatalogInventory\Model\Stock\Item::DEFAULT_STOCK_ID;
             $stockItemDo = $this->stockItemService->getStockItem($row['product_id']);
             $existStockData = $stockItemDo->__toArray();
             $row = array_merge($this->defaultStockData, array_intersect_key($existStockData, $this->defaultStockData), array_intersect_key($rowData, $this->defaultStockData), $row);
             $row = $this->stockItemService->processIsInStock($row);
             if ($this->stockItemService->isQty($this->_newSku[$rowData[self::COL_SKU]]['type_id'])) {
                 if ($this->stockItemService->verifyNotification($row['product_id'])) {
                     $row['low_stock_date'] = $this->_localeDate->date(null, null, null, false)->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
                 }
                 $row['stock_status_changed_auto'] = (int) (!$this->stockItemService->verifyStock($row['product_id']));
             } else {
                 $row['qty'] = 0;
             }
             $stockData[] = $row;
         }
         // Insert rows
         if (!empty($stockData)) {
             $this->_connection->insertOnDuplicate($entityTable, $stockData);
         }
         if ($productIdsToReindex) {
             $this->newIndexer->load('catalog_product_category')->reindexList($productIdsToReindex);
         }
     }
     return $this;
 }