Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward compatibility provided by #19765 #23407

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ abstract class AbstractEntity
*/
private $serializer;

/**
* @var string $uniqueField
*/
private $uniqueField;

/**
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
* @param \Magento\ImportExport\Helper\Data $importExportData
Expand All @@ -273,6 +278,7 @@ abstract class AbstractEntity
* @param \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper
* @param \Magento\Framework\Stdlib\StringUtils $string
* @param ProcessingErrorAggregatorInterface $errorAggregator
* @param string $uniqueField
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(
Expand All @@ -283,7 +289,8 @@ public function __construct(
ResourceConnection $resource,
\Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper,
\Magento\Framework\Stdlib\StringUtils $string,
ProcessingErrorAggregatorInterface $errorAggregator
ProcessingErrorAggregatorInterface $errorAggregator,
$uniqueField = 'sku'
) {
$this->jsonHelper = $jsonHelper;
$this->_importExportData = $importExportData;
Expand All @@ -300,6 +307,7 @@ public function __construct(
$this->_entityTypeId = $entityType->getEntityTypeId();
$this->_dataSourceModel = $importData;
$this->_connection = $resource->getConnection();
$this->uniqueField = $uniqueField;
}

/**
Expand Down Expand Up @@ -391,7 +399,7 @@ protected function _saveValidatedBunches()
$nextRowBackup = [];
$maxDataSize = $this->_resourceHelper->getMaxDataSize();
$bunchSize = $this->_importExportData->getBunchSize();
$skuSet = [];
$uniqueFieldSet = [];

$source->rewind();
$this->_dataSourceModel->cleanBunches();
Expand All @@ -408,8 +416,8 @@ protected function _saveValidatedBunches()
if ($source->valid()) {
try {
$rowData = $source->current();
if (array_key_exists('sku', $rowData)) {
$skuSet[$rowData['sku']] = true;
if ($this->uniqueField !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, revert array_key_exists check. We'll have undefined index error if $rowData does not contain $this->uniqueField field

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

$uniqueFieldSet[$rowData[$this->uniqueField]] = true;
}
} catch (\InvalidArgumentException $e) {
$this->addRowError($e->getMessage(), $this->_processedRowsCount);
Expand Down Expand Up @@ -438,8 +446,9 @@ protected function _saveValidatedBunches()
$source->next();
}
}
$this->_processedEntitiesCount = (count($skuSet)) ? : $this->_processedRowsCount;

if ($this->uniqueField !== null) {
$this->_processedEntitiesCount = count($uniqueFieldSet);
}
return $this;
}

Expand Down