Skip to content

Commit 1d602a3

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-73922' into 2.2-develop-pr60
2 parents 7d459d5 + 8c83a6e commit 1d602a3

File tree

2 files changed

+34
-5
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import/Product/Type
  • dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/Product/Type

2 files changed

+34
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ public function __construct(
195195
}
196196

197197
/**
198+
* Initialize template for error message.
199+
*
198200
* @param array $templateCollection
199201
* @return $this
200202
*/
@@ -377,6 +379,8 @@ public function retrieveAttributeFromCache($attributeCode)
377379
}
378380

379381
/**
382+
* Adding attribute option.
383+
*
380384
* In case we've dynamically added new attribute option during import we need to add it to our cache
381385
* in order to keep it up to date.
382386
*
@@ -508,8 +512,10 @@ public function isSuitable()
508512
}
509513

510514
/**
511-
* Prepare attributes values for save: exclude non-existent, static or with empty values attributes;
512-
* set default values if needed
515+
* Adding default attribute to product before save.
516+
*
517+
* Prepare attributes values for save: exclude non-existent, static or with empty values attributes,
518+
* set default values if needed.
513519
*
514520
* @param array $rowData
515521
* @param bool $withDefaultValue
@@ -537,9 +543,9 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
537543
} else {
538544
$resultAttrs[$attrCode] = $rowData[$attrCode];
539545
}
540-
} elseif (array_key_exists($attrCode, $rowData)) {
546+
} elseif (array_key_exists($attrCode, $rowData) && empty($rowData['_store'])) {
541547
$resultAttrs[$attrCode] = $rowData[$attrCode];
542-
} elseif ($withDefaultValue && null !== $attrParams['default_value']) {
548+
} elseif ($withDefaultValue && null !== $attrParams['default_value'] && empty($rowData['_store'])) {
543549
$resultAttrs[$attrCode] = $attrParams['default_value'];
544550
}
545551
}
@@ -605,7 +611,8 @@ protected function getProductEntityLinkField()
605611
}
606612

607613
/**
608-
* Clean cached values
614+
* Clean cached values.
615+
*
609616
* @since 100.2.0
610617
*/
611618
public function __destruct()

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ protected function setUp()
4343
}
4444

4545
/**
46+
* Test adding default attribute to product before save.
47+
*
48+
* @param array $rowData
49+
* @param bool $withDefaultValue
50+
* @param array $expectedAttributes
4651
* @dataProvider prepareAttributesWithDefaultValueForSaveDataProvider
4752
*/
4853
public function testPrepareAttributesWithDefaultValueForSave($rowData, $withDefaultValue, $expectedAttributes)
@@ -52,9 +57,15 @@ public function testPrepareAttributesWithDefaultValueForSave($rowData, $withDefa
5257
$this->assertArrayHasKey($key, $actualAttributes);
5358
$this->assertEquals($value, $actualAttributes[$key]);
5459
}
60+
61+
if (!empty($rowData['_store'])) {
62+
$this->assertEquals($expectedAttributes, $actualAttributes, '', 0.0, 10, true);
63+
}
5564
}
5665

5766
/**
67+
* Data provider for testPrepareAttributesWithDefaultValueForSave.
68+
*
5869
* @return array
5970
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
6071
*/
@@ -78,6 +89,17 @@ public function prepareAttributesWithDefaultValueForSaveDataProvider()
7889
false,
7990
['price' => 65, 'visibility' => 1, 'tax_class_id' => ''],
8091
],
92+
'Updating existing product with attributes that do not have default values with store in dataRow' => [
93+
[
94+
'sku' => 'simple_product_3',
95+
'price' => 75,
96+
'_attribute_set' => 'Default',
97+
'product_type' => 'simple',
98+
'_store' => 1
99+
],
100+
true,
101+
['price' => 75],
102+
],
81103
'Adding new product with attributes that do not have default values' => [
82104
[
83105
'sku' => 'simple_product_3',

0 commit comments

Comments
 (0)