Skip to content

Commit

Permalink
[WD2-622] Remove rewrite of _saveStockItem() to support MSI
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van Leusden committed Feb 11, 2021
1 parent a7608c1 commit d280f90
Showing 1 changed file with 0 additions and 78 deletions.
78 changes: 0 additions & 78 deletions src/Rewrite/ImportExport/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,84 +571,6 @@ private function getProductEntityLinkField()
return $this->productEntityLinkField;
}

/**
* Stock item saving.
* @fixme https://github.com/magento/magento2/issues/5887
*
* @return $this
*/
protected function _saveStockItem()
{
/** @var $stockResource \Magento\CatalogInventory\Model\ResourceModel\Stock\Item */
$stockResource = $this->_stockResItemFac->create();
$entityTable = $stockResource->getMainTable();
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
$stockData = [];
$productIdsToReindex = [];
// Format bunch to stock data rows
foreach ($bunch as $rowNum => $rowData) {
if (!$this->isRowAllowedToImport($rowData, $rowNum)) {
continue;
}
$row = [];
$row['product_id'] = $this->skuProcessor->getNewSku($rowData[self::COL_SKU])['entity_id'];
$productIdsToReindex[] = $row['product_id'];
$row['website_id'] = $this->stockConfiguration->getDefaultScopeId();
$row['stock_id'] = $this->stockRegistry->getStock($row['website_id'])->getStockId();
$stockItemDo = $this->stockRegistry->getStockItem($row['product_id'], $row['website_id']);
$existStockData = $stockItemDo->getData();
$row = array_merge(
$this->defaultStockData,
array_intersect_key($existStockData, $this->defaultStockData),
array_intersect_key($rowData, $this->defaultStockData),
$row
);
if ($this->stockConfiguration->isQty(
$this->skuProcessor->getNewSku($rowData[self::COL_SKU])['type_id']
)
) {
$stockItemDo->setData($row);
$row['is_in_stock'] = $this->stockStateProvider->verifyStock($stockItemDo);
if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
$row['low_stock_date'] = $this->dateTime->gmDate(
'Y-m-d H:i:s',
(new \DateTime())->getTimestamp()
);
}
$row['stock_status_changed_auto']
= (int)!$this->stockStateProvider->verifyStock($stockItemDo);
} else {
$row['qty'] = 0;
}
if (!isset($stockData[$rowData[self::COL_SKU]])) {
$stockData[$rowData[self::COL_SKU]] = $row;
}
}
// Insert rows
if (!empty($stockData)) {
$this->_connection->insertOnDuplicate($entityTable, array_values($stockData));
}

$this->reindexProducts($productIdsToReindex);
}

return $this;
}

/**
* Initiate product reindex by product ids
*
* @param array $productIdsToReindex
* @return void
*/
private function reindexProducts($productIdsToReindex = [])
{
$indexer = $this->indexerRegistry->get('catalog_product_category');
if (\is_array($productIdsToReindex) && count($productIdsToReindex) > 0 && !$indexer->isScheduled()) {
$indexer->reindexList($productIdsToReindex);
}
}

/**
* Validate data row.
*
Expand Down

0 comments on commit d280f90

Please sign in to comment.