@@ -26,9 +26,6 @@ protected function addAdditionalData($product, $withTax, $subProducts, $currency
26
26
$ this ->handleOriginalPrice ($ field , $ currencyCode , $ min , $ max , $ minOriginal , $ maxOriginal );
27
27
if (!$ this ->customData [$ field ][$ currencyCode ]['default ' ]) {
28
28
$ this ->handleZeroDefaultPrice ($ field , $ currencyCode , $ min , $ max );
29
- # need to rehandle specialPrice
30
- $ specialPrice = $ this ->getSpecialPrice ($ product , $ currencyCode , $ withTax );
31
- $ this ->addSpecialPrices ($ specialPrice , $ field , $ currencyCode );
32
29
}
33
30
if ($ this ->areCustomersGroupsEnabled ) {
34
31
$ this ->setFinalGroupPrices ($ field , $ currencyCode , $ min , $ max , $ dashedFormat , $ product , $ subProducts , $ withTax );
@@ -51,7 +48,14 @@ protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $cu
51
48
if (count ($ subProducts ) > 0 ) {
52
49
/** @var Product $subProduct */
53
50
foreach ($ subProducts as $ subProduct ) {
54
- $ price = $ this ->getTaxPrice ($ product , $ subProduct ->getFinalPrice (), $ withTax );
51
+ $ specialPrice = $ this ->getSpecialPrice ($ subProduct , $ currencyCode , $ withTax , $ subProducts );
52
+ $ tierPrice = $ this ->getTierPrice ($ subProduct , $ currencyCode , $ withTax );
53
+ if (!empty ($ tierPrice [0 ]) && $ specialPrice [0 ] > $ tierPrice [0 ]){
54
+ $ minPrice = $ tierPrice [0 ];
55
+ } else {
56
+ $ minPrice = $ specialPrice [0 ];
57
+ }
58
+ $ price = $ minPrice ?? $ this ->getTaxPrice ($ product , $ subProduct ->getFinalPrice (), $ withTax );
55
59
$ basePrice = $ this ->getTaxPrice ($ product , $ subProduct ->getPrice (), $ withTax );
56
60
$ min = min ($ min , $ price );
57
61
$ original = min ($ original , $ basePrice );
@@ -153,28 +157,32 @@ protected function handleZeroDefaultPrice($field, $currencyCode, $min, $max)
153
157
protected function setFinalGroupPrices ($ field , $ currencyCode , $ min , $ max , $ dashedFormat , $ product , $ subproducts , $ withTax )
154
158
{
155
159
if (count ($ subproducts ) > 0 ) {
156
- $ array = [];
160
+ $ groupPriceList = [];
157
161
/** @var Group $group */
158
162
foreach ($ this ->groups as $ group ) {
159
163
$ groupId = (int ) $ group ->getData ('customer_group_id ' );
164
+ $ minPrice = $ min ;
160
165
foreach ($ subproducts as $ subProduct ) {
161
166
$ subProduct ->setData ('customer_group_id ' , $ groupId );
162
167
$ subProduct ->setData ('website_id ' , $ subProduct ->getStore ()->getWebsiteId ());
168
+ $ specialPrice = $ this ->getSpecialPrice ($ subProduct , $ currencyCode , $ withTax , []);
169
+ $ tierPrice = $ this ->getTierPrice ($ subProduct , $ currencyCode , $ withTax );
163
170
$ price = $ this ->getTaxPrice ($ product , $ subProduct ->getPriceModel ()->getFinalPrice (1 , $ subProduct ), $ withTax );
164
- $ array [$ groupId ][] = $ price ;
171
+ if (!empty ($ tierPrice [$ groupId ]) && $ specialPrice [$ groupId ] > $ tierPrice [$ groupId ]){
172
+ $ minPrice = $ tierPrice [$ groupId ];
173
+ }
174
+ $ groupPriceList [$ groupId ]['min ' ] = min ($ minPrice , $ price );
175
+ $ groupPriceList [$ groupId ]['max ' ] = max ($ max , $ price );
165
176
$ subProduct ->setData ('customer_group_id ' , null );
166
177
}
167
178
}
179
+
168
180
$ minArray = [];
169
- foreach ($ array as $ key => $ value ) {
170
- $ minArray [$ key ]['price ' ] = min ($ value );
171
- $ price = min ($ value );
172
- $ formattedPrice = $ this ->formatPrice ($ price , $ currencyCode );
173
- $ minArray [$ key ]['formatted ' ] = $ formattedPrice ;
181
+ foreach ($ groupPriceList as $ key => $ value ) {
182
+ $ minArray [$ key ]['price ' ] = $ value ['min ' ];
183
+ $ minArray [$ key ]['formatted ' ] = $ this ->formattedConfigPrice ($ value ['min ' ], $ value ['max ' ], $ currencyCode );
174
184
if ($ currencyCode !== $ this ->baseCurrencyCode ) {
175
- $ min = $ this ->convertPrice ($ price , $ currencyCode );
176
- $ formattedPrice = $ this ->formatPrice ($ min , $ currencyCode );
177
- $ minArray [$ key ]['formatted ' ] = strval ($ formattedPrice );
185
+ $ minArray [$ key ]['formatted ' ] = $ this ->formattedConfigPrice ($ value ['min ' ], $ value ['max ' ], $ currencyCode );
178
186
}
179
187
}
180
188
/** @var Group $group */
@@ -200,6 +208,20 @@ protected function setFinalGroupPrices($field, $currencyCode, $min, $max, $dashe
200
208
}
201
209
}
202
210
211
+ /**
212
+ * @param $min
213
+ * @param $max
214
+ * @param $currencyCode
215
+ * @return mixed|string
216
+ */
217
+ public function formattedConfigPrice ($ min , $ max , $ currencyCode ) {
218
+ if ($ min != $ max ) {
219
+ return $ this ->getDashedPriceFormat ($ min , $ max , $ currencyCode );
220
+ } else {
221
+ return $ this ->formatPrice ($ min , $ currencyCode );
222
+ }
223
+ }
224
+
203
225
/**
204
226
* @param $field
205
227
* @param $currencyCode
@@ -219,11 +241,13 @@ public function handleOriginalPrice($field, $currencyCode, $min, $max, $minOrigi
219
241
$ maxOriginal ,
220
242
$ currencyCode
221
243
);
244
+ $ this ->handleGroupOrginalPriceformated ($ field , $ currencyCode , $ this ->customData [$ field ][$ currencyCode ]['default_original_formated ' ]);
222
245
} else {
223
246
$ this ->customData [$ field ][$ currencyCode ]['default_original_formated ' ] = $ this ->formatPrice (
224
247
$ minOriginal ,
225
248
$ currencyCode
226
249
);
250
+ $ this ->handleGroupOrginalPriceformated ($ field , $ currencyCode , $ this ->customData [$ field ][$ currencyCode ]['default_original_formated ' ]);
227
251
}
228
252
}
229
253
} else {
@@ -232,6 +256,25 @@ public function handleOriginalPrice($field, $currencyCode, $min, $max, $minOrigi
232
256
$ minOriginal ,
233
257
$ currencyCode
234
258
);
259
+ $ this ->handleGroupOrginalPriceformated ($ field , $ currencyCode , $ this ->customData [$ field ][$ currencyCode ]['default_original_formated ' ]);
260
+ }
261
+ }
262
+
263
+ }
264
+
265
+ /**
266
+ * @param $field
267
+ * @param $currencyCode
268
+ * @param $formatedPrice
269
+ * @return void
270
+ */
271
+ public function handleGroupOrginalPriceformated ($ field , $ currencyCode , $ formatedPrice ) {
272
+ if ($ this ->areCustomersGroupsEnabled ) {
273
+ /** @var Group $group */
274
+ foreach ($ this ->groups as $ group ) {
275
+ $ groupId = (int )$ group ->getData ('customer_group_id ' );
276
+ $ this ->customData [$ field ][$ currencyCode ]['group_ ' . $ groupId . '_original_formated ' ] =
277
+ $ formatedPrice ;
235
278
}
236
279
}
237
280
}
0 commit comments