Skip to content

Commit

Permalink
⏫ Forwardport of #11719 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11719.patch (created by @nmalevanec) based on commit(s):
  1. 2bbad00
  2. ec0210e

Fixed GitHub Issues in 2.3-develop branch:
  - #10920: Sku => Entity_id relations are fetched inefficiently when inserting attributes values during product import (reported by @diwipl)
  • Loading branch information
magento-engcom-team committed Jan 23, 2018
1 parent 8e77e2f commit 7734bd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
17 changes: 6 additions & 11 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1298,20 +1297,15 @@ protected function _saveLinks()
*/
protected function _saveProductAttributes(array $attributesData)
{
$linkField = $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)][$linkField];
foreach ($attributes as $attributeId => $storeValues) {
foreach ($storeValues as $storeId => $storeValue) {
$tableData[] = [
$this->getProductEntityLinkField() => $linkId,
$linkField => $linkId,
'attribute_id' => $attributeId,
'store_id' => $storeId,
'value' => $storeValue,
Expand All @@ -1321,6 +1315,7 @@ protected function _saveProductAttributes(array $attributesData)
}
$this->_connection->insertOnDuplicate($tableName, $tableData, ['value']);
}

return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down

0 comments on commit 7734bd1

Please sign in to comment.