Skip to content

Commit ee1c1cc

Browse files
author
Alexey Yakimovich
committed
MAGETWO-91640: Import of Products fails on error when errors should be skipped
- Added warning message with skipped errors count information;
1 parent d3a62b1 commit ee1c1cc

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

app/code/Magento/ImportExport/Model/Import.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
namespace Magento\ImportExport\Model;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\HTTP\Adapter\FileTransferFactory;
1112
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
1213
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
14+
use Magento\Framework\Message\ManagerInterface;
1315

1416
/**
1517
* Import model
@@ -167,6 +169,11 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
167169
*/
168170
protected $_filesystem;
169171

172+
/**
173+
* @var ManagerInterface
174+
*/
175+
private $messageManager;
176+
170177
/**
171178
* @param \Psr\Log\LoggerInterface $logger
172179
* @param \Magento\Framework\Filesystem $filesystem
@@ -183,6 +190,7 @@ class Import extends \Magento\ImportExport\Model\AbstractModel
183190
* @param History $importHistoryModel
184191
* @param \Magento\Framework\Stdlib\DateTime\DateTime $localeDate
185192
* @param array $data
193+
* @param ManagerInterface|null $messageManager
186194
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
187195
*/
188196
public function __construct(
@@ -200,7 +208,8 @@ public function __construct(
200208
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
201209
\Magento\ImportExport\Model\History $importHistoryModel,
202210
\Magento\Framework\Stdlib\DateTime\DateTime $localeDate,
203-
array $data = []
211+
array $data = [],
212+
ManagerInterface $messageManager = null
204213
) {
205214
$this->_importExportData = $importExportData;
206215
$this->_coreConfig = $coreConfig;
@@ -215,6 +224,7 @@ public function __construct(
215224
$this->_filesystem = $filesystem;
216225
$this->importHistoryModel = $importHistoryModel;
217226
$this->localeDate = $localeDate;
227+
$this->messageManager = $messageManager ?: ObjectManager::getInstance()->get(ManagerInterface::class);
218228
parent::__construct($logger, $filesystem, $data);
219229
}
220230

@@ -588,9 +598,13 @@ public function validateSource(\Magento\ImportExport\Model\Import\AbstractSource
588598
$messages = $this->getOperationResultMessages($errorAggregator);
589599
$this->addLogComment($messages);
590600

591-
$result = !$errorAggregator->getErrorsCount();
601+
$errorsCount = $errorAggregator->getErrorsCount();
602+
$result = !$errorsCount;
592603
$validationStrategy = $this->getData(self::FIELD_NAME_VALIDATION_STRATEGY);
593-
if ($validationStrategy === ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS) {
604+
if ($errorsCount
605+
&& $validationStrategy === ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS
606+
) {
607+
$this->messageManager->addWarningMessage(sprintf(__('Skipped errors: %d'), $errorsCount));
594608
$result = true;
595609
}
596610

0 commit comments

Comments
 (0)