Skip to content

Commit cde02ad

Browse files
committed
MAGETWO-62229: There is no Price on product page when product is out of stock
1 parent 717ba2b commit cde02ad

File tree

4 files changed

+75
-21
lines changed

4 files changed

+75
-21
lines changed

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,15 @@ public function __construct(
5555
*/
5656
protected function _toHtml()
5757
{
58-
if (!$this->salableResolver->isSalable($this->getSaleableItem())) {
58+
// Check catalog permissions
59+
if ($this->getSaleableItem()->getCanShowPrice() === false) {
5960
return '';
6061
}
6162

6263
$result = parent::_toHtml();
6364

64-
try {
65-
/** @var MsrpPrice $msrpPriceType */
66-
$msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price');
67-
} catch (\InvalidArgumentException $e) {
68-
$this->_logger->critical($e);
69-
return $this->wrapResult($result);
70-
}
71-
7265
//Renders MSRP in case it is enabled
73-
$product = $this->getSaleableItem();
74-
if ($msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product)) {
66+
if ($this->isMsrpPriceApplicable()) {
7567
/** @var BasePriceBox $msrpBlock */
7668
$msrpBlock = $this->rendererPool->createPriceRender(
7769
MsrpPrice::PRICE_CODE,
@@ -87,6 +79,29 @@ protected function _toHtml()
8779
return $this->wrapResult($result);
8880
}
8981

82+
/**
83+
* Check is MSRP applicable for the current product.
84+
*
85+
* @return bool
86+
*/
87+
protected function isMsrpPriceApplicable()
88+
{
89+
try {
90+
/** @var MsrpPrice $msrpPriceType */
91+
$msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price');
92+
} catch (\InvalidArgumentException $e) {
93+
$this->_logger->critical($e);
94+
return false;
95+
}
96+
97+
if ($msrpPriceType === null) {
98+
return false;
99+
}
100+
101+
$product = $this->getSaleableItem();
102+
return $msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product);
103+
}
104+
90105
/**
91106
* Wrap with standard required container
92107
*

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ public function testRenderMsrpDisabled()
178178
->with($this->equalTo($this->product))
179179
->will($this->returnValue(false));
180180

181-
$this->salableResolverMock->expects($this->once())->method('isSalable')->with($this->product)->willReturn(true);
181+
$this->salableResolverMock->expects($this->any())
182+
->method('isSalable')
183+
->with($this->product)
184+
->willReturn(true);
182185

183186
$result = $this->object->toHtml();
184187

@@ -191,13 +194,14 @@ public function testRenderMsrpDisabled()
191194
public function testNotSalableItem()
192195
{
193196
$this->salableResolverMock
194-
->expects($this->once())
197+
->expects($this->any())
195198
->method('isSalable')
196199
->with($this->product)
197200
->willReturn(false);
201+
198202
$result = $this->object->toHtml();
199203

200-
$this->assertEmpty($result);
204+
$this->assertNotEmpty($result);
201205
}
202206

203207
public function testRenderMsrpEnabled()
@@ -234,7 +238,10 @@ public function testRenderMsrpEnabled()
234238
->with('msrp_price', $this->product, $arguments)
235239
->will($this->returnValue($priceBoxRender));
236240

237-
$this->salableResolverMock->expects($this->once())->method('isSalable')->with($this->product)->willReturn(true);
241+
$this->salableResolverMock->expects($this->any())
242+
->method('isSalable')
243+
->with($this->product)
244+
->willReturn(true);
238245

239246
$result = $this->object->toHtml();
240247

@@ -255,7 +262,10 @@ public function testRenderMsrpNotRegisteredException()
255262
->with($this->equalTo('msrp_price'))
256263
->will($this->throwException(new \InvalidArgumentException()));
257264

258-
$this->salableResolverMock->expects($this->once())->method('isSalable')->with($this->product)->willReturn(true);
265+
$this->salableResolverMock->expects($this->any())
266+
->method('isSalable')
267+
->with($this->product)
268+
->willReturn(true);
259269

260270
$result = $this->object->toHtml();
261271

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ public function testRenderMsrpDisabled()
178178
->with($this->equalTo($this->product))
179179
->will($this->returnValue(false));
180180

181-
$this->salableResolverMock->expects($this->once())->method('isSalable')->with($this->product)->willReturn(true);
181+
$this->salableResolverMock->expects($this->any())
182+
->method('isSalable')
183+
->with($this->product)
184+
->willReturn(true);
182185

183186
$result = $this->object->toHtml();
184187

@@ -191,13 +194,14 @@ public function testRenderMsrpDisabled()
191194
public function testNotSalableItem()
192195
{
193196
$this->salableResolverMock
194-
->expects($this->once())
197+
->expects($this->any())
195198
->method('isSalable')
196199
->with($this->product)
197200
->willReturn(false);
201+
198202
$result = $this->object->toHtml();
199203

200-
$this->assertEmpty($result);
204+
$this->assertNotEmpty($result);
201205
}
202206

203207
public function testRenderMsrpEnabled()
@@ -234,7 +238,10 @@ public function testRenderMsrpEnabled()
234238
->with('msrp_price', $this->product, $arguments)
235239
->will($this->returnValue($priceBoxRender));
236240

237-
$this->salableResolverMock->expects($this->once())->method('isSalable')->with($this->product)->willReturn(true);
241+
$this->salableResolverMock->expects($this->any())
242+
->method('isSalable')
243+
->with($this->product)
244+
->willReturn(true);
238245

239246
$result = $this->object->toHtml();
240247

@@ -255,7 +262,10 @@ public function testRenderMsrpNotRegisteredException()
255262
->with($this->equalTo('msrp_price'))
256263
->will($this->throwException(new \InvalidArgumentException()));
257264

258-
$this->salableResolverMock->expects($this->once())->method('isSalable')->with($this->product)->willReturn(true);
265+
$this->salableResolverMock->expects($this->any())
266+
->method('isSalable')
267+
->with($this->product)
268+
->willReturn(true);
259269

260270
$result = $this->object->toHtml();
261271

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/mtf/Magento/Mtf/TestRunner/etc/testRunner.xsd">
10+
<rule scope="testsuite">
11+
<allow>
12+
<class value="Magento\Bundle\Test\TestCase\CreateBundleProductEntityTest" />
13+
<class value="Magento\Catalog\Test\TestCase\Product\CreateSimpleProductEntityTest" />
14+
<class value="Magento\Catalog\Test\TestCase\Product\UpdateSimpleProductEntityTest" />
15+
<class value="Magento\Catalog\Test\TestCase\Product\CreateVirtualProductEntityTest" />
16+
<class value="Magento\Catalog\Test\TestCase\Product\UpdateVirtualProductEntityTest" />
17+
</allow>
18+
</rule>
19+
</config>

0 commit comments

Comments
 (0)