Skip to content

Commit 17a9daa

Browse files
committed
Merge remote-tracking branch 'origin/MC-18710' into 2.3-develop-pr30
2 parents 484cc98 + a7792ed commit 17a9daa

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

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

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,12 @@ protected function _getNewOptionsWithTheSameTitlesErrorRows(array $sourceProduct
684684
ksort($outerTitles);
685685
ksort($innerTitles);
686686
if ($outerTitles === $innerTitles) {
687-
$errorRows = array_merge($errorRows, $innerData['rows'], $outerData['rows']);
687+
foreach ($innerData['rows'] as $innerDataRow) {
688+
$errorRows[] = $innerDataRow;
689+
}
690+
foreach ($outerData['rows'] as $outerDataRow) {
691+
$errorRows[] = $outerDataRow;
692+
}
688693
}
689694
}
690695
}
@@ -719,7 +724,9 @@ protected function _findOldOptionsWithTheSameTitles()
719724
}
720725
}
721726
if ($optionsCount > 1) {
722-
$errorRows = array_merge($errorRows, $outerData['rows']);
727+
foreach ($outerData['rows'] as $dataRow) {
728+
$errorRows[] = $dataRow;
729+
}
723730
}
724731
}
725732
}
@@ -747,7 +754,9 @@ protected function _findNewOldOptionsTypeMismatch()
747754
ksort($outerTitles);
748755
ksort($innerTitles);
749756
if ($outerTitles === $innerTitles && $outerData['type'] != $innerData['type']) {
750-
$errorRows = array_merge($errorRows, $outerData['rows']);
757+
foreach ($outerData['rows'] as $dataRow) {
758+
$errorRows[] = $dataRow;
759+
}
751760
}
752761
}
753762
}
@@ -959,8 +968,10 @@ public function validateRow(array $rowData, $rowNumber)
959968

960969
$multiRowData = $this->_getMultiRowFormat($rowData);
961970

962-
foreach ($multiRowData as $optionData) {
963-
$combinedData = array_merge($rowData, $optionData);
971+
foreach ($multiRowData as $combinedData) {
972+
foreach ($rowData as $key => $field) {
973+
$combinedData[$key] = $field;
974+
}
964975

965976
if ($this->_isRowWithCustomOption($combinedData)) {
966977
if ($this->_isMainOptionRow($combinedData)) {
@@ -1109,15 +1120,15 @@ protected function _getMultiRowFormat($rowData)
11091120
foreach ($rowData['custom_options'] as $name => $customOption) {
11101121
$i++;
11111122
foreach ($customOption as $rowOrder => $optionRow) {
1112-
$row = array_merge(
1113-
[
1114-
self::COLUMN_STORE => '',
1115-
self::COLUMN_TITLE => $name,
1116-
self::COLUMN_SORT_ORDER => $i,
1117-
self::COLUMN_ROW_SORT => $rowOrder
1118-
],
1119-
$this->processOptionRow($name, $optionRow)
1120-
);
1123+
$row = [
1124+
self::COLUMN_STORE => '',
1125+
self::COLUMN_TITLE => $name,
1126+
self::COLUMN_SORT_ORDER => $i,
1127+
self::COLUMN_ROW_SORT => $rowOrder
1128+
];
1129+
foreach ($this->processOptionRow($name, $optionRow) as $key => $value) {
1130+
$row[$key] = $value;
1131+
}
11211132
$name = '';
11221133
$multiRow[] = $row;
11231134
}
@@ -1215,6 +1226,8 @@ private function addFileOptions($result, $optionRow)
12151226
*
12161227
* @return boolean
12171228
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
1229+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1230+
* @SuppressWarnings(PHPMD.NPathComplexity)
12181231
*/
12191232
protected function _importData()
12201233
{
@@ -1256,9 +1269,11 @@ protected function _importData()
12561269
$optionsToRemove[] = $this->_rowProductId;
12571270
}
12581271
}
1259-
foreach ($multiRowData as $optionData) {
1260-
$combinedData = array_merge($rowData, $optionData);
12611272

1273+
foreach ($multiRowData as $combinedData) {
1274+
foreach ($rowData as $key => $field) {
1275+
$combinedData[$key] = $field;
1276+
}
12621277
if (!$this->isRowAllowedToImport($combinedData, $rowNumber)
12631278
|| !$this->_parseRequiredData($combinedData)
12641279
) {
@@ -1441,7 +1456,9 @@ protected function _collectOptionMainData(
14411456
if (!$this->_isRowHasSpecificType($this->_rowType)
14421457
&& ($priceData = $this->_getPriceData($rowData, $nextOptionId, $this->_rowType))
14431458
) {
1444-
$prices[$nextOptionId] = $priceData;
1459+
if ($this->_isPriceGlobal) {
1460+
$prices[$nextOptionId][Store::DEFAULT_STORE_ID] = $priceData;
1461+
}
14451462
}
14461463

14471464
if (!isset($products[$this->_rowProductId])) {
@@ -1547,6 +1564,7 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
15471564
* @param array &$prices
15481565
* @param array &$typeValues
15491566
* @return $this
1567+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
15501568
*/
15511569
protected function _compareOptionsWithExisting(array &$options, array &$titles, array &$prices, array &$typeValues)
15521570
{
@@ -1557,7 +1575,9 @@ protected function _compareOptionsWithExisting(array &$options, array &$titles,
15571575
$titles[$optionId] = $titles[$newOptionId];
15581576
unset($titles[$newOptionId]);
15591577
if (isset($prices[$newOptionId])) {
1560-
$prices[$newOptionId]['option_id'] = $optionId;
1578+
foreach ($prices[$newOptionId] as $storeId => $priceStoreData) {
1579+
$prices[$newOptionId][$storeId]['option_id'] = $optionId;
1580+
}
15611581
}
15621582
if (isset($typeValues[$newOptionId])) {
15631583
$typeValues[$optionId] = $typeValues[$newOptionId];
@@ -1590,8 +1610,10 @@ private function restoreOriginalOptionTypeIds(array &$typeValues, array &$typePr
15901610
$optionType['option_type_id'] = $existingTypeId;
15911611
$typeTitles[$existingTypeId] = $typeTitles[$optionTypeId];
15921612
unset($typeTitles[$optionTypeId]);
1593-
$typePrices[$existingTypeId] = $typePrices[$optionTypeId];
1594-
unset($typePrices[$optionTypeId]);
1613+
if (isset($typePrices[$optionTypeId])) {
1614+
$typePrices[$existingTypeId] = $typePrices[$optionTypeId];
1615+
unset($typePrices[$optionTypeId]);
1616+
}
15951617
// If option type titles match at least in one store, consider current option type as existing
15961618
break;
15971619
}
@@ -1651,7 +1673,7 @@ protected function _parseRequiredData(array $rowData)
16511673
if (!isset($this->_storeCodeToId[$rowData[self::COLUMN_STORE]])) {
16521674
return false;
16531675
}
1654-
$this->_rowStoreId = $this->_storeCodeToId[$rowData[self::COLUMN_STORE]];
1676+
$this->_rowStoreId = (int)$this->_storeCodeToId[$rowData[self::COLUMN_STORE]];
16551677
} else {
16561678
$this->_rowStoreId = Store::DEFAULT_STORE_ID;
16571679
}
@@ -1767,7 +1789,7 @@ protected function _getPriceData(array $rowData, $optionId, $type)
17671789
) {
17681790
$priceData = [
17691791
'option_id' => $optionId,
1770-
'store_id' => Store::DEFAULT_STORE_ID,
1792+
'store_id' => $this->_rowStoreId,
17711793
'price_type' => 'fixed',
17721794
];
17731795

@@ -1901,11 +1923,19 @@ protected function _saveTitles(array $titles)
19011923
protected function _savePrices(array $prices)
19021924
{
19031925
if ($prices) {
1904-
$this->_connection->insertOnDuplicate(
1905-
$this->_tables['catalog_product_option_price'],
1906-
$prices,
1907-
['price', 'price_type']
1908-
);
1926+
$optionPriceRows = [];
1927+
foreach ($prices as $storesData) {
1928+
foreach ($storesData as $row) {
1929+
$optionPriceRows[] = $row;
1930+
}
1931+
}
1932+
if ($optionPriceRows) {
1933+
$this->_connection->insertOnDuplicate(
1934+
$this->_tables['catalog_product_option_price'],
1935+
$optionPriceRows,
1936+
['price', 'price_type']
1937+
);
1938+
}
19091939
}
19101940

19111941
return $this;

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/OptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class OptionTest extends \Magento\ImportExport\Test\Unit\Model\Import\AbstractIm
7979
* @var array
8080
*/
8181
protected $_expectedPrices = [
82-
2 => ['option_id' => 2, 'store_id' => 0, 'price_type' => 'fixed', 'price' => 0],
83-
3 => ['option_id' => 3, 'store_id' => 0, 'price_type' => 'fixed', 'price' => 2]
82+
0 => ['option_id' => 2, 'store_id' => 0, 'price_type' => 'fixed', 'price' => 0],
83+
1 => ['option_id' => 3, 'store_id' => 0, 'price_type' => 'fixed', 'price' => 2]
8484
];
8585

8686
/**
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
sku,website_code,store_view_code,attribute_set_code,product_type,name,description,short_description,weight,product_online,visibility,product_websites,categories,price,special_price,special_price_from_date,special_price_to_date,tax_class_name,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,additional_images,additional_image_labels,configurable_variation_labels,configurable_variations,bundle_price_type,bundle_sku_type,bundle_weight_type,bundle_values,downloadble_samples,downloadble_links,associated_skus,related_skus,crosssell_skus,upsell_skus,custom_options,additional_attributes,manage_stock,is_in_stock,qty,out_of_stock_qty,is_qty_decimal,allow_backorders,min_cart_qty,max_cart_qty,notify_on_stock_below,qty_increments,enable_qty_increments,is_decimal_divided,new_from_date,new_to_date,gift_message_available,created_at,updated_at,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_price,msrp_display_actual_price_type,map_enabled
2-
simple,base,,Default,simple,New Product,,,9,1,"Catalog, Search",base,,10,,,,Taxable Goods,new-product,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Select,type=drop_down,required=1,price=3,option_title=Select Option 1,sku=3-1-select|name=Test Select,type=drop_down,required=1,price=3,option_title=Select Option 2,sku=3-2-select|name=Test Field Title,type=field,required=1,sku=1-text,price=0,price_type=fixed,max_characters=10|name=Test Date and Time Title,type=date_time,required=1,price=2,sku=2-date|name=Test Checkbox,type=checkbox,required=1,price=3,option_title=Checkbox Option 1,sku=4-1-select|name=Test Checkbox,type=checkbox,required=1,price=3,option_title=Checkbox Option 2,sku=4-2-select|name=Test Radio,type=radio,required=1,price=3,option_title=Radio Option 1,sku=5-1-radio|name=Test Radio,type=radio,required=1,price=3,option_title=Radio Option 2,sku=5-2-radio",,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,
2+
simple,base,,Default,simple,New Product,,,9,1,"Catalog, Search",base,,10,,,,Taxable Goods,new-product,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Select,type=drop_down,required=1,price=3,option_title=Select Option 1,sku=3-1-select|name=Test Select,type=drop_down,required=1,price=3,option_title=Select Option 2,sku=3-2-select|name=Test Field Title,type=field,required=1,sku=1-text,price=0,price_type=fixed,max_characters=10|name=Test Date and Time Title,type=date_time,required=1,sku=2-date|name=Test Checkbox,type=checkbox,required=1,price=3,option_title=Checkbox Option 1,sku=4-1-select|name=Test Checkbox,type=checkbox,required=1,price=3,option_title=Checkbox Option 2,sku=4-2-select|name=Test Radio,type=radio,required=1,price=3,option_title=Radio Option 1,sku=5-1-radio|name=Test Radio,type=radio,required=1,price=3,option_title=Radio Option 2,sku=5-2-radio",,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,
33
simple,,default,Default,simple,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Select_default,type=drop_down,option_title=Select Option 1_default|name=Test Select_default,type=drop_down,option_title=Select Option 2_default|name=Test Field Title_default,type=field|name=Test Date and Time Title_default,type=date_time|name=Test Checkbox_default,type=checkbox,option_title=Checkbox Option 1_default|name=Test Checkbox_default,type=checkbox,option_title=Checkbox Option 2_default|name=Test Radio_default,type=radio,option_title=Radio Option 1_default|name=Test Radio_default,type=radio,option_title=Radio Option 2_default",,,,,,,,,,,,,,,,,,,,,,,,,,,
4-
simple,,fixture_second_store,Default,simple,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Select_fixture_second_store,type=drop_down,price=1,option_title=Select Option 1_fixture_second_store|name=Test Select_fixture_second_store,type=drop_down,option_title=Select Option 2_fixture_second_store|name=Test Field Title_fixture_second_store,type=field|name=Test Date and Time Title_fixture_second_store,type=date_time|name=Test Checkbox_second_store,type=checkbox,option_title=Checkbox Option 1_second_store|name=Test Checkbox_second_store,type=checkbox,option_title=Checkbox Option 2_second_store|name=Test Radio_fixture_second_store,type=radio,option_title=Radio Option 1_fixture_second_store|name=Test Radio_fixture_second_store,type=radio,option_title=Radio Option 2_fixture_second_store",,,,,,,,,,,,,,,,,,,,,,,,,,,
4+
simple,,fixture_second_store,Default,simple,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Select_fixture_second_store,type=drop_down,price=1,option_title=Select Option 1_fixture_second_store|name=Test Select_fixture_second_store,type=drop_down,option_title=Select Option 2_fixture_second_store|name=Test Field Title_fixture_second_store,type=field|name=Test Date and Time Title_fixture_second_store,price=8,type=date_time|name=Test Checkbox_second_store,type=checkbox,option_title=Checkbox Option 1_second_store|name=Test Checkbox_second_store,type=checkbox,option_title=Checkbox Option 2_second_store|name=Test Radio_fixture_second_store,type=radio,option_title=Radio Option 1_fixture_second_store|name=Test Radio_fixture_second_store,type=radio,option_title=Radio Option 2_fixture_second_store",,,,,,,,,,,,,,,,,,,,,,,,,,,

0 commit comments

Comments
 (0)