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