Skip to content

Commit 9f72fee

Browse files
committed
MC-18847: Special Price & Regular Price Display Issues on Configurable Product
1 parent 40f300f commit 9f72fee

File tree

3 files changed

+59
-79
lines changed

3 files changed

+59
-79
lines changed

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
namespace Magento\ConfigurableProduct\Pricing\Price;
88

99
use Magento\Catalog\Api\Data\ProductInterface;
10-
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
11-
use Magento\Framework\App\ResourceConnection;
1210
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
13-
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
14-
use Magento\Framework\App\RequestSafetyInterface;
1511

12+
/**
13+
* Provide configurable child products for price calculation
14+
*/
1615
class ConfigurableOptionsProvider implements ConfigurableOptionsProviderInterface
1716
{
1817
/**
19-
* @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable
18+
* @var Configurable
2019
*/
2120
private $configurable;
2221

@@ -27,24 +26,15 @@ class ConfigurableOptionsProvider implements ConfigurableOptionsProviderInterfac
2726

2827
/**
2928
* @param Configurable $configurable
30-
* @param ResourceConnection $resourceConnection
31-
* @param LinkedProductSelectBuilderInterface $linkedProductSelectBuilder
32-
* @param CollectionFactory $collectionFactory
33-
* @param RequestSafetyInterface $requestSafety
34-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3529
*/
3630
public function __construct(
37-
Configurable $configurable,
38-
ResourceConnection $resourceConnection,
39-
LinkedProductSelectBuilderInterface $linkedProductSelectBuilder,
40-
CollectionFactory $collectionFactory,
41-
RequestSafetyInterface $requestSafety
31+
Configurable $configurable
4232
) {
4333
$this->configurable = $configurable;
4434
}
4535

4636
/**
47-
* {@inheritdoc}
37+
* @inheritdoc
4838
*/
4939
public function getProducts(ProductInterface $product)
5040
{

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
1111
use Magento\Catalog\Pricing\Price\RegularPrice;
1212
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
13-
use Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProviderInterface;
14-
use Magento\Framework\App\ObjectManager;
1513
use Magento\Framework\Pricing\Price\PriceInterface;
1614
use Magento\Framework\Pricing\Render\RendererPool;
1715
use Magento\Framework\Pricing\SaleableInterface;
@@ -22,11 +20,6 @@
2220
*/
2321
class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
2422
{
25-
/**
26-
* @var LowestPriceOptionsProviderInterface
27-
*/
28-
private $lowestPriceOptionsProvider;
29-
3023
/**
3124
* @var ConfigurableOptionsProviderInterface
3225
*/
@@ -39,20 +32,18 @@ class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
3932
* @param RendererPool $rendererPool
4033
* @param ConfigurableOptionsProviderInterface $configurableOptionsProvider
4134
* @param array $data
42-
* @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
43-
* @param SalableResolverInterface|null $salableResolver
44-
* @param MinimalPriceCalculatorInterface|null $minimalPriceCalculator
35+
* @param SalableResolverInterface $salableResolver
36+
* @param MinimalPriceCalculatorInterface $minimalPriceCalculator
4537
*/
4638
public function __construct(
4739
Context $context,
4840
SaleableInterface $saleableItem,
4941
PriceInterface $price,
5042
RendererPool $rendererPool,
43+
SalableResolverInterface $salableResolver,
44+
MinimalPriceCalculatorInterface $minimalPriceCalculator,
5145
ConfigurableOptionsProviderInterface $configurableOptionsProvider,
52-
array $data = [],
53-
LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider = null,
54-
SalableResolverInterface $salableResolver = null,
55-
MinimalPriceCalculatorInterface $minimalPriceCalculator = null
46+
array $data = []
5647
) {
5748
parent::__construct(
5849
$context,
@@ -63,9 +54,8 @@ public function __construct(
6354
$salableResolver,
6455
$minimalPriceCalculator
6556
);
57+
6658
$this->configurableOptionsProvider = $configurableOptionsProvider;
67-
$this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider ?:
68-
ObjectManager::getInstance()->get(LowestPriceOptionsProviderInterface::class);
6959
}
7060

7161
/**

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

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,74 @@
55
*/
66
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Render;
77

8+
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
810
use Magento\Catalog\Pricing\Price\FinalPrice;
11+
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
912
use Magento\Catalog\Pricing\Price\RegularPrice;
10-
use Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProviderInterface;
13+
use Magento\ConfigurableProduct\Pricing\Price\ConfigurableOptionsProviderInterface;
1114
use Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox;
15+
use Magento\Framework\Pricing\Price\PriceInterface;
16+
use Magento\Framework\Pricing\PriceInfoInterface;
17+
use Magento\Framework\Pricing\Render\RendererPool;
1218
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19+
use Magento\Framework\View\Element\Template\Context;
20+
use PHPUnit\Framework\MockObject\MockObject;
1321

1422
class FinalPriceBoxTest extends \PHPUnit\Framework\TestCase
1523
{
1624
/**
17-
* @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
25+
* @var Context|MockObject
1826
*/
1927
private $context;
2028

2129
/**
22-
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
30+
* @var Product|MockObject
2331
*/
2432
private $saleableItem;
2533

2634
/**
27-
* @var \Magento\Framework\Pricing\Price\PriceInterface|\PHPUnit_Framework_MockObject_MockObject
35+
* @var PriceInterface|MockObject
2836
*/
2937
private $price;
3038

3139
/**
32-
* @var \Magento\Framework\Pricing\Render\RendererPool|\PHPUnit_Framework_MockObject_MockObject
40+
* @var RendererPool|MockObject
3341
*/
3442
private $rendererPool;
3543

3644
/**
37-
* @var LowestPriceOptionsProviderInterface|\PHPUnit_Framework_MockObject_MockObject
45+
* @var SalableResolverInterface|MockObject
3846
*/
39-
private $lowestPriceOptionsProvider;
47+
private $salableResolver;
48+
49+
/**
50+
* @var MinimalPriceCalculatorInterface|MockObject
51+
*/
52+
private $minimalPriceCalculator;
53+
54+
/**
55+
* @var ConfigurableOptionsProviderInterface|MockObject
56+
*/
57+
private $configurableOptionsProvider;
4058

4159
/**
4260
* @var FinalPriceBox
4361
*/
4462
private $model;
4563

64+
/**
65+
* @inheritDoc
66+
*/
4667
protected function setUp()
4768
{
48-
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
49-
->disableOriginalConstructor()
50-
->getMock();
51-
52-
$this->saleableItem = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
53-
->disableOriginalConstructor()
54-
->getMock();
55-
56-
$this->price = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
57-
->getMockForAbstractClass();
58-
59-
$this->rendererPool = $this->getMockBuilder(\Magento\Framework\Pricing\Render\RendererPool::class)
60-
->disableOriginalConstructor()
61-
->getMock();
62-
63-
$this->lowestPriceOptionsProvider = $this->getMockBuilder(LowestPriceOptionsProviderInterface::class)
64-
->getMockForAbstractClass();
69+
$this->context = $this->createMock(Context::class);
70+
$this->saleableItem = $this->createMock(Product::class);
71+
$this->price = $this->createMock(PriceInterface::class);
72+
$this->rendererPool = $this->createMock(RendererPool::class);
73+
$this->salableResolver = $this->createMock(SalableResolverInterface::class);
74+
$this->minimalPriceCalculator = $this->createMock(MinimalPriceCalculatorInterface::class);
75+
$this->configurableOptionsProvider = $this->createMock(ConfigurableOptionsProviderInterface::class);
6576

6677
$this->model = (new ObjectManager($this))->getObject(
6778
FinalPriceBox::class,
@@ -70,7 +81,9 @@ protected function setUp()
7081
'saleableItem' => $this->saleableItem,
7182
'price' => $this->price,
7283
'rendererPool' => $this->rendererPool,
73-
'lowestPriceOptionsProvider' => $this->lowestPriceOptionsProvider,
84+
'salableResolver' => $this->salableResolver,
85+
'minimalPriceCalculator' => $this->minimalPriceCalculator,
86+
'configurableOptionsProvider' => $this->configurableOptionsProvider,
7487
]
7588
);
7689
}
@@ -82,44 +95,31 @@ protected function setUp()
8295
* @dataProvider hasSpecialPriceDataProvider
8396
*/
8497
public function testHasSpecialPrice(
85-
$regularPrice,
86-
$finalPrice,
87-
$expected
98+
float $regularPrice,
99+
float $finalPrice,
100+
bool $expected
88101
) {
89-
$priceMockOne = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
90-
->getMockForAbstractClass();
91-
102+
$priceMockOne = $this->createMock(PriceInterface::class);
92103
$priceMockOne->expects($this->once())
93104
->method('getValue')
94105
->willReturn($regularPrice);
95-
96-
$priceMockTwo = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
97-
->getMockForAbstractClass();
98-
106+
$priceMockTwo = $this->createMock(PriceInterface::class);
99107
$priceMockTwo->expects($this->once())
100108
->method('getValue')
101109
->willReturn($finalPrice);
102-
103-
$priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class)
104-
->disableOriginalConstructor()
105-
->getMock();
106-
110+
$priceInfoMock = $this->createMock(PriceInfoInterface::class);
107111
$priceInfoMock->expects($this->exactly(2))
108112
->method('getPrice')
109113
->willReturnMap([
110114
[RegularPrice::PRICE_CODE, $priceMockOne],
111115
[FinalPrice::PRICE_CODE, $priceMockTwo],
112116
]);
113117

114-
$productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
115-
->setMethods(['getPriceInfo'])
116-
->getMockForAbstractClass();
117-
118+
$productMock = $this->createMock(Product::class);
118119
$productMock->expects($this->exactly(2))
119120
->method('getPriceInfo')
120121
->willReturn($priceInfoMock);
121-
122-
$this->lowestPriceOptionsProvider->expects($this->once())
122+
$this->configurableOptionsProvider->expects($this->once())
123123
->method('getProducts')
124124
->with($this->saleableItem)
125125
->willReturn([$productMock]);
@@ -130,7 +130,7 @@ public function testHasSpecialPrice(
130130
/**
131131
* @return array
132132
*/
133-
public function hasSpecialPriceDataProvider()
133+
public function hasSpecialPriceDataProvider(): array
134134
{
135135
return [
136136
[10., 20., false],

0 commit comments

Comments
 (0)