Skip to content

Commit 2aec878

Browse files
committed
Merge remote-tracking branch 'origin/MC-18472' into 2.3-develop-pr29
2 parents 72f72dd + fe84af1 commit 2aec878

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

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

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ protected function _findNewOptionsWithTheSameTitles()
669669
*
670670
* @param array $sourceProductData
671671
* @return array
672+
* phpcs:disable Generic.Metrics.NestingLevel
672673
*/
673674
protected function _getNewOptionsWithTheSameTitlesErrorRows(array $sourceProductData)
674675
{
@@ -697,6 +698,7 @@ protected function _getNewOptionsWithTheSameTitlesErrorRows(array $sourceProduct
697698
* Find options with the same titles in DB
698699
*
699700
* @return array
701+
* phpcs:disable Generic.Metrics.NestingLevel
700702
*/
701703
protected function _findOldOptionsWithTheSameTitles()
702704
{
@@ -730,6 +732,7 @@ protected function _findOldOptionsWithTheSameTitles()
730732
* Find source file options, which have analogs in DB with the same name, but with different type
731733
*
732734
* @return array
735+
* phpcs:disable Generic.Metrics.NestingLevel
733736
*/
734737
protected function _findNewOldOptionsTypeMismatch()
735738
{
@@ -1067,7 +1070,7 @@ protected function _isSecondaryOptionRow(array $rowData)
10671070
*
10681071
* @param array &$options
10691072
* @param array &$titles
1070-
* @param array $typeValues
1073+
* @param array $typeValues
10711074
* @return bool
10721075
*/
10731076
protected function _isReadyForSaving(array &$options, array &$titles, array $typeValues)
@@ -1414,9 +1417,9 @@ protected function _initProductsSku()
14141417
/**
14151418
* Collect custom option main data to import
14161419
*
1417-
* @param array $rowData
1418-
* @param int &$prevOptionId
1419-
* @param int &$nextOptionId
1420+
* @param array $rowData
1421+
* @param int &$prevOptionId
1422+
* @param int &$nextOptionId
14201423
* @param array &$products
14211424
* @param array &$prices
14221425
* @return array|null
@@ -1454,9 +1457,9 @@ protected function _collectOptionMainData(
14541457
/**
14551458
* Collect custom option type data to import
14561459
*
1457-
* @param array $rowData
1458-
* @param int &$prevOptionId
1459-
* @param int &$nextValueId
1460+
* @param array $rowData
1461+
* @param int &$prevOptionId
1462+
* @param int &$nextValueId
14601463
* @param array &$typeValues
14611464
* @param array &$typePrices
14621465
* @param array &$typeTitles
@@ -1504,6 +1507,9 @@ protected function _collectOptionTypeData(
15041507
$specificTypeData = $this->_getSpecificTypeData($rowData, 0, false);
15051508
//For others stores
15061509
if ($specificTypeData) {
1510+
if (isset($specificTypeData['price'])) {
1511+
$typePrices[$nextValueId][$this->_rowStoreId] = $specificTypeData['price'];
1512+
}
15071513
$typeTitles[$nextValueId++][$this->_rowStoreId] = $specificTypeData['title'];
15081514
}
15091515
}
@@ -1512,8 +1518,8 @@ protected function _collectOptionTypeData(
15121518
/**
15131519
* Collect custom option title to import
15141520
*
1515-
* @param array $rowData
1516-
* @param int $prevOptionId
1521+
* @param array $rowData
1522+
* @param int $prevOptionId
15171523
* @param array &$titles
15181524
* @return void
15191525
*/
@@ -1788,29 +1794,30 @@ protected function _getPriceData(array $rowData, $optionId, $type)
17881794
*/
17891795
protected function _getSpecificTypeData(array $rowData, $optionTypeId, $defaultStore = true)
17901796
{
1797+
$data = [];
1798+
$priceData = [];
1799+
$customOptionRowPrice = $rowData[self::COLUMN_ROW_PRICE];
1800+
if (!empty($customOptionRowPrice) || $customOptionRowPrice === '0') {
1801+
$priceData['price'] = (double)rtrim($rowData[self::COLUMN_ROW_PRICE], '%');
1802+
$priceData['price_type'] = ('%' == substr($rowData[self::COLUMN_ROW_PRICE], -1)) ? 'percent' : 'fixed';
1803+
}
17911804
if (!empty($rowData[self::COLUMN_ROW_TITLE]) && $defaultStore && empty($rowData[self::COLUMN_STORE])) {
17921805
$valueData = [
17931806
'option_type_id' => $optionTypeId,
17941807
'sort_order' => empty($rowData[self::COLUMN_ROW_SORT]) ? 0 : abs($rowData[self::COLUMN_ROW_SORT]),
17951808
'sku' => !empty($rowData[self::COLUMN_ROW_SKU]) ? $rowData[self::COLUMN_ROW_SKU] : '',
17961809
];
1797-
1798-
$priceData = false;
1799-
$customOptionRowPrice = $rowData[self::COLUMN_ROW_PRICE];
1800-
if (!empty($customOptionRowPrice) || $customOptionRowPrice === '0') {
1801-
$priceData = [
1802-
'price' => (double)rtrim($rowData[self::COLUMN_ROW_PRICE], '%'),
1803-
'price_type' => 'fixed',
1804-
];
1805-
if ('%' == substr($rowData[self::COLUMN_ROW_PRICE], -1)) {
1806-
$priceData['price_type'] = 'percent';
1807-
}
1808-
}
1809-
return ['value' => $valueData, 'title' => $rowData[self::COLUMN_ROW_TITLE], 'price' => $priceData];
1810+
$data['value'] = $valueData;
1811+
$data['title'] = $rowData[self::COLUMN_ROW_TITLE];
1812+
$data['price'] = $priceData;
18101813
} elseif (!empty($rowData[self::COLUMN_ROW_TITLE]) && !$defaultStore && !empty($rowData[self::COLUMN_STORE])) {
1811-
return ['title' => $rowData[self::COLUMN_ROW_TITLE]];
1814+
if ($priceData) {
1815+
$data['price'] = $priceData;
1816+
}
1817+
$data['title'] = $rowData[self::COLUMN_ROW_TITLE];
18121818
}
1813-
return false;
1819+
1820+
return $data ?: false;
18141821
}
18151822

18161823
/**
@@ -1868,7 +1875,9 @@ protected function _saveTitles(array $titles)
18681875
{
18691876
$titleRows = [];
18701877
foreach ($titles as $optionId => $storeInfo) {
1871-
foreach ($storeInfo as $storeId => $title) {
1878+
//for use default
1879+
$uniqStoreInfo = array_unique($storeInfo);
1880+
foreach ($uniqStoreInfo as $storeId => $title) {
18721881
$titleRows[] = ['option_id' => $optionId, 'store_id' => $storeId, 'title' => $title];
18731882
}
18741883
}
@@ -1963,7 +1972,9 @@ protected function _saveSpecificTypeTitles(array $typeTitles)
19631972
{
19641973
$optionTypeTitleRows = [];
19651974
foreach ($typeTitles as $optionTypeId => $storesData) {
1966-
foreach ($storesData as $storeId => $title) {
1975+
//for use default
1976+
$uniqStoresData = array_unique($storesData);
1977+
foreach ($uniqStoresData as $storeId => $title) {
19671978
$optionTypeTitleRows[] = [
19681979
'option_type_id' => $optionTypeId,
19691980
'store_id' => $storeId,
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
22
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,,,
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,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,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)