From 2bbad00ea2d09e525c3082878ca5bb6bc862fe5a Mon Sep 17 00:00:00 2001 From: magento-engcom-team Date: Wed, 25 Oct 2017 13:19:04 +0300 Subject: [PATCH 1/2] MAGETWO-10920: Sku => Entity_id relations are fetched inefficiently when inserting attributes values during product import. --- .../Model/Import/Product.php | 17 ++++++--------- .../Test/Unit/Model/Import/ProductTest.php | 21 +------------------ 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index a0f1e25cf6512..a8935f31bbd62 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -5,19 +5,18 @@ */ namespace Magento\CatalogImportExport\Model\Import; +use Magento\Catalog\Model\Config as CatalogConfig; use Magento\Catalog\Model\Product\Visibility; use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\Filesystem; use Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor; use Magento\Framework\Model\ResourceModel\Db\TransactionManagerInterface; use Magento\Framework\Stdlib\DateTime; -use Magento\Framework\Filesystem; use Magento\ImportExport\Model\Import; use Magento\ImportExport\Model\Import\Entity\AbstractEntity; use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError; use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface; -use Magento\Catalog\Model\Config as CatalogConfig; /** * Import entity product model @@ -1293,20 +1292,15 @@ protected function _saveLinks() */ protected function _saveProductAttributes(array $attributesData) { + $productEntityLinkField = $this->getProductEntityLinkField(); foreach ($attributesData as $tableName => $skuData) { $tableData = []; foreach ($skuData as $sku => $attributes) { - $linkId = $this->_connection->fetchOne( - $this->_connection->select() - ->from($this->getResource()->getTable('catalog_product_entity')) - ->where('sku = ?', (string)$sku) - ->columns($this->getProductEntityLinkField()) - ); - + $linkId = $this->_oldSku[strtolower($sku)][$productEntityLinkField]; foreach ($attributes as $attributeId => $storeValues) { foreach ($storeValues as $storeId => $storeValue) { $tableData[] = [ - $this->getProductEntityLinkField() => $linkId, + $productEntityLinkField => $linkId, 'attribute_id' => $attributeId, 'store_id' => $storeId, 'value' => $storeValue, @@ -1316,6 +1310,7 @@ protected function _saveProductAttributes(array $attributesData) } $this->_connection->insertOnDuplicate($tableName, $tableData, ['value']); } + return $this; } diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php index 862276d35bac5..743557f7eac8a 100644 --- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php +++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php @@ -6,7 +6,6 @@ namespace Magento\CatalogImportExport\Test\Unit\Model\Import; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Stdlib\DateTime; use Magento\ImportExport\Model\Import; /** @@ -513,25 +512,6 @@ public function testSaveProductAttributes() ] ] ]; - $entityTable = 'catalog_product_entity'; - $resource = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModel::class) - ->disableOriginalConstructor() - ->setMethods(['getTable']) - ->getMock(); - $resource->expects($this->once())->method('getTable')->with($entityTable)->willReturnArgument(0); - $this->_resourceFactory->expects($this->once())->method('create')->willReturn($resource); - $selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class) - ->disableOriginalConstructor() - ->getMock(); - $selectMock->expects($this->once())->method('from')->with($entityTable, '*', null)->willReturnSelf(); - $selectMock->expects($this->once())->method('where')->with('sku = ?', $testSku)->willReturnSelf(); - $selectMock->expects($this->once())->method('columns')->with('entity_id')->willReturnSelf(); - $this->_connection->expects($this->any())->method('fetchOne')->willReturn(self::ENTITY_ID); - $this->_connection->expects($this->any())->method('select')->willReturn($selectMock); - $this->_connection->expects($this->any()) - ->method('quoteInto') - ->willReturnCallback([$this, 'returnQuoteCallback']); - $tableData[] = [ 'entity_id' => self::ENTITY_ID, 'attribute_id' => $attributeId, @@ -541,6 +521,7 @@ public function testSaveProductAttributes() $this->_connection->expects($this->once()) ->method('insertOnDuplicate') ->with($testTable, $tableData, ['value']); + $this->setPropertyValue($this->importProduct, '_oldSku', [$testSku => ['entity_id' => self::ENTITY_ID]]); $object = $this->invokeMethod($this->importProduct, '_saveProductAttributes', [$attributesData]); $this->assertEquals($this->importProduct, $object); } From ec0210e602a503fe5c4ec097e336381ec7a8bc2e Mon Sep 17 00:00:00 2001 From: magento-engcom-team Date: Wed, 25 Oct 2017 16:10:05 +0300 Subject: [PATCH 2/2] MAGETWO-10920: Sku => Entity_id relations are fetched inefficiently when inserting attributes values during product import. --- .../Magento/CatalogImportExport/Model/Import/Product.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index a8935f31bbd62..26af4a1152900 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -1292,15 +1292,15 @@ protected function _saveLinks() */ protected function _saveProductAttributes(array $attributesData) { - $productEntityLinkField = $this->getProductEntityLinkField(); + $linkField = $this->getProductEntityLinkField(); foreach ($attributesData as $tableName => $skuData) { $tableData = []; foreach ($skuData as $sku => $attributes) { - $linkId = $this->_oldSku[strtolower($sku)][$productEntityLinkField]; + $linkId = $this->_oldSku[strtolower($sku)][$linkField]; foreach ($attributes as $attributeId => $storeValues) { foreach ($storeValues as $storeId => $storeValue) { $tableData[] = [ - $productEntityLinkField => $linkId, + $linkField => $linkId, 'attribute_id' => $attributeId, 'store_id' => $storeId, 'value' => $storeValue,