Skip to content

Commit 6f59233

Browse files
cebevzabaznov
authored andcommitted
Improve AdvancedPricingImportExport saving of bunch data
Current implementation inserts the same data from previous bunches again and again until the import finishes. This might work in most cases because the insert checks for duplicates but causes problems for imports that do some pre-processing on the data before running the insert. This changes also significantly improves import performance.
1 parent ffc08c4 commit 6f59233

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ protected function saveAndReplaceAdvancedPrices()
397397
$listSku = [];
398398
$tierPrices = [];
399399
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
400+
$bunchTierPrices = [];
400401
foreach ($bunch as $rowNum => $rowData) {
401402
if (!$this->validateRow($rowData, $rowNum)) {
402403
$this->addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, $rowNum);
@@ -410,7 +411,7 @@ protected function saveAndReplaceAdvancedPrices()
410411
$rowSku = $rowData[self::COL_SKU];
411412
$listSku[] = $rowSku;
412413
if (!empty($rowData[self::COL_TIER_PRICE_WEBSITE])) {
413-
$tierPrices[$rowSku][] = [
414+
$tierPrice = [
414415
'all_groups' => $rowData[self::COL_TIER_PRICE_CUSTOMER_GROUP] == self::VALUE_ALL_GROUPS,
415416
'customer_group_id' => $this->getCustomerGroupId(
416417
$rowData[self::COL_TIER_PRICE_CUSTOMER_GROUP]
@@ -422,17 +423,26 @@ protected function saveAndReplaceAdvancedPrices()
422423
? $rowData[self::COL_TIER_PRICE] : null,
423424
'website_id' => $this->getWebSiteId($rowData[self::COL_TIER_PRICE_WEBSITE])
424425
];
426+
if (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
427+
$bunchTierPrices[$rowSku][] = $tierPrice;
428+
}
429+
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
430+
$tierPrices[$rowSku][] = $tierPrice;
431+
}
425432
}
426433
}
427434

428435
if (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
429-
$this->processCountExistingPrices($tierPrices, self::TABLE_TIER_PRICE)
430-
->processCountNewPrices($tierPrices);
436+
$this->processCountExistingPrices($bunchTierPrices, self::TABLE_TIER_PRICE)
437+
->processCountNewPrices($bunchTierPrices);
431438

432-
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE);
433-
if ($listSku) {
434-
$this->setUpdatedAt($listSku);
435-
}
439+
$this->saveProductPrices($bunchTierPrices, self::TABLE_TIER_PRICE);
440+
}
441+
}
442+
443+
if (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
444+
if ($listSku) {
445+
$this->setUpdatedAt($listSku);
436446
}
437447
}
438448

0 commit comments

Comments
 (0)