Skip to content

[Forwardport] Fix zero price simple failed to resolve as default #16817

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

Merged
merged 3 commits into from
Jul 18, 2018
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,
],
];
}
}