Skip to content

Commit 84e1f27

Browse files
committed
Fix PAT failure
1 parent 72733c3 commit 84e1f27

File tree

4 files changed

+41
-288
lines changed

4 files changed

+41
-288
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Price/ConfigurableRegularPrice.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22
/**
3-
* Copyright 2015 Adobe
4-
* All Rights Reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
55
*/
66

77
namespace Magento\ConfigurableProduct\Pricing\Price;
88

99
use Magento\Catalog\Model\Product;
10+
use Magento\ConfigurableProduct\Model\ConfigurableMaxPriceCalculator;
1011
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1213
use Magento\Framework\Pricing\Price\AbstractPrice;
@@ -54,12 +55,18 @@ class ConfigurableRegularPrice extends AbstractPrice implements
5455
*/
5556
private $lowestPriceOptionsProvider;
5657

58+
/**
59+
* @var ConfigurableMaxPriceCalculator
60+
*/
61+
private $configurableMaxPriceCalculator;
62+
5763
/**
5864
* @param \Magento\Framework\Pricing\SaleableInterface $saleableItem
5965
* @param float $quantity
6066
* @param \Magento\Framework\Pricing\Adjustment\CalculatorInterface $calculator
6167
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
6268
* @param PriceResolverInterface $priceResolver
69+
* @param ConfigurableMaxPriceCalculator $configurableMaxPriceCalculator
6370
* @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
6471
*/
6572
public function __construct(
@@ -68,12 +75,14 @@ public function __construct(
6875
\Magento\Framework\Pricing\Adjustment\CalculatorInterface $calculator,
6976
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
7077
PriceResolverInterface $priceResolver,
78+
ConfigurableMaxPriceCalculator $configurableMaxPriceCalculator,
7179
?LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider = null
7280
) {
7381
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
7482
$this->priceResolver = $priceResolver;
7583
$this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider ?:
7684
ObjectManager::getInstance()->get(LowestPriceOptionsProviderInterface::class);
85+
$this->configurableMaxPriceCalculator = $configurableMaxPriceCalculator;
7786
}
7887

7988
/**
@@ -187,28 +196,26 @@ public function _resetState(): void
187196
}
188197

189198
/**
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
191200
*
192201
* @param SaleableInterface $product
193202
* @return bool
194203
*/
195204
public function isChildProductsOfEqualPrices(SaleableInterface $product): bool
196205
{
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;
201211
}
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();
206218
}
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;
213220
}
214221
}

app/code/Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ public function asHtml()
156156
public function validate(AbstractModel $model)
157157
{
158158
$subSelectConditionsFlag = true;
159+
if (!$this->getConditions()) {
160+
return false;
161+
}
159162
$attr = $this->getAttribute();
160163
$total = 0;
161164
$isMultiShipping = (bool) $model->getQuote()->getIsMultiShipping();

app/code/Magento/SalesRule/Test/Unit/Model/Rule/Condition/Product/SubselectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public static function dataProviderForFixedBundleProduct(): array
412412
'baseRowTotal' => 100,
413413
'valueParsed' => 100
414414
],
415-
true,
415+
false,
416416
false
417417
],
418418
'validate true for bundle product

0 commit comments

Comments
 (0)