Skip to content

Commit 3a2417a

Browse files
committed
ACP2E-982: Assignment of sources changes after importing data
1 parent 0ee70b3 commit 3a2417a

File tree

1 file changed

+19
-3
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+19
-3
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\CatalogImportExport\Model\Import\Product\StatusProcessor;
1717
use Magento\CatalogImportExport\Model\Import\Product\StockProcessor;
1818
use Magento\CatalogImportExport\Model\StockItemImporterInterface;
19+
use Magento\CatalogImportExport\Model\StockItemProcessorInterface;
1920
use Magento\CatalogInventory\Api\Data\StockItemInterface;
2021
use Magento\Framework\App\Filesystem\DirectoryList;
2122
use Magento\Framework\App\ObjectManager;
@@ -227,7 +228,7 @@ class Product extends AbstractEntity
227228
* Links attribute name-to-link type ID.
228229
*
229230
* @deprecated 101.1.0 use DI for LinkProcessor class if you want to add additional types
230-
*
231+
* @see It is possible to supply additional link types via DI
231232
* @var array
232233
*/
233234
protected $_linkNameToId = [
@@ -548,6 +549,7 @@ class Product extends AbstractEntity
548549
/**
549550
* @var \Magento\CatalogInventory\Model\ResourceModel\Stock\ItemFactory
550551
* @deprecated 101.0.0 this variable isn't used anymore.
552+
* @see avoid using this variable
551553
*/
552554
protected $_stockResItemFac;
553555

@@ -613,6 +615,7 @@ class Product extends AbstractEntity
613615
* @var array
614616
* @deprecated 100.0.3
615617
* @since 100.0.3
618+
* @see avoid using this variable
616619
*/
617620
protected $productUrlKeys = [];
618621

@@ -751,6 +754,11 @@ class Product extends AbstractEntity
751754
*/
752755
private $linkProcessor;
753756

757+
/**
758+
* @var StockItemProcessorInterface
759+
*/
760+
private $stockItemProcessor;
761+
754762
/**
755763
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
756764
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -800,6 +808,7 @@ class Product extends AbstractEntity
800808
* @param StockProcessor|null $stockProcessor
801809
* @param LinkProcessor|null $linkProcessor
802810
* @param File|null $fileDriver
811+
* @param StockItemProcessorInterface|null $stockItemProcessor
803812
* @throws LocalizedException
804813
* @throws \Magento\Framework\Exception\FileSystemException
805814
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -854,7 +863,8 @@ public function __construct(
854863
StatusProcessor $statusProcessor = null,
855864
StockProcessor $stockProcessor = null,
856865
LinkProcessor $linkProcessor = null,
857-
?File $fileDriver = null
866+
?File $fileDriver = null,
867+
?StockItemProcessorInterface $stockItemProcessor = null
858868
) {
859869
$this->_eventManager = $eventManager;
860870
$this->stockRegistry = $stockRegistry;
@@ -918,6 +928,8 @@ public function __construct(
918928
$this->dateTimeFactory = $dateTimeFactory ?? ObjectManager::getInstance()->get(DateTimeFactory::class);
919929
$this->productRepository = $productRepository ?? ObjectManager::getInstance()
920930
->get(ProductRepositoryInterface::class);
931+
$this->stockItemProcessor = $stockItemProcessor ?? ObjectManager::getInstance()
932+
->get(StockItemProcessorInterface::class);
921933
}
922934

923935
/**
@@ -1280,6 +1292,7 @@ protected function _prepareRowForDb(array $rowData)
12801292
* Must be called after ALL products saving done.
12811293
*
12821294
* @deprecated 101.1.0 use linkProcessor Directly
1295+
* @see \Magento\CatalogImportExport\Model\Import\Product\linkProcessor::saveLinks
12831296
*
12841297
* @return $this
12851298
*/
@@ -1489,6 +1502,7 @@ private function getNewSkuFieldsForSelect()
14891502
* @return void
14901503
* @since 100.0.4
14911504
* @deprecated 100.2.3
1505+
* @see avoid using this function
14921506
*/
14931507
protected function initMediaGalleryResources()
14941508
{
@@ -2322,6 +2336,7 @@ protected function _saveStockItem()
23222336
{
23232337
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
23242338
$stockData = [];
2339+
$importedData = [];
23252340
$productIdsToReindex = [];
23262341
$stockChangedProductIds = [];
23272342
// Format bunch to stock data rows
@@ -2347,12 +2362,13 @@ protected function _saveStockItem()
23472362

23482363
if (!isset($stockData[$sku])) {
23492364
$stockData[$sku] = $row;
2365+
$importedData[$sku] = $rowData;
23502366
}
23512367
}
23522368

23532369
// Insert rows
23542370
if (!empty($stockData)) {
2355-
$this->stockItemImporter->import($stockData);
2371+
$this->stockItemProcessor->process($stockData, $importedData);
23562372
}
23572373

23582374
$this->reindexStockStatus($stockChangedProductIds);

0 commit comments

Comments
 (0)