@@ -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
@@ -1206,7 +1211,6 @@ private function addFileOptions($result, $optionRow)
1206
1211
protected function _importData ()
1207
1212
{
1208
1213
$ this ->_initProductsSku ();
1209
-
1210
1214
$ nextOptionId = $ this ->_resourceHelper ->getNextAutoincrement ($ this ->_tables ['catalog_product_option ' ]);
1211
1215
$ nextValueId = $ this ->_resourceHelper ->getNextAutoincrement (
1212
1216
$ this ->_tables ['catalog_product_option_type_value ' ]
@@ -1225,7 +1229,6 @@ protected function _importData()
1225
1229
$ parentCount = [];
1226
1230
$ childCount = [];
1227
1231
$ optionsToRemove = [];
1228
-
1229
1232
foreach ($ bunch as $ rowNumber => $ rowData ) {
1230
1233
if (isset ($ optionId , $ valueId ) && empty ($ rowData [PRODUCT ::COL_STORE_VIEW_CODE ])) {
1231
1234
$ nextOptionId = $ optionId ;
@@ -1273,17 +1276,26 @@ protected function _importData()
1273
1276
$ parentCount ,
1274
1277
$ childCount
1275
1278
);
1279
+
1276
1280
$ this ->_collectOptionTitle ($ combinedData , $ prevOptionId , $ titles );
1281
+ $ this ->checkOptionTitles (
1282
+ $ options ,
1283
+ $ titles ,
1284
+ $ combinedData ,
1285
+ $ prevOptionId ,
1286
+ $ optionId ,
1287
+ $ products ,
1288
+ $ prices
1289
+ );
1277
1290
}
1278
1291
}
1279
-
1280
1292
$ this ->removeExistingOptions ($ products , $ optionsToRemove );
1281
-
1282
1293
$ types = [
1283
1294
'values ' => $ typeValues ,
1284
1295
'prices ' => $ typePrices ,
1285
1296
'titles ' => $ typeTitles ,
1286
1297
];
1298
+ $ this ->setLastOptionTitle ($ titles );
1287
1299
//Save prepared custom options data.
1288
1300
$ this ->savePreparedCustomOptions (
1289
1301
$ products ,
@@ -1293,10 +1305,64 @@ protected function _importData()
1293
1305
$ types
1294
1306
);
1295
1307
}
1296
-
1297
1308
return true ;
1298
1309
}
1299
1310
1311
+ /**
1312
+ * If products were split up between bunches,
1313
+ * this function will add needed option for option titles
1314
+ *
1315
+ * @param array $options
1316
+ * @param array $titles
1317
+ * @param array $combinedData
1318
+ * @param int $prevOptionId
1319
+ * @param int $optionId
1320
+ * @param array $products
1321
+ * @param array $prices
1322
+ * @return void
1323
+ */
1324
+ private function checkOptionTitles (
1325
+ array &$ options ,
1326
+ array &$ titles ,
1327
+ array $ combinedData ,
1328
+ int &$ prevOptionId ,
1329
+ int &$ optionId ,
1330
+ array $ products ,
1331
+ array $ prices
1332
+ ) : void {
1333
+ $ titlesCount = count ($ titles );
1334
+ if ($ titlesCount > 0 && count ($ options ) !== $ titlesCount ) {
1335
+ $ combinedData [Product::COL_STORE_VIEW_CODE ] = '' ;
1336
+ $ optionId --;
1337
+ $ option = $ this ->_collectOptionMainData (
1338
+ $ combinedData ,
1339
+ $ prevOptionId ,
1340
+ $ optionId ,
1341
+ $ products ,
1342
+ $ prices
1343
+ );
1344
+ if ($ option ) {
1345
+ $ options [] = $ option ;
1346
+ }
1347
+ }
1348
+ }
1349
+
1350
+ /**
1351
+ * Setting last Custom Option Title
1352
+ * to use it later in _collectOptionTitle
1353
+ * to set correct title for default store view
1354
+ *
1355
+ * @param array $titles
1356
+ */
1357
+ private function setLastOptionTitle (array &$ titles ) : void
1358
+ {
1359
+ if (count ($ titles ) > 0 ) {
1360
+ end ($ titles );
1361
+ $ key = key ($ titles );
1362
+ $ this ->lastOptionTitle [$ key ] = $ titles [$ key ];
1363
+ }
1364
+ }
1365
+
1300
1366
/**
1301
1367
* Remove all existing options if import behaviour is APPEND
1302
1368
* in other case remove options for products with empty "custom_options" row only.
@@ -1447,8 +1513,12 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
1447
1513
$ defaultStoreId = Store::DEFAULT_STORE_ID ;
1448
1514
if (!empty ($ rowData [self ::COLUMN_TITLE ])) {
1449
1515
if (!isset ($ titles [$ prevOptionId ][$ defaultStoreId ])) {
1450
- // ensure default title is set
1451
- $ titles [$ prevOptionId ][$ defaultStoreId ] = $ rowData [self ::COLUMN_TITLE ];
1516
+ if (isset ($ this ->lastOptionTitle [$ prevOptionId ])) {
1517
+ $ titles [$ prevOptionId ] = $ this ->lastOptionTitle [$ prevOptionId ];
1518
+ unset($ this ->lastOptionTitle );
1519
+ } else {
1520
+ $ titles [$ prevOptionId ][$ defaultStoreId ] = $ rowData [self ::COLUMN_TITLE ];
1521
+ }
1452
1522
}
1453
1523
$ titles [$ prevOptionId ][$ this ->_rowStoreId ] = $ rowData [self ::COLUMN_TITLE ];
1454
1524
}
0 commit comments