Skip to content
Merged
Show file tree
Hide file tree
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
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 @@ -1293,20 +1292,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 @@ -1316,6 +1310,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