@@ -1290,11 +1290,23 @@ private function appendMultirowData(&$dataRow, $multiRawData)
1290
1290
}
1291
1291
1292
1292
if (!empty ($ multiRawData ['customOptionsData ' ][$ productLinkId ][$ storeId ])) {
1293
+ $ shouldBeMerged = true ;
1293
1294
$ customOptionsRows = $ multiRawData ['customOptionsData ' ][$ productLinkId ][$ storeId ];
1294
- $ multiRawData ['customOptionsData ' ][$ productLinkId ][$ storeId ] = [];
1295
- $ customOptions = implode (ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR , $ customOptionsRows );
1296
1295
1297
- $ dataRow = array_merge ($ dataRow , ['custom_options ' => $ customOptions ]);
1296
+ if ($ storeId != Store::DEFAULT_STORE_ID
1297
+ && !empty ($ multiRawData ['customOptionsData ' ][$ productLinkId ][Store::DEFAULT_STORE_ID ])
1298
+ ) {
1299
+ $ defaultCustomOptions = $ multiRawData ['customOptionsData ' ][$ productLinkId ][Store::DEFAULT_STORE_ID ];
1300
+ if (!array_diff ($ defaultCustomOptions , $ customOptionsRows )) {
1301
+ $ shouldBeMerged = false ;
1302
+ }
1303
+ }
1304
+
1305
+ if ($ shouldBeMerged ) {
1306
+ $ multiRawData ['customOptionsData ' ][$ productLinkId ][$ storeId ] = [];
1307
+ $ customOptions = implode (ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR , $ customOptionsRows );
1308
+ $ dataRow = array_merge ($ dataRow , ['custom_options ' => $ customOptions ]);
1309
+ }
1298
1310
}
1299
1311
1300
1312
if (empty ($ dataRow )) {
@@ -1390,6 +1402,7 @@ protected function optionRowToCellString($option)
1390
1402
protected function getCustomOptionsData ($ productIds )
1391
1403
{
1392
1404
$ customOptionsData = [];
1405
+ $ defaultOptionsData = [];
1393
1406
1394
1407
foreach (array_keys ($ this ->_storeIdToCode ) as $ storeId ) {
1395
1408
$ options = $ this ->_optionColFactory ->create ();
@@ -1402,38 +1415,42 @@ protected function getCustomOptionsData($productIds)
1402
1415
->addValuesToResult ($ storeId );
1403
1416
1404
1417
foreach ($ options as $ option ) {
1418
+ $ optionData = $ option ->toArray ();
1405
1419
$ row = [];
1406
1420
$ productId = $ option ['product_id ' ];
1407
1421
$ row ['name ' ] = $ option ['title ' ];
1408
1422
$ row ['type ' ] = $ option ['type ' ];
1409
- if (Store::DEFAULT_STORE_ID === $ storeId ) {
1410
- $ row ['required ' ] = $ option ['is_require ' ];
1411
- $ row ['price ' ] = $ option ['price ' ];
1412
- $ row ['price_type ' ] = ($ option ['price_type ' ] === 'percent ' ) ? 'percent ' : 'fixed ' ;
1413
- $ row ['sku ' ] = $ option ['sku ' ];
1414
- if ($ option ['max_characters ' ]) {
1415
- $ row ['max_characters ' ] = $ option ['max_characters ' ];
1416
- }
1417
-
1418
- foreach (['file_extension ' , 'image_size_x ' , 'image_size_y ' ] as $ fileOptionKey ) {
1419
- if (!isset ($ option [$ fileOptionKey ])) {
1420
- continue ;
1421
- }
1422
1423
1423
- $ row [$ fileOptionKey ] = $ option [$ fileOptionKey ];
1424
+ $ row ['required ' ] = $ this ->getOptionValue ('is_require ' , $ defaultOptionsData , $ optionData );
1425
+ $ row ['price ' ] = $ this ->getOptionValue ('price ' , $ defaultOptionsData , $ optionData );
1426
+ $ row ['sku ' ] = $ this ->getOptionValue ('sku ' , $ defaultOptionsData , $ optionData );
1427
+ if (array_key_exists ('max_characters ' , $ optionData )
1428
+ || array_key_exists ('max_characters ' , $ defaultOptionsData )
1429
+ ) {
1430
+ $ row ['max_characters ' ] = $ this ->getOptionValue ('max_characters ' , $ defaultOptionsData , $ optionData );
1431
+ }
1432
+ foreach (['file_extension ' , 'image_size_x ' , 'image_size_y ' ] as $ fileOptionKey ) {
1433
+ if (isset ($ option [$ fileOptionKey ]) || isset ($ defaultOptionsData [$ fileOptionKey ])) {
1434
+ $ row [$ fileOptionKey ] = $ this ->getOptionValue ($ fileOptionKey , $ defaultOptionsData , $ optionData );
1424
1435
}
1425
1436
}
1437
+ $ percentType = $ this ->getOptionValue ('price_type ' , $ defaultOptionsData , $ optionData );
1438
+ $ row ['price_type ' ] = ($ percentType === 'percent ' ) ? 'percent ' : 'fixed ' ;
1439
+
1440
+ if (Store::DEFAULT_STORE_ID === $ storeId ) {
1441
+ $ optionId = $ option ['option_id ' ];
1442
+ $ defaultOptionsData [$ optionId ] = $ option ->toArray ();
1443
+ }
1444
+
1426
1445
$ values = $ option ->getValues ();
1427
1446
1428
1447
if ($ values ) {
1429
1448
foreach ($ values as $ value ) {
1430
1449
$ row ['option_title ' ] = $ value ['title ' ];
1431
- if (Store::DEFAULT_STORE_ID === $ storeId ) {
1432
- $ row ['option_title ' ] = $ value ['title ' ];
1433
- $ row ['price ' ] = $ value ['price ' ];
1434
- $ row ['price_type ' ] = ($ value ['price_type ' ] === 'percent ' ) ? 'percent ' : 'fixed ' ;
1435
- $ row ['sku ' ] = $ value ['sku ' ];
1436
- }
1450
+ $ row ['option_title ' ] = $ value ['title ' ];
1451
+ $ row ['price ' ] = $ value ['price ' ];
1452
+ $ row ['price_type ' ] = ($ value ['price_type ' ] === 'percent ' ) ? 'percent ' : 'fixed ' ;
1453
+ $ row ['sku ' ] = $ value ['sku ' ];
1437
1454
$ customOptionsData [$ productId ][$ storeId ][] = $ this ->optionRowToCellString ($ row );
1438
1455
}
1439
1456
} else {
@@ -1447,6 +1464,31 @@ protected function getCustomOptionsData($productIds)
1447
1464
return $ customOptionsData ;
1448
1465
}
1449
1466
1467
+ /**
1468
+ * Get value for custom option according to store or default value
1469
+ *
1470
+ * @param string $optionName
1471
+ * @param array $defaultOptionsData
1472
+ * @param array $optionData
1473
+ * @return mixed
1474
+ */
1475
+ private function getOptionValue ($ optionName , $ defaultOptionsData , $ optionData )
1476
+ {
1477
+ $ optionId = $ optionData ['option_id ' ];
1478
+
1479
+ if (array_key_exists ($ optionName , $ optionData ) && $ optionData [$ optionName ] !== null ) {
1480
+ return $ optionData [$ optionName ];
1481
+ }
1482
+
1483
+ if (array_key_exists ($ optionId , $ defaultOptionsData )
1484
+ && array_key_exists ($ optionName , $ defaultOptionsData [$ optionId ])
1485
+ ) {
1486
+ return $ defaultOptionsData [$ optionId ][$ optionName ];
1487
+ }
1488
+
1489
+ return null ;
1490
+ }
1491
+
1450
1492
/**
1451
1493
* Clean up already loaded attribute collection.
1452
1494
*
0 commit comments