@@ -19,13 +19,14 @@ class Bundle extends ProductWithChildren
19
19
*/
20
20
protected function addAdditionalData ($ product , $ withTax , $ subProducts , $ currencyCode , $ field ) {
21
21
$ data = $ this ->getMinMaxPrices ($ product , $ withTax , $ subProducts , $ currencyCode );
22
- $ dashedFormat = $ this ->getDashedPriceFormat ($ data ['min_price ' ], $ data ['max ' ], $ currencyCode );
23
- if ($ data ['min_price ' ] !== $ data ['max ' ]) {
24
- $ this ->handleBundleNonEqualMinMaxPrices ($ field , $ currencyCode , $ data ['min_price ' ], $ data ['max ' ], $ dashedFormat );
22
+ $ dashedFormat = $ this ->getDashedPriceFormat ($ data ['min_price ' ], $ data ['max_price ' ], $ currencyCode );
23
+ if ($ data ['min_price ' ] !== $ data ['max_price ' ]) {
24
+ $ this ->handleBundleNonEqualMinMaxPrices ($ field , $ currencyCode , $ data ['min_price ' ], $ data ['max_price ' ], $ dashedFormat );
25
25
}
26
- $ this ->handleOriginalPrice ($ field , $ currencyCode , $ data ['min_price ' ], $ data ['max ' ], $ data ['min_original ' ], $ data ['max_original ' ]);
26
+
27
+ $ this ->handleOriginalPrice ($ field , $ currencyCode , $ data ['min_price ' ], $ data ['max_price ' ], $ data ['min_original ' ], $ data ['max_original ' ]);
27
28
if (!$ this ->customData [$ field ][$ currencyCode ]['default ' ]) {
28
- $ this ->handleZeroDefaultPrice ($ field , $ currencyCode , $ data ['min_price ' ], $ data ['max ' ]);
29
+ $ this ->handleZeroDefaultPrice ($ field , $ currencyCode , $ data ['min_price ' ], $ data ['max_price ' ]);
29
30
}
30
31
if ($ this ->areCustomersGroupsEnabled ) {
31
32
$ groupedDashedFormat = $ this ->getBundleDashedPriceFormat ($ data ['min ' ], $ data ['max ' ], $ currencyCode );
@@ -42,25 +43,29 @@ protected function addAdditionalData($product, $withTax, $subProducts, $currency
42
43
*/
43
44
protected function getMinMaxPrices (Product $ product , $ withTax , $ subProducts , $ currencyCode )
44
45
{
45
- $ regularPrice = $ product ->getPriceInfo ()-> getPrice ( ' regular_price ' )-> getMinimalPrice ()->getValue ( );
46
+ $ product ->setData ( ' website_id ' , $ product -> getStore ()->getWebsiteId () );
46
47
$ minPrice = $ product ->getPriceInfo ()->getPrice ('final_price ' )->getMinimalPrice ()->getValue ();
47
48
$ minOriginalPrice = $ product ->getPriceInfo ()->getPrice ('regular_price ' )->getMinimalPrice ()->getValue ();
48
49
$ maxOriginalPrice = $ product ->getPriceInfo ()->getPrice ('regular_price ' )->getMaximalPrice ()->getValue ();
49
50
$ max = $ product ->getPriceInfo ()->getPrice ('final_price ' )->getMaximalPrice ()->getValue ();
50
51
$ minArray = [];
52
+ $ maxArray = [];
51
53
foreach ($ this ->groups as $ group ) {
52
54
$ groupId = (int ) $ group ->getData ('customer_group_id ' );
53
- foreach ($ subProducts as $ subProduct ) {
54
- $ subProduct ->setData ('customer_group_id ' , $ groupId );
55
- $ subProductFinalPrice = $ this ->getTaxPrice ($ product , $ subProduct ->getPriceModel ()->getFinalPrice (1 , $ subProduct ), $ withTax );
56
- $ priceDiff = $ subProduct ->getPrice () - $ subProductFinalPrice ;
57
- $ minArray [$ groupId ][] = $ regularPrice - $ priceDiff ;
58
- }
55
+ $ product ->setData ('customer_group_id ' , $ groupId );
56
+ $ minPrice = $ product ->getPriceInfo ()->getPrice ('final_price ' )->getMinimalPrice ()->getValue ();
57
+ $ minArray [$ groupId ] = $ product ->getPriceInfo ()->getPrice ('final_price ' )->getMinimalPrice ()->getValue ();
58
+ $ maxArray [$ groupId ] = $ product ->getPriceInfo ()->getPrice ('final_price ' )->getMaximalPrice ()->getValue ();
59
+ $ product ->setData ('customer_group_id ' , null );
59
60
}
60
61
61
62
$ minPriceArray = [];
62
63
foreach ($ minArray as $ groupId => $ min ) {
63
- $ minPriceArray [$ groupId ] = min ($ min );
64
+ $ minPriceArray [$ groupId ] = $ min ;
65
+ }
66
+ $ maxPriceArray = [];
67
+ foreach ($ maxArray as $ groupId => $ max ) {
68
+ $ maxPriceArray [$ groupId ] = $ max ;
64
69
}
65
70
66
71
if ($ currencyCode !== $ this ->baseCurrencyCode ) {
@@ -70,15 +75,15 @@ protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $cu
70
75
foreach ($ minPriceArray as $ groupId => $ price ) {
71
76
$ minPriceArray [$ groupId ] = $ this ->convertPrice ($ price , $ currencyCode );
72
77
}
73
- if ($ min !== $ max ) {
78
+ if ($ minPrice !== $ max ) {
74
79
$ max = $ this ->convertPrice ($ max , $ currencyCode );
75
80
}
76
81
}
77
-
78
82
return [
79
83
'min ' => $ minPriceArray ,
80
- 'max ' => $ max ,
84
+ 'max ' => $ maxPriceArray ,
81
85
'min_price ' => $ minPrice ,
86
+ 'max_price ' => $ max ,
82
87
'min_original ' => $ minOriginalPrice ,
83
88
'max_original ' => $ maxOriginalPrice
84
89
];
@@ -117,10 +122,10 @@ protected function handleBundleNonEqualMinMaxPrices($field, $currencyCode, $min,
117
122
protected function getBundleDashedPriceFormat ($ minPrices , $ max , $ currencyCode ) {
118
123
$ dashedFormatPrice = [];
119
124
foreach ($ minPrices as $ groupId => $ min ) {
120
- if ($ min === $ max ) {
125
+ if ($ min === $ max[ $ groupId ] ) {
121
126
$ dashedFormatPrice [$ groupId ] = '' ;
122
127
}
123
- $ dashedFormatPrice [$ groupId ] = $ this ->formatPrice ($ min , $ currencyCode ) . ' - ' . $ this ->formatPrice ($ max , $ currencyCode );
128
+ $ dashedFormatPrice [$ groupId ] = $ this ->formatPrice ($ min , $ currencyCode ) . ' - ' . $ this ->formatPrice ($ max[ $ groupId ] , $ currencyCode );
124
129
}
125
130
return $ dashedFormatPrice ;
126
131
}
@@ -139,12 +144,12 @@ protected function setFinalGroupPricesBundle($field, $currencyCode, $min, $max,
139
144
foreach ($ this ->groups as $ group ) {
140
145
$ groupId = (int ) $ group ->getData ('customer_group_id ' );
141
146
$ this ->customData [$ field ][$ currencyCode ]['group_ ' . $ groupId ] = $ min [$ groupId ];
142
- if ($ min === $ max ) {
147
+ if ($ min[ $ groupId ] === $ max[ $ groupId ] ) {
143
148
$ this ->customData [$ field ][$ currencyCode ]['group_ ' . $ groupId . '_formated ' ] =
144
149
$ this ->customData [$ field ][$ currencyCode ]['default_formated ' ];
145
150
} else {
146
151
$ this ->customData [$ field ][$ currencyCode ]['group_ ' . $ groupId . '_formated ' ] = $ dashedFormat [$ groupId ];
147
152
}
148
153
}
149
154
}
150
- }
155
+ }
0 commit comments