Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zero price simple failed to resolve as default #16540

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $produ

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

return (float)$price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,31 @@ protected function setUp()
* situation: one product is supplying the price, which could be a price of zero (0)
*
* @dataProvider resolvePriceDataProvider
*
* @param $variantPrices
* @param $expectedPrice
*/
public function testResolvePrice($expectedValue)
public function testResolvePrice($variantPrices, $expectedPrice)
{
$price = $expectedValue;

$product = $this->getMockBuilder(
\Magento\Catalog\Model\Product::class
)->disableOriginalConstructor()->getMock();

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

$this->lowestPriceOptionsProvider->expects($this->once())->method('getProducts')->willReturn([$product]);
$this->priceResolver->expects($this->once())
$products = array_map(function () {
return $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->getMock();
}, $variantPrices);

$this->lowestPriceOptionsProvider->expects($this->once())->method('getProducts')->willReturn($products);
$this->priceResolver
->method('resolvePrice')
->with($product)
->willReturn($price);
->willReturnOnConsecutiveCalls(...$variantPrices);

$this->assertEquals($expectedValue, $this->resolver->resolvePrice($product));
$actualPrice = $this->resolver->resolvePrice($product);
self::assertSame($expectedPrice, $actualPrice);
}

/**
Expand All @@ -81,8 +88,40 @@ public function testResolvePrice($expectedValue)
public function resolvePriceDataProvider()
{
return [
'price of zero' => [0.00],
'price of five' => [5],
'Single variant at price 0.00 (float), should return 0.00 (float)' => [
$variantPrices = [
0.00,
],
$expectedPrice = 0.00,
],
'Single variant at price 5 (integer), should return 5.00 (float)' => [
$variantPrices = [
5,
],
$expectedPrice = 5.00,
],
'Single variants at price null (null), should return 0.00 (float)' => [
$variantPrices = [
null,
],
$expectedPrice = 0.00,
],
'Multiple variants at price 0, 10, 20, should return 0.00 (float)' => [
$variantPrices = [
0,
10,
20,
],
$expectedPrice = 0.00,
],
'Multiple variants at price 10, 0, 20, should return 0.00 (float)' => [
$variantPrices = [
10,
0,
20,
],
$expectedPrice = 0.00,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @VladimirZaets I have refactored the unit test to be more meaningful as test cases. New test cases are added to reflect the bug. Does it make sense to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @torreytsui, yes, it is ok, thanks!

],
];
}
}