@@ -681,7 +681,12 @@ protected function _getNewOptionsWithTheSameTitlesErrorRows(array $sourceProduct
681
681
ksort ($ outerTitles );
682
682
ksort ($ innerTitles );
683
683
if ($ outerTitles === $ innerTitles ) {
684
- $ errorRows = array_merge ($ errorRows , $ innerData ['rows ' ], $ outerData ['rows ' ]);
684
+ foreach ($ innerData ['rows ' ] as $ innerDataRow ) {
685
+ $ errorRows [] = $ innerDataRow ;
686
+ }
687
+ foreach ($ outerData ['rows ' ] as $ outerDataRow ) {
688
+ $ errorRows [] = $ outerDataRow ;
689
+ }
685
690
}
686
691
}
687
692
}
@@ -715,7 +720,9 @@ protected function _findOldOptionsWithTheSameTitles()
715
720
}
716
721
}
717
722
if ($ optionsCount > 1 ) {
718
- $ errorRows = array_merge ($ errorRows , $ outerData ['rows ' ]);
723
+ foreach ($ outerData ['rows ' ] as $ dataRow ) {
724
+ $ errorRows [] = $ dataRow ;
725
+ }
719
726
}
720
727
}
721
728
}
@@ -742,7 +749,9 @@ protected function _findNewOldOptionsTypeMismatch()
742
749
ksort ($ outerTitles );
743
750
ksort ($ innerTitles );
744
751
if ($ outerTitles === $ innerTitles && $ outerData ['type ' ] != $ innerData ['type ' ]) {
745
- $ errorRows = array_merge ($ errorRows , $ outerData ['rows ' ]);
752
+ foreach ($ outerData ['rows ' ] as $ dataRow ) {
753
+ $ errorRows [] = $ dataRow ;
754
+ }
746
755
}
747
756
}
748
757
}
@@ -955,8 +964,10 @@ public function validateRow(array $rowData, $rowNumber)
955
964
956
965
$ multiRowData = $ this ->_getMultiRowFormat ($ rowData );
957
966
958
- foreach ($ multiRowData as $ optionData ) {
959
- $ combinedData = array_merge ($ rowData , $ optionData );
967
+ foreach ($ multiRowData as $ combinedData ) {
968
+ foreach ($ rowData as $ key => $ field ) {
969
+ $ combinedData [$ key ] = $ field ;
970
+ }
960
971
961
972
if ($ this ->_isRowWithCustomOption ($ combinedData )) {
962
973
if ($ this ->_isMainOptionRow ($ combinedData )) {
@@ -1106,15 +1117,15 @@ protected function _getMultiRowFormat($rowData)
1106
1117
foreach ($ rowData ['custom_options ' ] as $ name => $ customOption ) {
1107
1118
$ i ++;
1108
1119
foreach ($ customOption as $ rowOrder => $ optionRow ) {
1109
- $ row = array_merge (
1110
- [
1111
- self ::COLUMN_STORE => '' ,
1112
- self ::COLUMN_TITLE => $ name ,
1113
- self ::COLUMN_SORT_ORDER => $ i ,
1114
- self :: COLUMN_ROW_SORT => $ rowOrder
1115
- ],
1116
- $ this -> processOptionRow ( $ name , $ optionRow )
1117
- );
1120
+ $ row = [
1121
+ self :: COLUMN_STORE => '' ,
1122
+ self ::COLUMN_TITLE => $ name ,
1123
+ self ::COLUMN_SORT_ORDER => $ i ,
1124
+ self ::COLUMN_ROW_SORT => $ rowOrder
1125
+ ];
1126
+ foreach ( $ this -> processOptionRow ( $ name , $ optionRow ) as $ key => $ value ) {
1127
+ $ row [ $ key ] = $ value ;
1128
+ }
1118
1129
$ name = '' ;
1119
1130
$ multiRow [] = $ row ;
1120
1131
}
@@ -1197,6 +1208,8 @@ private function addFileOptions($result, $optionRow)
1197
1208
*
1198
1209
* @return boolean
1199
1210
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
1211
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1212
+ * @SuppressWarnings(PHPMD.NPathComplexity)
1200
1213
*/
1201
1214
protected function _importData ()
1202
1215
{
@@ -1234,9 +1247,10 @@ protected function _importData()
1234
1247
$ optionsToRemove [] = $ this ->_rowProductId ;
1235
1248
}
1236
1249
}
1237
- foreach ($ multiRowData as $ optionData ) {
1238
- $ combinedData = array_merge ($ rowData , $ optionData );
1239
-
1250
+ foreach ($ multiRowData as $ combinedData ) {
1251
+ foreach ($ rowData as $ key => $ field ) {
1252
+ $ combinedData [$ key ] = $ field ;
1253
+ }
1240
1254
if (!$ this ->isRowAllowedToImport ($ combinedData , $ rowNumber )) {
1241
1255
continue ;
1242
1256
}
@@ -1403,7 +1417,9 @@ protected function _collectOptionMainData(
1403
1417
if (!$ this ->_isRowHasSpecificType ($ this ->_rowType )
1404
1418
&& ($ priceData = $ this ->_getPriceData ($ rowData , $ nextOptionId , $ this ->_rowType ))
1405
1419
) {
1406
- $ prices [$ nextOptionId ] = $ priceData ;
1420
+ if ($ this ->_isPriceGlobal ) {
1421
+ $ prices [$ nextOptionId ][Store::DEFAULT_STORE_ID ] = $ priceData ;
1422
+ }
1407
1423
}
1408
1424
1409
1425
if (!isset ($ products [$ this ->_rowProductId ])) {
@@ -1468,6 +1484,9 @@ protected function _collectOptionTypeData(
1468
1484
$ specificTypeData = $ this ->_getSpecificTypeData ($ rowData , 0 , false );
1469
1485
//For others stores
1470
1486
if ($ specificTypeData ) {
1487
+ if (isset ($ specificTypeData ['price ' ])) {
1488
+ $ typePrices [$ nextValueId ][$ this ->_rowStoreId ] = $ specificTypeData ['price ' ];
1489
+ }
1471
1490
$ typeTitles [$ nextValueId ++][$ this ->_rowStoreId ] = $ specificTypeData ['title ' ];
1472
1491
}
1473
1492
}
@@ -1505,6 +1524,7 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
1505
1524
* @param array &$prices
1506
1525
* @param array &$typeValues
1507
1526
* @return $this
1527
+ * @SuppressWarnings(PHPMD.UnusedLocalVariable)
1508
1528
*/
1509
1529
protected function _compareOptionsWithExisting (array &$ options , array &$ titles , array &$ prices , array &$ typeValues )
1510
1530
{
@@ -1515,7 +1535,9 @@ protected function _compareOptionsWithExisting(array &$options, array &$titles,
1515
1535
$ titles [$ optionId ] = $ titles [$ newOptionId ];
1516
1536
unset($ titles [$ newOptionId ]);
1517
1537
if (isset ($ prices [$ newOptionId ])) {
1518
- $ prices [$ newOptionId ]['option_id ' ] = $ optionId ;
1538
+ foreach ($ prices [$ newOptionId ] as $ storeId => $ priceStoreData ) {
1539
+ $ prices [$ newOptionId ][$ storeId ]['option_id ' ] = $ optionId ;
1540
+ }
1519
1541
}
1520
1542
if (isset ($ typeValues [$ newOptionId ])) {
1521
1543
$ typeValues [$ optionId ] = $ typeValues [$ newOptionId ];
@@ -1548,8 +1570,10 @@ private function restoreOriginalOptionTypeIds(array &$typeValues, array &$typePr
1548
1570
$ optionType ['option_type_id ' ] = $ existingTypeId ;
1549
1571
$ typeTitles [$ existingTypeId ] = $ typeTitles [$ optionTypeId ];
1550
1572
unset($ typeTitles [$ optionTypeId ]);
1551
- $ typePrices [$ existingTypeId ] = $ typePrices [$ optionTypeId ];
1552
- unset($ typePrices [$ optionTypeId ]);
1573
+ if (isset ($ typePrices [$ optionTypeId ])) {
1574
+ $ typePrices [$ existingTypeId ] = $ typePrices [$ optionTypeId ];
1575
+ unset($ typePrices [$ optionTypeId ]);
1576
+ }
1553
1577
// If option type titles match at least in one store, consider current option type as existing
1554
1578
break ;
1555
1579
}
@@ -1606,7 +1630,7 @@ protected function _parseRequiredData(array $rowData)
1606
1630
if (!isset ($ this ->_storeCodeToId [$ rowData [self ::COLUMN_STORE ]])) {
1607
1631
return false ;
1608
1632
}
1609
- $ this ->_rowStoreId = $ this ->_storeCodeToId [$ rowData [self ::COLUMN_STORE ]];
1633
+ $ this ->_rowStoreId = ( int ) $ this ->_storeCodeToId [$ rowData [self ::COLUMN_STORE ]];
1610
1634
} else {
1611
1635
$ this ->_rowStoreId = Store::DEFAULT_STORE_ID ;
1612
1636
}
@@ -1722,7 +1746,7 @@ protected function _getPriceData(array $rowData, $optionId, $type)
1722
1746
) {
1723
1747
$ priceData = [
1724
1748
'option_id ' => $ optionId ,
1725
- 'store_id ' => Store:: DEFAULT_STORE_ID ,
1749
+ 'store_id ' => $ this -> _rowStoreId ,
1726
1750
'price_type ' => 'fixed ' ,
1727
1751
];
1728
1752
@@ -1749,28 +1773,30 @@ protected function _getPriceData(array $rowData, $optionId, $type)
1749
1773
*/
1750
1774
protected function _getSpecificTypeData (array $ rowData , $ optionTypeId , $ defaultStore = true )
1751
1775
{
1776
+ $ data = [];
1777
+ $ priceData = [];
1778
+ $ customOptionRowPrice = $ rowData [self ::COLUMN_ROW_PRICE ];
1779
+ if (!empty ($ customOptionRowPrice ) || $ customOptionRowPrice === '0 ' ) {
1780
+ $ priceData ['price ' ] = (double )rtrim ($ rowData [self ::COLUMN_ROW_PRICE ], '% ' );
1781
+ $ priceData ['price_type ' ] = ('% ' == substr ($ rowData [self ::COLUMN_ROW_PRICE ], -1 )) ? 'percent ' : 'fixed ' ;
1782
+ }
1752
1783
if (!empty ($ rowData [self ::COLUMN_ROW_TITLE ]) && $ defaultStore && empty ($ rowData [self ::COLUMN_STORE ])) {
1753
1784
$ valueData = [
1754
1785
'option_type_id ' => $ optionTypeId ,
1755
1786
'sort_order ' => empty ($ rowData [self ::COLUMN_ROW_SORT ]) ? 0 : abs ($ rowData [self ::COLUMN_ROW_SORT ]),
1756
1787
'sku ' => !empty ($ rowData [self ::COLUMN_ROW_SKU ]) ? $ rowData [self ::COLUMN_ROW_SKU ] : '' ,
1757
1788
];
1758
-
1759
- $ priceData = false ;
1760
- if (!empty ($ rowData [self ::COLUMN_ROW_PRICE ])) {
1761
- $ priceData = [
1762
- 'price ' => (double )rtrim ($ rowData [self ::COLUMN_ROW_PRICE ], '% ' ),
1763
- 'price_type ' => 'fixed ' ,
1764
- ];
1765
- if ('% ' == substr ($ rowData [self ::COLUMN_ROW_PRICE ], -1 )) {
1766
- $ priceData ['price_type ' ] = 'percent ' ;
1767
- }
1768
- }
1769
- return ['value ' => $ valueData , 'title ' => $ rowData [self ::COLUMN_ROW_TITLE ], 'price ' => $ priceData ];
1789
+ $ data ['value ' ] = $ valueData ;
1790
+ $ data ['title ' ] = $ rowData [self ::COLUMN_ROW_TITLE ];
1791
+ $ data ['price ' ] = $ priceData ;
1770
1792
} elseif (!empty ($ rowData [self ::COLUMN_ROW_TITLE ]) && !$ defaultStore && !empty ($ rowData [self ::COLUMN_STORE ])) {
1771
- return ['title ' => $ rowData [self ::COLUMN_ROW_TITLE ]];
1793
+ if ($ priceData ) {
1794
+ $ data ['price ' ] = $ priceData ;
1795
+ }
1796
+ $ data ['title ' ] = $ rowData [self ::COLUMN_ROW_TITLE ];
1772
1797
}
1773
- return false ;
1798
+
1799
+ return $ data ?: false ;
1774
1800
}
1775
1801
1776
1802
/**
@@ -1828,7 +1854,9 @@ protected function _saveTitles(array $titles)
1828
1854
{
1829
1855
$ titleRows = [];
1830
1856
foreach ($ titles as $ optionId => $ storeInfo ) {
1831
- foreach ($ storeInfo as $ storeId => $ title ) {
1857
+ //for use default
1858
+ $ uniqStoreInfo = array_unique ($ storeInfo );
1859
+ foreach ($ uniqStoreInfo as $ storeId => $ title ) {
1832
1860
$ titleRows [] = ['option_id ' => $ optionId , 'store_id ' => $ storeId , 'title ' => $ title ];
1833
1861
}
1834
1862
}
@@ -1852,11 +1880,19 @@ protected function _saveTitles(array $titles)
1852
1880
protected function _savePrices (array $ prices )
1853
1881
{
1854
1882
if ($ prices ) {
1855
- $ this ->_connection ->insertOnDuplicate (
1856
- $ this ->_tables ['catalog_product_option_price ' ],
1857
- $ prices ,
1858
- ['price ' , 'price_type ' ]
1859
- );
1883
+ $ optionPriceRows = [];
1884
+ foreach ($ prices as $ storesData ) {
1885
+ foreach ($ storesData as $ row ) {
1886
+ $ optionPriceRows [] = $ row ;
1887
+ }
1888
+ }
1889
+ if ($ optionPriceRows ) {
1890
+ $ this ->_connection ->insertOnDuplicate (
1891
+ $ this ->_tables ['catalog_product_option_price ' ],
1892
+ $ optionPriceRows ,
1893
+ ['price ' , 'price_type ' ]
1894
+ );
1895
+ }
1860
1896
}
1861
1897
1862
1898
return $ this ;
@@ -1923,7 +1959,9 @@ protected function _saveSpecificTypeTitles(array $typeTitles)
1923
1959
{
1924
1960
$ optionTypeTitleRows = [];
1925
1961
foreach ($ typeTitles as $ optionTypeId => $ storesData ) {
1926
- foreach ($ storesData as $ storeId => $ title ) {
1962
+ //for use default
1963
+ $ uniqStoresData = array_unique ($ storesData );
1964
+ foreach ($ uniqStoresData as $ storeId => $ title ) {
1927
1965
$ optionTypeTitleRows [] = [
1928
1966
'option_type_id ' => $ optionTypeId ,
1929
1967
'store_id ' => $ storeId ,
0 commit comments