1
1
<?php
2
2
/**
3
- * Copyright 2015 Adobe
4
- * All Rights Reserved .
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details .
5
5
*/
6
6
7
7
namespace Magento \ConfigurableProduct \Pricing \Price ;
8
8
9
9
use Magento \Catalog \Model \Product ;
10
+ use Magento \ConfigurableProduct \Model \ConfigurableMaxPriceCalculator ;
10
11
use Magento \Framework \App \ObjectManager ;
11
12
use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
12
13
use Magento \Framework \Pricing \Price \AbstractPrice ;
@@ -54,12 +55,18 @@ class ConfigurableRegularPrice extends AbstractPrice implements
54
55
*/
55
56
private $ lowestPriceOptionsProvider ;
56
57
58
+ /**
59
+ * @var ConfigurableMaxPriceCalculator
60
+ */
61
+ private $ configurableMaxPriceCalculator ;
62
+
57
63
/**
58
64
* @param \Magento\Framework\Pricing\SaleableInterface $saleableItem
59
65
* @param float $quantity
60
66
* @param \Magento\Framework\Pricing\Adjustment\CalculatorInterface $calculator
61
67
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
62
68
* @param PriceResolverInterface $priceResolver
69
+ * @param ConfigurableMaxPriceCalculator $configurableMaxPriceCalculator
63
70
* @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
64
71
*/
65
72
public function __construct (
@@ -68,12 +75,14 @@ public function __construct(
68
75
\Magento \Framework \Pricing \Adjustment \CalculatorInterface $ calculator ,
69
76
\Magento \Framework \Pricing \PriceCurrencyInterface $ priceCurrency ,
70
77
PriceResolverInterface $ priceResolver ,
78
+ ConfigurableMaxPriceCalculator $ configurableMaxPriceCalculator ,
71
79
?LowestPriceOptionsProviderInterface $ lowestPriceOptionsProvider = null
72
80
) {
73
81
parent ::__construct ($ saleableItem , $ quantity , $ calculator , $ priceCurrency );
74
82
$ this ->priceResolver = $ priceResolver ;
75
83
$ this ->lowestPriceOptionsProvider = $ lowestPriceOptionsProvider ?:
76
84
ObjectManager::getInstance ()->get (LowestPriceOptionsProviderInterface::class);
85
+ $ this ->configurableMaxPriceCalculator = $ configurableMaxPriceCalculator ;
77
86
}
78
87
79
88
/**
@@ -187,28 +196,26 @@ public function _resetState(): void
187
196
}
188
197
189
198
/**
190
- * Check whether Configurable Product has more than one child product and if their prices are equal
199
+ * Check whether Configurable Product have more than one children products
191
200
*
192
201
* @param SaleableInterface $product
193
202
* @return bool
194
203
*/
195
204
public function isChildProductsOfEqualPrices (SaleableInterface $ product ): bool
196
205
{
197
- // Get all child products of the configurable product
198
- $ childProducts = $ product ->getTypeInstance ()->getUsedProducts ($ product );
199
- if (count ($ childProducts ) <= 1 ) {
200
- return false ; // Not more than one child product
206
+ $ minPrice = $ this ->getMinRegularAmount ()->getValue ();
207
+ $ final_price = $ product ->getFinalPrice ();
208
+ $ productId = $ product ->getId ();
209
+ if ($ final_price < $ minPrice ) {
210
+ return false ;
201
211
}
202
-
203
- $ prices = [];
204
- foreach ($ childProducts as $ child ) {
205
- $ prices [] = $ child ->getFinalPrice ();
212
+ $ attributes = $ product ->getTypeInstance ()->getConfigurableAttributes ($ product );
213
+ $ items = $ attributes ->getItems ();
214
+ $ options = reset ($ items );
215
+ $ maxPrice = $ this ->configurableMaxPriceCalculator ->getMaxPriceForConfigurableProduct ($ productId );
216
+ if ($ maxPrice == 0 ) {
217
+ $ maxPrice = $ this ->getMaxRegularAmount ()->getValue ();
206
218
}
207
-
208
- $ minPrice = min ($ prices );
209
- $ maxPrice = max ($ prices );
210
-
211
- // Return true only if all child prices are equal (min == max)
212
- return $ minPrice == $ maxPrice ;
219
+ return (count ($ options ->getOptions ()) > 1 ) && $ minPrice == $ maxPrice ;
213
220
}
214
221
}
0 commit comments