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