Skip to content

Commit 3e3cb84

Browse files
authored
ENGCOM-3722: Re-enable PriceBox block caching #19897
2 parents ded3799 + 2b7e4ec commit 3e3cb84

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

app/code/Magento/Msrp/Pricing/Price/MsrpPrice.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public function canApplyMsrp(Product $product)
9393
}
9494

9595
/**
96+
* Check if is minimal price is less than the msrp.
97+
*
9698
* @param Product $product
9799
* @return bool|float
98100
*/

app/code/Magento/Msrp/Pricing/Render/PriceBox.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,16 @@ public function getMsrpPriceCalculator(): MsrpPriceCalculatorInterface
5959
{
6060
return $this->msrpPriceCalculator;
6161
}
62+
63+
/**
64+
* @inheritDoc
65+
*/
66+
public function getCacheKey()
67+
{
68+
return sprintf(
69+
'%s-%s',
70+
parent::getCacheKey(),
71+
$this->getZone()
72+
);
73+
}
6274
}

lib/internal/Magento/Framework/Pricing/Render/PriceBox.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
use Magento\Framework\DataObject\IdentityInterface;
1010
use Magento\Framework\Pricing\Amount\AmountInterface;
11-
use Magento\Framework\Pricing\SaleableInterface;
1211
use Magento\Framework\Pricing\Price\PriceInterface;
12+
use Magento\Framework\Pricing\SaleableInterface;
1313
use Magento\Framework\View\Element\Template;
1414

1515
/**
@@ -21,7 +21,7 @@
2121
class PriceBox extends Template implements PriceBoxRenderInterface, IdentityInterface
2222
{
2323
/** Default block lifetime */
24-
const DEFAULT_LIFETIME = 3600;
24+
const DEFAULT_LIFETIME = 86400;
2525

2626
/**
2727
* @var SaleableInterface
@@ -39,11 +39,11 @@ class PriceBox extends Template implements PriceBoxRenderInterface, IdentityInte
3939
protected $rendererPool;
4040

4141
/**
42-
* @param Template\Context $context
42+
* @param Template\Context $context
4343
* @param SaleableInterface $saleableItem
44-
* @param PriceInterface $price
45-
* @param RendererPool $rendererPool
46-
* @param array $data
44+
* @param PriceInterface $price
45+
* @param RendererPool $rendererPool
46+
* @param array $data
4747
*/
4848
public function __construct(
4949
Template\Context $context,
@@ -59,7 +59,7 @@ public function __construct(
5959
}
6060

6161
/**
62-
* @return string
62+
* @inheritdoc
6363
*/
6464
protected function _toHtml()
6565
{
@@ -70,35 +70,31 @@ protected function _toHtml()
7070
}
7171

7272
/**
73-
* Get Key for caching block content
74-
*
75-
* @return string
73+
* @inheritdoc
7674
*/
7775
public function getCacheKey()
7876
{
7977
return parent::getCacheKey() . '-' . $this->getPriceId() . '-' . $this->getPrice()->getPriceCode();
8078
}
8179

8280
/**
83-
* Get block cache life time
84-
*
85-
* @return int
81+
* @inheritdoc
8682
*/
8783
protected function getCacheLifetime()
8884
{
89-
return parent::hasCacheLifetime() ? parent::getCacheLifetime() : null;
85+
return parent::hasCacheLifetime() ? parent::getCacheLifetime() : self::DEFAULT_LIFETIME;
9086
}
91-
87+
9288
/**
93-
* @return SaleableInterface
89+
* @inheritdoc
9490
*/
9591
public function getSaleableItem()
9692
{
9793
return $this->saleableItem;
9894
}
9995

10096
/**
101-
* @return PriceInterface
97+
* @inheritdoc
10298
*/
10399
public function getPrice()
104100
{
@@ -136,9 +132,7 @@ public function getPriceType($priceCode)
136132
}
137133

138134
/**
139-
* @param AmountInterface $amount
140-
* @param array $arguments
141-
* @return string
135+
* @inheritdoc
142136
*/
143137
public function renderAmount(AmountInterface $amount, array $arguments = [])
144138
{
@@ -149,6 +143,8 @@ public function renderAmount(AmountInterface $amount, array $arguments = [])
149143
}
150144

151145
/**
146+
* Get amount render.
147+
*
152148
* @param AmountInterface $amount
153149
* @param array $arguments
154150
* @return AmountRenderInterface
@@ -164,6 +160,8 @@ protected function getAmountRender(AmountInterface $amount, array $arguments = [
164160
}
165161

166162
/**
163+
* Get renderer pool.
164+
*
167165
* @return RendererPool
168166
*/
169167
public function getRendererPool()
@@ -172,9 +170,7 @@ public function getRendererPool()
172170
}
173171

174172
/**
175-
* Return unique ID(s) for each object in system
176-
*
177-
* @return array
173+
* @inheritdoc
178174
*/
179175
public function getIdentities()
180176
{

lib/internal/Magento/Framework/Pricing/Test/Unit/Render/PriceBoxTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,4 @@ public function testGetRendererPool()
248248
{
249249
$this->assertEquals($this->rendererPool, $this->model->getRendererPool());
250250
}
251-
252-
/**
253-
* This tests ensures that protected method getCacheLifetime() returns a null value when cacheLifeTime is not
254-
* explicitly set in the parent block
255-
*/
256-
public function testCacheLifetime()
257-
{
258-
$reflectionClass = new \ReflectionClass(get_class($this->model));
259-
$methodReflection = $reflectionClass->getMethod('getCacheLifetime');
260-
$methodReflection->setAccessible(true);
261-
$cacheLifeTime = $methodReflection->invoke($this->model);
262-
$this->assertNull($cacheLifeTime, 'Expected null cache lifetime');
263-
}
264251
}

0 commit comments

Comments
 (0)