Skip to content

Commit a17a901

Browse files
committed
Merge remote-tracking branch 'github-magento/MAGETWO-91594' into EPAM-PR-8
2 parents cadad31 + 1f8bf28 commit a17a901

File tree

1 file changed

+86
-7
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import/Product

1 file changed

+86
-7
lines changed

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

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
333333
*/
334334
private $optionTypeTitles;
335335

336+
/**
337+
* @var array
338+
*/
339+
private $lastOptionTitle;
340+
336341
/**
337342
* @param \Magento\ImportExport\Model\ResourceModel\Import\Data $importData
338343
* @param ResourceConnection $resource
@@ -1117,6 +1122,8 @@ protected function _getMultiRowFormat($rowData)
11171122
}
11181123

11191124
/**
1125+
* Process option row.
1126+
*
11201127
* @param string $name
11211128
* @param array $optionRow
11221129
* @return array
@@ -1198,6 +1205,7 @@ private function addFileOptions($result, $optionRow)
11981205

11991206
/**
12001207
* Import data rows.
1208+
*
12011209
* Additional store view data (option titles) will be sought in store view specified import file rows
12021210
*
12031211
* @return boolean
@@ -1206,7 +1214,6 @@ private function addFileOptions($result, $optionRow)
12061214
protected function _importData()
12071215
{
12081216
$this->_initProductsSku();
1209-
12101217
$nextOptionId = $this->_resourceHelper->getNextAutoincrement($this->_tables['catalog_product_option']);
12111218
$nextValueId = $this->_resourceHelper->getNextAutoincrement(
12121219
$this->_tables['catalog_product_option_type_value']
@@ -1225,7 +1232,6 @@ protected function _importData()
12251232
$parentCount = [];
12261233
$childCount = [];
12271234
$optionsToRemove = [];
1228-
12291235
foreach ($bunch as $rowNumber => $rowData) {
12301236
if (isset($optionId, $valueId) && empty($rowData[PRODUCT::COL_STORE_VIEW_CODE])) {
12311237
$nextOptionId = $optionId;
@@ -1273,17 +1279,26 @@ protected function _importData()
12731279
$parentCount,
12741280
$childCount
12751281
);
1282+
12761283
$this->_collectOptionTitle($combinedData, $prevOptionId, $titles);
1284+
$this->checkOptionTitles(
1285+
$options,
1286+
$titles,
1287+
$combinedData,
1288+
$prevOptionId,
1289+
$optionId,
1290+
$products,
1291+
$prices
1292+
);
12771293
}
12781294
}
1279-
12801295
$this->removeExistingOptions($products, $optionsToRemove);
1281-
12821296
$types = [
12831297
'values' => $typeValues,
12841298
'prices' => $typePrices,
12851299
'titles' => $typeTitles,
12861300
];
1301+
$this->setLastOptionTitle($titles);
12871302
//Save prepared custom options data.
12881303
$this->savePreparedCustomOptions(
12891304
$products,
@@ -1293,11 +1308,69 @@ protected function _importData()
12931308
$types
12941309
);
12951310
}
1296-
12971311
return true;
12981312
}
12991313

13001314
/**
1315+
* Check options titles.
1316+
*
1317+
* If products were split up between bunches,
1318+
* this function will add needed option for option titles
1319+
*
1320+
* @param array $options
1321+
* @param array $titles
1322+
* @param array $combinedData
1323+
* @param int $prevOptionId
1324+
* @param int $optionId
1325+
* @param array $products
1326+
* @param array $prices
1327+
* @return void
1328+
*/
1329+
private function checkOptionTitles(
1330+
array &$options,
1331+
array &$titles,
1332+
array $combinedData,
1333+
int &$prevOptionId,
1334+
int &$optionId,
1335+
array $products,
1336+
array $prices
1337+
) : void {
1338+
$titlesCount = count($titles);
1339+
if ($titlesCount > 0 && count($options) !== $titlesCount) {
1340+
$combinedData[Product::COL_STORE_VIEW_CODE] = '';
1341+
$optionId--;
1342+
$option = $this->_collectOptionMainData(
1343+
$combinedData,
1344+
$prevOptionId,
1345+
$optionId,
1346+
$products,
1347+
$prices
1348+
);
1349+
if ($option) {
1350+
$options[] = $option;
1351+
}
1352+
}
1353+
}
1354+
1355+
/**
1356+
* Setting last Custom Option Title
1357+
* to use it later in _collectOptionTitle
1358+
* to set correct title for default store view
1359+
*
1360+
* @param array $titles
1361+
*/
1362+
private function setLastOptionTitle(array &$titles) : void
1363+
{
1364+
if (count($titles) > 0) {
1365+
end($titles);
1366+
$key = key($titles);
1367+
$this->lastOptionTitle[$key] = $titles[$key];
1368+
}
1369+
}
1370+
1371+
/**
1372+
* Remove existing options.
1373+
*
13011374
* Remove all existing options if import behaviour is APPEND
13021375
* in other case remove options for products with empty "custom_options" row only.
13031376
*
@@ -1447,8 +1520,12 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
14471520
$defaultStoreId = Store::DEFAULT_STORE_ID;
14481521
if (!empty($rowData[self::COLUMN_TITLE])) {
14491522
if (!isset($titles[$prevOptionId][$defaultStoreId])) {
1450-
// ensure default title is set
1451-
$titles[$prevOptionId][$defaultStoreId] = $rowData[self::COLUMN_TITLE];
1523+
if (isset($this->lastOptionTitle[$prevOptionId])) {
1524+
$titles[$prevOptionId] = $this->lastOptionTitle[$prevOptionId];
1525+
unset($this->lastOptionTitle);
1526+
} else {
1527+
$titles[$prevOptionId][$defaultStoreId] = $rowData[self::COLUMN_TITLE];
1528+
}
14521529
}
14531530
$titles[$prevOptionId][$this->_rowStoreId] = $rowData[self::COLUMN_TITLE];
14541531
}
@@ -1547,6 +1624,8 @@ private function getExistingOptionTypeId($optionId, $storeId, $optionTypeTitle)
15471624
}
15481625

15491626
/**
1627+
* Rarse required data.
1628+
*
15501629
* Parse required data from current row and store to class internal variables some data
15511630
* for underlying dependent rows
15521631
*

0 commit comments

Comments
 (0)