Skip to content

Commit c0d8ef7

Browse files
author
Mike Weis
committed
MAGETWO-36325: Catalog Prices on Frontend do not include the cost of required Custom Option
- fixed
1 parent 26be84a commit c0d8ef7

File tree

2 files changed

+78
-19
lines changed

2 files changed

+78
-19
lines changed

app/code/Magento/Bundle/Pricing/Render/FinalPriceBox.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,33 @@
88

99
use Magento\Bundle\Pricing\Price;
1010
use Magento\Catalog\Pricing\Render as CatalogRender;
11+
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
1112

1213
/**
1314
* Class for final_price rendering
1415
*/
1516
class FinalPriceBox extends CatalogRender\FinalPriceBox
1617
{
1718
/**
18-
* Check if bundle product has one more custom option with different prices
19+
* Check if bundle product has one or more options, or custom options, with different prices
1920
*
2021
* @return bool
2122
*/
2223
public function showRangePrice()
2324
{
24-
/** @var Price\BundleOptionPrice $optionPrice */
25-
$optionPrice = $this->getPriceType(Price\BundleOptionPrice::PRICE_CODE);
26-
return $optionPrice->getValue() !== $optionPrice->getMaxValue();
25+
//Check the bundle options
26+
/** @var Price\BundleOptionPrice $bundleOptionPrice */
27+
$bundleOptionPrice = $this->getPriceType(Price\BundleOptionPrice::PRICE_CODE);
28+
$showRange = $bundleOptionPrice->getValue() != $bundleOptionPrice->getMaxValue();
29+
30+
if (!$showRange) {
31+
//Check the custom options, if any
32+
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
33+
$customOptionPrice = $this->getPriceType(CustomOptionPrice::PRICE_CODE);
34+
$showRange =
35+
$customOptionPrice->getCustomOptionRange(true) != $customOptionPrice->getCustomOptionRange(false);
36+
}
37+
38+
return $showRange;
2739
}
2840
}

app/code/Magento/Bundle/Test/Unit/Pricing/Render/FinalPriceBoxTest.php

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66
namespace Magento\Bundle\Test\Unit\Pricing\Render;
77

8-
use \Magento\Bundle\Pricing\Render\FinalPriceBox;
9-
8+
use Magento\Bundle\Pricing\Render\FinalPriceBox;
109
use Magento\Bundle\Pricing\Price;
10+
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
1111

1212
class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
1313
{
@@ -34,31 +34,50 @@ public function setUp()
3434
/**
3535
* @dataProvider showRangePriceDataProvider
3636
*/
37-
public function testShowRangePrice($value, $maxValue, $result)
37+
public function testShowRangePrice($optMinValue, $optMaxValue, $custMinValue, $custMaxValue, $expectedShowRange)
3838
{
39+
$enableCustomOptionMocks = ($optMinValue == $optMaxValue);
40+
3941
$priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false);
40-
$optionPrice = $this->getMockBuilder('Magento\Bundle\Pricing\Price\BundleOptionPrice')
42+
$bundleOptionPrice = $this->getMockBuilder('Magento\Bundle\Pricing\Price\BundleOptionPrice')
43+
->disableOriginalConstructor()
44+
->getMock();
45+
$customOptionPrice = $this->getMockBuilder('Magento\Catalog\Pricing\Price\CustomOptionPrice')
4146
->disableOriginalConstructor()
4247
->getMock();
4348

4449
$this->saleableItem->expects($this->atLeastOnce())
4550
->method('getPriceInfo')
4651
->will($this->returnValue($priceInfo));
4752

48-
$priceInfo->expects($this->atLeastOnce())
53+
$priceInfo->expects($this->at(0))
4954
->method('getPrice')
5055
->with(Price\BundleOptionPrice::PRICE_CODE)
51-
->will($this->returnValue($optionPrice));
56+
->will($this->returnValue($bundleOptionPrice));
57+
if ($enableCustomOptionMocks) {
58+
$priceInfo->expects($this->at(1))
59+
->method('getPrice')
60+
->with(CustomOptionPrice::PRICE_CODE)
61+
->will($this->returnValue($customOptionPrice));
62+
}
5263

53-
$optionPrice->expects($this->once())
64+
$bundleOptionPrice->expects($this->once())
5465
->method('getValue')
55-
->will($this->returnValue($value));
56-
57-
$optionPrice->expects($this->once())
66+
->will($this->returnValue($optMinValue));
67+
$bundleOptionPrice->expects($this->once())
5868
->method('getMaxValue')
59-
->will($this->returnValue($maxValue));
69+
->will($this->returnValue($optMaxValue));
6070

61-
$this->assertEquals($result, $this->model->showRangePrice());
71+
if ($enableCustomOptionMocks) {
72+
$customOptionPrice->expects($this->at(0))
73+
->method('getCustomOptionRange')
74+
->will($this->returnValue($custMinValue));
75+
$customOptionPrice->expects($this->at(1))
76+
->method('getCustomOptionRange')
77+
->will($this->returnValue($custMaxValue));
78+
}
79+
80+
$this->assertEquals($expectedShowRange, $this->model->showRangePrice());
6281
}
6382

6483
/**
@@ -67,9 +86,37 @@ public function testShowRangePrice($value, $maxValue, $result)
6786
public function showRangePriceDataProvider()
6887
{
6988
return [
70-
['value' => 40.2, 'maxValue' => 45., 'result' => true],
71-
['value' => false, 'maxValue' => false, 'result' => false],
72-
['value' => 45.0, 'maxValue' => 45., 'result' => false],
89+
'bundle options different, custom options noop' => [
90+
'optMinValue' => 40.2,
91+
'optMaxValue' => 45.,
92+
'custMinValue' => 0,
93+
'custMaxValue' => 0,
94+
'expectedShowRange' => true
95+
],
96+
97+
'bundle options same boolean, custom options same boolean' => [
98+
'optMinValue' => false,
99+
'optMaxValue' => false,
100+
'custMinValue' => false,
101+
'custMaxValue' => false,
102+
'expectedShowRange' => false
103+
],
104+
105+
'bundle options same numeric, custom options same' => [
106+
'optMinValue' => 45.0,
107+
'optMaxValue' => 45,
108+
'custMinValue' => 1.0,
109+
'custMaxValue' => 1,
110+
'expectedShowRange' => false
111+
],
112+
113+
'bundle options same numeric, custom options different' => [
114+
'optMinValue' => 45.0,
115+
'optMaxValue' => 45.,
116+
'custMinValue' => 0,
117+
'custMaxValue' => 1,
118+
'expectedShowRange' => true
119+
],
73120
];
74121
}
75122
}

0 commit comments

Comments
 (0)