Skip to content

Commit c53f861

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-92226' into EPAM-PR-34
2 parents fb30023 + 8f2e45e commit c53f861

File tree

1 file changed

+65
-23
lines changed
  • app/code/Magento/CatalogImportExport/Model/Export

1 file changed

+65
-23
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,11 +1294,23 @@ private function appendMultirowData(&$dataRow, $multiRawData)
12941294
}
12951295

12961296
if (!empty($multiRawData['customOptionsData'][$productLinkId][$storeId])) {
1297+
$shouldBeMerged = true;
12971298
$customOptionsRows = $multiRawData['customOptionsData'][$productLinkId][$storeId];
1298-
$multiRawData['customOptionsData'][$productLinkId][$storeId] = [];
1299-
$customOptions = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $customOptionsRows);
13001299

1301-
$dataRow = array_merge($dataRow, ['custom_options' => $customOptions]);
1300+
if ($storeId != Store::DEFAULT_STORE_ID
1301+
&& !empty($multiRawData['customOptionsData'][$productLinkId][Store::DEFAULT_STORE_ID])
1302+
) {
1303+
$defaultCustomOptions = $multiRawData['customOptionsData'][$productLinkId][Store::DEFAULT_STORE_ID];
1304+
if (!array_diff($defaultCustomOptions, $customOptionsRows)) {
1305+
$shouldBeMerged = false;
1306+
}
1307+
}
1308+
1309+
if ($shouldBeMerged) {
1310+
$multiRawData['customOptionsData'][$productLinkId][$storeId] = [];
1311+
$customOptions = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $customOptionsRows);
1312+
$dataRow = array_merge($dataRow, ['custom_options' => $customOptions]);
1313+
}
13021314
}
13031315

13041316
if (empty($dataRow)) {
@@ -1394,6 +1406,7 @@ protected function optionRowToCellString($option)
13941406
protected function getCustomOptionsData($productIds)
13951407
{
13961408
$customOptionsData = [];
1409+
$defaultOptionsData = [];
13971410

13981411
foreach (array_keys($this->_storeIdToCode) as $storeId) {
13991412
$options = $this->_optionColFactory->create();
@@ -1406,38 +1419,42 @@ protected function getCustomOptionsData($productIds)
14061419
->addValuesToResult($storeId);
14071420

14081421
foreach ($options as $option) {
1422+
$optionData = $option->toArray();
14091423
$row = [];
14101424
$productId = $option['product_id'];
14111425
$row['name'] = $option['title'];
14121426
$row['type'] = $option['type'];
1413-
if (Store::DEFAULT_STORE_ID === $storeId) {
1414-
$row['required'] = $option['is_require'];
1415-
$row['price'] = $option['price'];
1416-
$row['price_type'] = ($option['price_type'] === 'percent') ? 'percent' : 'fixed';
1417-
$row['sku'] = $option['sku'];
1418-
if ($option['max_characters']) {
1419-
$row['max_characters'] = $option['max_characters'];
1420-
}
1421-
1422-
foreach (['file_extension', 'image_size_x', 'image_size_y'] as $fileOptionKey) {
1423-
if (!isset($option[$fileOptionKey])) {
1424-
continue;
1425-
}
14261427

1427-
$row[$fileOptionKey] = $option[$fileOptionKey];
1428+
$row['required'] = $this->getOptionValue('is_require', $defaultOptionsData, $optionData);
1429+
$row['price'] = $this->getOptionValue('price', $defaultOptionsData, $optionData);
1430+
$row['sku'] = $this->getOptionValue('sku', $defaultOptionsData, $optionData);
1431+
if (array_key_exists('max_characters', $optionData)
1432+
|| array_key_exists('max_characters', $defaultOptionsData)
1433+
) {
1434+
$row['max_characters'] = $this->getOptionValue('max_characters', $defaultOptionsData, $optionData);
1435+
}
1436+
foreach (['file_extension', 'image_size_x', 'image_size_y'] as $fileOptionKey) {
1437+
if (isset($option[$fileOptionKey]) || isset($defaultOptionsData[$fileOptionKey])) {
1438+
$row[$fileOptionKey] = $this->getOptionValue($fileOptionKey, $defaultOptionsData, $optionData);
14281439
}
14291440
}
1441+
$percentType = $this->getOptionValue('price_type', $defaultOptionsData, $optionData);
1442+
$row['price_type'] = ($percentType === 'percent') ? 'percent' : 'fixed';
1443+
1444+
if (Store::DEFAULT_STORE_ID === $storeId) {
1445+
$optionId = $option['option_id'];
1446+
$defaultOptionsData[$optionId] = $option->toArray();
1447+
}
1448+
14301449
$values = $option->getValues();
14311450

14321451
if ($values) {
14331452
foreach ($values as $value) {
14341453
$row['option_title'] = $value['title'];
1435-
if (Store::DEFAULT_STORE_ID === $storeId) {
1436-
$row['option_title'] = $value['title'];
1437-
$row['price'] = $value['price'];
1438-
$row['price_type'] = ($value['price_type'] === 'percent') ? 'percent' : 'fixed';
1439-
$row['sku'] = $value['sku'];
1440-
}
1454+
$row['option_title'] = $value['title'];
1455+
$row['price'] = $value['price'];
1456+
$row['price_type'] = ($value['price_type'] === 'percent') ? 'percent' : 'fixed';
1457+
$row['sku'] = $value['sku'];
14411458
$customOptionsData[$productId][$storeId][] = $this->optionRowToCellString($row);
14421459
}
14431460
} else {
@@ -1451,6 +1468,31 @@ protected function getCustomOptionsData($productIds)
14511468
return $customOptionsData;
14521469
}
14531470

1471+
/**
1472+
* Get value for custom option according to store or default value
1473+
*
1474+
* @param string $optionName
1475+
* @param array $defaultOptionsData
1476+
* @param array $optionData
1477+
* @return mixed
1478+
*/
1479+
private function getOptionValue($optionName, $defaultOptionsData, $optionData)
1480+
{
1481+
$optionId = $optionData['option_id'];
1482+
1483+
if (array_key_exists($optionName, $optionData) && $optionData[$optionName] !== null) {
1484+
return $optionData[$optionName];
1485+
}
1486+
1487+
if (array_key_exists($optionId, $defaultOptionsData)
1488+
&& array_key_exists($optionName, $defaultOptionsData[$optionId])
1489+
) {
1490+
return $defaultOptionsData[$optionId][$optionName];
1491+
}
1492+
1493+
return null;
1494+
}
1495+
14541496
/**
14551497
* Clean up already loaded attribute collection.
14561498
*

0 commit comments

Comments
 (0)