Skip to content

Commit fd5966d

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-91283' into 2.2-develop-pr47
2 parents 2165937 + d5a7fd2 commit fd5966d

File tree

1 file changed

+83
-5
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import/Product

1 file changed

+83
-5
lines changed

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

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
336336
*/
337337
private $optionTypeTitles;
338338

339+
/**
340+
* @var array
341+
*/
342+
private $lastOptionTitle;
343+
339344
/**
340345
* @param \Magento\ImportExport\Model\ResourceModel\Import\Data $importData
341346
* @param ResourceConnection $resource
@@ -1119,6 +1124,8 @@ protected function _getMultiRowFormat($rowData)
11191124
}
11201125

11211126
/**
1127+
* Process option row.
1128+
*
11221129
* @param string $name
11231130
* @param array $optionRow
11241131
* @return array
@@ -1185,6 +1192,7 @@ private function addFileOptions($result, $optionRow)
11851192

11861193
/**
11871194
* Import data rows.
1195+
*
11881196
* Additional store view data (option titles) will be sought in store view specified import file rows
11891197
*
11901198
* @return boolean
@@ -1212,7 +1220,6 @@ protected function _importData()
12121220
$parentCount = [];
12131221
$childCount = [];
12141222
$optionsToRemove = [];
1215-
12161223
foreach ($bunch as $rowNumber => $rowData) {
12171224
if (isset($optionId, $valueId) && empty($rowData[Product::COL_STORE_VIEW_CODE])) {
12181225
$nextOptionId = $optionId;
@@ -1257,9 +1264,17 @@ protected function _importData()
12571264
$childCount
12581265
);
12591266
$this->_collectOptionTitle($combinedData, $prevOptionId, $titles);
1267+
$this->checkOptionTitles(
1268+
$options,
1269+
$titles,
1270+
$combinedData,
1271+
$prevOptionId,
1272+
$optionId,
1273+
$products,
1274+
$prices
1275+
);
12601276
}
12611277
}
1262-
12631278
// Remove all existing options if import behaviour is APPEND
12641279
// in other case remove options for products with empty "custom_options" row only
12651280
if ($this->getBehavior() != \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND) {
@@ -1268,21 +1283,80 @@ protected function _importData()
12681283
// Remove options for products with empty "custom_options" row
12691284
$this->_deleteEntities($optionsToRemove);
12701285
}
1271-
12721286
// Save prepared custom options data
12731287
if ($this->_isReadyForSaving($options, $titles, $typeValues)) {
12741288
$types = [
12751289
'values' => $typeValues,
12761290
'prices' => $typePrices,
12771291
'titles' => $typeTitles
12781292
];
1293+
$this->setLastOptionTitle($titles);
12791294
$this->savePreparedCustomOptions($products, $options, $titles, $prices, $types);
12801295
}
12811296
}
12821297

12831298
return true;
12841299
}
12851300

1301+
/**
1302+
* Check options titles.
1303+
*
1304+
* If products were split up between bunches,
1305+
* this function will add needed option for option titles.
1306+
*
1307+
* @param array $options
1308+
* @param array $titles
1309+
* @param array $combinedData
1310+
* @param int $prevOptionId
1311+
* @param int $optionId
1312+
* @param array $products
1313+
* @param array $prices
1314+
* @return void
1315+
*/
1316+
private function checkOptionTitles(
1317+
array &$options,
1318+
array &$titles,
1319+
array $combinedData,
1320+
int &$prevOptionId,
1321+
int &$optionId,
1322+
array $products,
1323+
array $prices
1324+
) {
1325+
$titlesCount = count($titles);
1326+
if ($titlesCount > 0 && count($options) !== $titlesCount) {
1327+
$combinedData[Product::COL_STORE_VIEW_CODE] = '';
1328+
$optionId--;
1329+
$option = $this->_collectOptionMainData(
1330+
$combinedData,
1331+
$prevOptionId,
1332+
$optionId,
1333+
$products,
1334+
$prices
1335+
);
1336+
if ($option) {
1337+
$options[] = $option;
1338+
}
1339+
}
1340+
}
1341+
1342+
/**
1343+
* Setting last Custom Option Title
1344+
* to use it later in _collectOptionTitle
1345+
* to set correct title for default store view.
1346+
*
1347+
* @param array $titles
1348+
* @return void
1349+
*/
1350+
private function setLastOptionTitle(array &$titles)
1351+
{
1352+
if (count($titles) > 0) {
1353+
end($titles);
1354+
$key = key($titles);
1355+
$this->lastOptionTitle[$key] = $titles[$key];
1356+
}
1357+
}
1358+
1359+
12861360
/**
12871361
* Load data of existed products
12881362
*
@@ -1413,8 +1487,12 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
14131487
$defaultStoreId = Store::DEFAULT_STORE_ID;
14141488
if (!empty($rowData[self::COLUMN_TITLE])) {
14151489
if (!isset($titles[$prevOptionId][$defaultStoreId])) {
1416-
// ensure default title is set
1417-
$titles[$prevOptionId][$defaultStoreId] = $rowData[self::COLUMN_TITLE];
1490+
if (isset($this->lastOptionTitle[$prevOptionId])) {
1491+
$titles[$prevOptionId] = $this->lastOptionTitle[$prevOptionId];
1492+
unset($this->lastOptionTitle);
1493+
} else {
1494+
$titles[$prevOptionId][$defaultStoreId] = $rowData[self::COLUMN_TITLE];
1495+
}
14181496
}
14191497
$titles[$prevOptionId][$this->_rowStoreId] = $rowData[self::COLUMN_TITLE];
14201498
}

0 commit comments

Comments
 (0)