Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit ef4b6ef

Browse files
author
Stanislav Idolov
authored
ENGCOM-2352: [Forwardport] Fix zero price simple failed to resolve as default #16817
2 parents ae65624 + 456257c commit ef4b6ef

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $produ
6464

6565
foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
6666
$productPrice = $this->priceResolver->resolvePrice($subProduct);
67-
$price = $price ? min($price, $productPrice) : $productPrice;
67+
$price = isset($price) ? min($price, $productPrice) : $productPrice;
6868
}
6969

7070
return (float)$price;

app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/ConfigurablePriceResolverTest.php

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,31 @@ protected function setUp()
5555
* situation: one product is supplying the price, which could be a price of zero (0)
5656
*
5757
* @dataProvider resolvePriceDataProvider
58+
*
59+
* @param $variantPrices
60+
* @param $expectedPrice
5861
*/
59-
public function testResolvePrice($expectedValue)
62+
public function testResolvePrice($variantPrices, $expectedPrice)
6063
{
61-
$price = $expectedValue;
62-
6364
$product = $this->getMockBuilder(
6465
\Magento\Catalog\Model\Product::class
6566
)->disableOriginalConstructor()->getMock();
6667

6768
$product->expects($this->never())->method('getSku');
6869

69-
$this->lowestPriceOptionsProvider->expects($this->once())->method('getProducts')->willReturn([$product]);
70-
$this->priceResolver->expects($this->once())
70+
$products = array_map(function () {
71+
return $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
72+
->disableOriginalConstructor()
73+
->getMock();
74+
}, $variantPrices);
75+
76+
$this->lowestPriceOptionsProvider->expects($this->once())->method('getProducts')->willReturn($products);
77+
$this->priceResolver
7178
->method('resolvePrice')
72-
->with($product)
73-
->willReturn($price);
79+
->willReturnOnConsecutiveCalls(...$variantPrices);
7480

75-
$this->assertEquals($expectedValue, $this->resolver->resolvePrice($product));
81+
$actualPrice = $this->resolver->resolvePrice($product);
82+
self::assertSame($expectedPrice, $actualPrice);
7683
}
7784

7885
/**
@@ -81,8 +88,40 @@ public function testResolvePrice($expectedValue)
8188
public function resolvePriceDataProvider()
8289
{
8390
return [
84-
'price of zero' => [0.00],
85-
'price of five' => [5],
91+
'Single variant at price 0.00 (float), should return 0.00 (float)' => [
92+
$variantPrices = [
93+
0.00,
94+
],
95+
$expectedPrice = 0.00,
96+
],
97+
'Single variant at price 5 (integer), should return 5.00 (float)' => [
98+
$variantPrices = [
99+
5,
100+
],
101+
$expectedPrice = 5.00,
102+
],
103+
'Single variants at price null (null), should return 0.00 (float)' => [
104+
$variantPrices = [
105+
null,
106+
],
107+
$expectedPrice = 0.00,
108+
],
109+
'Multiple variants at price 0, 10, 20, should return 0.00 (float)' => [
110+
$variantPrices = [
111+
0,
112+
10,
113+
20,
114+
],
115+
$expectedPrice = 0.00,
116+
],
117+
'Multiple variants at price 10, 0, 20, should return 0.00 (float)' => [
118+
$variantPrices = [
119+
10,
120+
0,
121+
20,
122+
],
123+
$expectedPrice = 0.00,
124+
],
86125
];
87126
}
88127
}

0 commit comments

Comments
 (0)