Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 755c24d

Browse files
MAGETWO-83322: 10920: Sku => Entity_id relations are fetched inefficiently when inserting attributes values during product import. #11719
2 parents 35f1d51 + 773e8c7 commit 755c24d

File tree

2 files changed

+7
-31
lines changed

2 files changed

+7
-31
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Import;
77

8+
use Magento\Catalog\Model\Config as CatalogConfig;
89
use Magento\Catalog\Model\Product\Visibility;
910
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
1011
use Magento\Framework\App\Filesystem\DirectoryList;
11-
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor;
1314
use Magento\Framework\Model\ResourceModel\Db\TransactionManagerInterface;
1415
use Magento\Framework\Stdlib\DateTime;
15-
use Magento\Framework\Filesystem;
1616
use Magento\ImportExport\Model\Import;
1717
use Magento\ImportExport\Model\Import\Entity\AbstractEntity;
1818
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
1919
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
20-
use Magento\Catalog\Model\Config as CatalogConfig;
2120

2221
/**
2322
* Import entity product model
@@ -1293,20 +1292,15 @@ protected function _saveLinks()
12931292
*/
12941293
protected function _saveProductAttributes(array $attributesData)
12951294
{
1295+
$linkField = $this->getProductEntityLinkField();
12961296
foreach ($attributesData as $tableName => $skuData) {
12971297
$tableData = [];
12981298
foreach ($skuData as $sku => $attributes) {
1299-
$linkId = $this->_connection->fetchOne(
1300-
$this->_connection->select()
1301-
->from($this->getResource()->getTable('catalog_product_entity'))
1302-
->where('sku = ?', (string)$sku)
1303-
->columns($this->getProductEntityLinkField())
1304-
);
1305-
1299+
$linkId = $this->_oldSku[strtolower($sku)][$linkField];
13061300
foreach ($attributes as $attributeId => $storeValues) {
13071301
foreach ($storeValues as $storeId => $storeValue) {
13081302
$tableData[] = [
1309-
$this->getProductEntityLinkField() => $linkId,
1303+
$linkField => $linkId,
13101304
'attribute_id' => $attributeId,
13111305
'store_id' => $storeId,
13121306
'value' => $storeValue,
@@ -1316,6 +1310,7 @@ protected function _saveProductAttributes(array $attributesData)
13161310
}
13171311
$this->_connection->insertOnDuplicate($tableName, $tableData, ['value']);
13181312
}
1313+
13191314
return $this;
13201315
}
13211316

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\CatalogImportExport\Test\Unit\Model\Import;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9-
use Magento\Framework\Stdlib\DateTime;
109
use Magento\ImportExport\Model\Import;
1110

1211
/**
@@ -513,25 +512,6 @@ public function testSaveProductAttributes()
513512
]
514513
]
515514
];
516-
$entityTable = 'catalog_product_entity';
517-
$resource = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModel::class)
518-
->disableOriginalConstructor()
519-
->setMethods(['getTable'])
520-
->getMock();
521-
$resource->expects($this->once())->method('getTable')->with($entityTable)->willReturnArgument(0);
522-
$this->_resourceFactory->expects($this->once())->method('create')->willReturn($resource);
523-
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
524-
->disableOriginalConstructor()
525-
->getMock();
526-
$selectMock->expects($this->once())->method('from')->with($entityTable, '*', null)->willReturnSelf();
527-
$selectMock->expects($this->once())->method('where')->with('sku = ?', $testSku)->willReturnSelf();
528-
$selectMock->expects($this->once())->method('columns')->with('entity_id')->willReturnSelf();
529-
$this->_connection->expects($this->any())->method('fetchOne')->willReturn(self::ENTITY_ID);
530-
$this->_connection->expects($this->any())->method('select')->willReturn($selectMock);
531-
$this->_connection->expects($this->any())
532-
->method('quoteInto')
533-
->willReturnCallback([$this, 'returnQuoteCallback']);
534-
535515
$tableData[] = [
536516
'entity_id' => self::ENTITY_ID,
537517
'attribute_id' => $attributeId,
@@ -541,6 +521,7 @@ public function testSaveProductAttributes()
541521
$this->_connection->expects($this->once())
542522
->method('insertOnDuplicate')
543523
->with($testTable, $tableData, ['value']);
524+
$this->setPropertyValue($this->importProduct, '_oldSku', [$testSku => ['entity_id' => self::ENTITY_ID]]);
544525
$object = $this->invokeMethod($this->importProduct, '_saveProductAttributes', [$attributesData]);
545526
$this->assertEquals($this->importProduct, $object);
546527
}

0 commit comments

Comments
 (0)