Skip to content

Commit d37bc74

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-982' into PR_21_SEP_2022
2 parents 24a2c46 + 5b91ee0 commit d37bc74

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

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

Lines changed: 17 additions & 4 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;
@@ -229,7 +230,6 @@ class Product extends AbstractEntity
229230
* @deprecated 101.1.0 use DI for LinkProcessor class if you want to add additional types
230231
*
231232
* @see Magento_CatalogImportExport::etc/di.xml
232-
*
233233
* @var array
234234
*/
235235
protected $_linkNameToId = [
@@ -615,8 +615,8 @@ class Product extends AbstractEntity
615615
/**
616616
* @var array
617617
* @deprecated 100.0.3
618-
* @since 100.0.3
619618
*
619+
* @since 100.0.3
620620
* @see we don't recommend this approach anymore
621621
*/
622622
protected $productUrlKeys = [];
@@ -756,6 +756,11 @@ class Product extends AbstractEntity
756756
*/
757757
private $linkProcessor;
758758

759+
/**
760+
* @var StockItemProcessorInterface
761+
*/
762+
private $stockItemProcessor;
763+
759764
/**
760765
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
761766
* @param \Magento\ImportExport\Helper\Data $importExportData
@@ -805,6 +810,7 @@ class Product extends AbstractEntity
805810
* @param StockProcessor|null $stockProcessor
806811
* @param LinkProcessor|null $linkProcessor
807812
* @param File|null $fileDriver
813+
* @param StockItemProcessorInterface|null $stockItemProcessor
808814
* @throws LocalizedException
809815
* @throws \Magento\Framework\Exception\FileSystemException
810816
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -859,7 +865,8 @@ public function __construct(
859865
StatusProcessor $statusProcessor = null,
860866
StockProcessor $stockProcessor = null,
861867
LinkProcessor $linkProcessor = null,
862-
?File $fileDriver = null
868+
?File $fileDriver = null,
869+
?StockItemProcessorInterface $stockItemProcessor = null
863870
) {
864871
$this->_eventManager = $eventManager;
865872
$this->stockRegistry = $stockRegistry;
@@ -923,6 +930,8 @@ public function __construct(
923930
$this->dateTimeFactory = $dateTimeFactory ?? ObjectManager::getInstance()->get(DateTimeFactory::class);
924931
$this->productRepository = $productRepository ?? ObjectManager::getInstance()
925932
->get(ProductRepositoryInterface::class);
933+
$this->stockItemProcessor = $stockItemProcessor ?? ObjectManager::getInstance()
934+
->get(StockItemProcessorInterface::class);
926935
}
927936

928937
/**
@@ -1286,6 +1295,7 @@ protected function _prepareRowForDb(array $rowData)
12861295
*
12871296
* @deprecated 101.1.0 use linkProcessor Directly
12881297
* @see linkProcessor
1298+
*
12891299
* @return $this
12901300
*/
12911301
protected function _saveLinks()
@@ -2328,6 +2338,7 @@ protected function _saveStockItem()
23282338
{
23292339
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
23302340
$stockData = [];
2341+
$importedData = [];
23312342
$productIdsToReindex = [];
23322343
$stockChangedProductIds = [];
23332344
// Format bunch to stock data rows
@@ -2353,12 +2364,13 @@ protected function _saveStockItem()
23532364

23542365
if (!isset($stockData[$sku])) {
23552366
$stockData[$sku] = $row;
2367+
$importedData[$sku] = $rowData;
23562368
}
23572369
}
23582370

23592371
// Insert rows
23602372
if (!empty($stockData)) {
2361-
$this->stockItemImporter->import($stockData);
2373+
$this->stockItemProcessor->process($stockData, $importedData);
23622374
}
23632375

23642376
$this->reindexStockStatus($stockChangedProductIds);
@@ -2512,6 +2524,7 @@ public function getRowScope(array $rowData)
25122524
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
25132525
* @SuppressWarnings(PHPMD.NPathComplexity)
25142526
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2527+
* @throws \Zend_Validate_Exception
25152528
*/
25162529
public function validateRow(array $rowData, $rowNum)
25172530
{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model;
9+
10+
class StockItemProcessor implements StockItemProcessorInterface
11+
{
12+
/**
13+
* @var StockItemImporterInterface
14+
*/
15+
private $stockItemImporter;
16+
17+
/**
18+
* @param StockItemImporterInterface $stockItemImporter
19+
*/
20+
public function __construct(
21+
StockItemImporterInterface $stockItemImporter
22+
) {
23+
$this->stockItemImporter = $stockItemImporter;
24+
}
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
public function process(array $stockData, array $importedData): void
30+
{
31+
$this->stockItemImporter->import($stockData);
32+
}
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model;
9+
10+
use Magento\Framework\Exception\CouldNotSaveException;
11+
use Magento\Framework\Exception\InputException;
12+
use Magento\Framework\Validation\ValidationException;
13+
14+
interface StockItemProcessorInterface
15+
{
16+
/**
17+
* Handle Import of Stock Item Data
18+
*
19+
* @param array $stockData
20+
* @param array $importedData
21+
* @return void
22+
* @throws CouldNotSaveException
23+
* @throws InputException
24+
* @throws ValidationException
25+
*/
26+
public function process(array $stockData, array $importedData): void;
27+
}

app/code/Magento/CatalogImportExport/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\CatalogImportExport\Model\Export\RowCustomizerInterface" type="Magento\CatalogImportExport\Model\Export\RowCustomizer\Composite" />
1010
<preference for="Magento\CatalogImportExport\Model\StockItemImporterInterface" type="Magento\CatalogImportExport\Model\StockItemImporter" />
11+
<preference for="Magento\CatalogImportExport\Model\StockItemProcessorInterface" type="Magento\CatalogImportExport\Model\StockItemProcessor" />
1112
<preference for="Magento\CatalogImportExport\Model\Export\ProductFilterInterface" type="Magento\CatalogImportExport\Model\Export\ProductFilters" />
1213
<type name="Magento\ImportExport\Model\Import">
1314
<plugin name="catalogProductFlatIndexerImport" type="Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import" />

0 commit comments

Comments
 (0)