@@ -333,6 +333,11 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
333
333
*/
334
334
private $ optionTypeTitles ;
335
335
336
+ /**
337
+ * @var array
338
+ */
339
+ private $ lastOptionTitle ;
340
+
336
341
/**
337
342
* @param \Magento\ImportExport\Model\ResourceModel\Import\Data $importData
338
343
* @param ResourceConnection $resource
@@ -1117,6 +1122,8 @@ protected function _getMultiRowFormat($rowData)
1117
1122
}
1118
1123
1119
1124
/**
1125
+ * Process option row.
1126
+ *
1120
1127
* @param string $name
1121
1128
* @param array $optionRow
1122
1129
* @return array
@@ -1198,6 +1205,7 @@ private function addFileOptions($result, $optionRow)
1198
1205
1199
1206
/**
1200
1207
* Import data rows.
1208
+ *
1201
1209
* Additional store view data (option titles) will be sought in store view specified import file rows
1202
1210
*
1203
1211
* @return boolean
@@ -1206,7 +1214,6 @@ private function addFileOptions($result, $optionRow)
1206
1214
protected function _importData ()
1207
1215
{
1208
1216
$ this ->_initProductsSku ();
1209
-
1210
1217
$ nextOptionId = $ this ->_resourceHelper ->getNextAutoincrement ($ this ->_tables ['catalog_product_option ' ]);
1211
1218
$ nextValueId = $ this ->_resourceHelper ->getNextAutoincrement (
1212
1219
$ this ->_tables ['catalog_product_option_type_value ' ]
@@ -1225,7 +1232,6 @@ protected function _importData()
1225
1232
$ parentCount = [];
1226
1233
$ childCount = [];
1227
1234
$ optionsToRemove = [];
1228
-
1229
1235
foreach ($ bunch as $ rowNumber => $ rowData ) {
1230
1236
if (isset ($ optionId , $ valueId ) && empty ($ rowData [PRODUCT ::COL_STORE_VIEW_CODE ])) {
1231
1237
$ nextOptionId = $ optionId ;
@@ -1273,17 +1279,26 @@ protected function _importData()
1273
1279
$ parentCount ,
1274
1280
$ childCount
1275
1281
);
1282
+
1276
1283
$ this ->_collectOptionTitle ($ combinedData , $ prevOptionId , $ titles );
1284
+ $ this ->checkOptionTitles (
1285
+ $ options ,
1286
+ $ titles ,
1287
+ $ combinedData ,
1288
+ $ prevOptionId ,
1289
+ $ optionId ,
1290
+ $ products ,
1291
+ $ prices
1292
+ );
1277
1293
}
1278
1294
}
1279
-
1280
1295
$ this ->removeExistingOptions ($ products , $ optionsToRemove );
1281
-
1282
1296
$ types = [
1283
1297
'values ' => $ typeValues ,
1284
1298
'prices ' => $ typePrices ,
1285
1299
'titles ' => $ typeTitles ,
1286
1300
];
1301
+ $ this ->setLastOptionTitle ($ titles );
1287
1302
//Save prepared custom options data.
1288
1303
$ this ->savePreparedCustomOptions (
1289
1304
$ products ,
@@ -1293,11 +1308,69 @@ protected function _importData()
1293
1308
$ types
1294
1309
);
1295
1310
}
1296
-
1297
1311
return true ;
1298
1312
}
1299
1313
1300
1314
/**
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
+ *
1301
1374
* Remove all existing options if import behaviour is APPEND
1302
1375
* in other case remove options for products with empty "custom_options" row only.
1303
1376
*
@@ -1447,8 +1520,12 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
1447
1520
$ defaultStoreId = Store::DEFAULT_STORE_ID ;
1448
1521
if (!empty ($ rowData [self ::COLUMN_TITLE ])) {
1449
1522
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
+ }
1452
1529
}
1453
1530
$ titles [$ prevOptionId ][$ this ->_rowStoreId ] = $ rowData [self ::COLUMN_TITLE ];
1454
1531
}
@@ -1547,6 +1624,8 @@ private function getExistingOptionTypeId($optionId, $storeId, $optionTypeTitle)
1547
1624
}
1548
1625
1549
1626
/**
1627
+ * Rarse required data.
1628
+ *
1550
1629
* Parse required data from current row and store to class internal variables some data
1551
1630
* for underlying dependent rows
1552
1631
*
0 commit comments