@@ -336,6 +336,11 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
336
336
*/
337
337
private $ optionTypeTitles ;
338
338
339
+ /**
340
+ * @var array
341
+ */
342
+ private $ lastOptionTitle ;
343
+
339
344
/**
340
345
* @param \Magento\ImportExport\Model\ResourceModel\Import\Data $importData
341
346
* @param ResourceConnection $resource
@@ -1119,6 +1124,8 @@ protected function _getMultiRowFormat($rowData)
1119
1124
}
1120
1125
1121
1126
/**
1127
+ * Process option row.
1128
+ *
1122
1129
* @param string $name
1123
1130
* @param array $optionRow
1124
1131
* @return array
@@ -1185,6 +1192,7 @@ private function addFileOptions($result, $optionRow)
1185
1192
1186
1193
/**
1187
1194
* Import data rows.
1195
+ *
1188
1196
* Additional store view data (option titles) will be sought in store view specified import file rows
1189
1197
*
1190
1198
* @return boolean
@@ -1212,7 +1220,6 @@ protected function _importData()
1212
1220
$ parentCount = [];
1213
1221
$ childCount = [];
1214
1222
$ optionsToRemove = [];
1215
-
1216
1223
foreach ($ bunch as $ rowNumber => $ rowData ) {
1217
1224
if (isset ($ optionId , $ valueId ) && empty ($ rowData [Product::COL_STORE_VIEW_CODE ])) {
1218
1225
$ nextOptionId = $ optionId ;
@@ -1257,9 +1264,17 @@ protected function _importData()
1257
1264
$ childCount
1258
1265
);
1259
1266
$ this ->_collectOptionTitle ($ combinedData , $ prevOptionId , $ titles );
1267
+ $ this ->checkOptionTitles (
1268
+ $ options ,
1269
+ $ titles ,
1270
+ $ combinedData ,
1271
+ $ prevOptionId ,
1272
+ $ optionId ,
1273
+ $ products ,
1274
+ $ prices
1275
+ );
1260
1276
}
1261
1277
}
1262
-
1263
1278
// Remove all existing options if import behaviour is APPEND
1264
1279
// in other case remove options for products with empty "custom_options" row only
1265
1280
if ($ this ->getBehavior () != \Magento \ImportExport \Model \Import::BEHAVIOR_APPEND ) {
@@ -1268,21 +1283,80 @@ protected function _importData()
1268
1283
// Remove options for products with empty "custom_options" row
1269
1284
$ this ->_deleteEntities ($ optionsToRemove );
1270
1285
}
1271
-
1272
1286
// Save prepared custom options data
1273
1287
if ($ this ->_isReadyForSaving ($ options , $ titles , $ typeValues )) {
1274
1288
$ types = [
1275
1289
'values ' => $ typeValues ,
1276
1290
'prices ' => $ typePrices ,
1277
1291
'titles ' => $ typeTitles
1278
1292
];
1293
+ $ this ->setLastOptionTitle ($ titles );
1279
1294
$ this ->savePreparedCustomOptions ($ products , $ options , $ titles , $ prices , $ types );
1280
1295
}
1281
1296
}
1282
1297
1283
1298
return true ;
1284
1299
}
1285
1300
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
+
1286
1360
/**
1287
1361
* Load data of existed products
1288
1362
*
@@ -1413,8 +1487,12 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
1413
1487
$ defaultStoreId = Store::DEFAULT_STORE_ID ;
1414
1488
if (!empty ($ rowData [self ::COLUMN_TITLE ])) {
1415
1489
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
+ }
1418
1496
}
1419
1497
$ titles [$ prevOptionId ][$ this ->_rowStoreId ] = $ rowData [self ::COLUMN_TITLE ];
1420
1498
}
0 commit comments