Skip to content

Commit 169ae34

Browse files
committed
MAGE-1245 Refactor plugin
1 parent 42d5e70 commit 169ae34

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

Plugin/RenderingCacheContextPlugin.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,11 @@ class RenderingCacheContextPlugin
2020
public const RENDERING_WITH_BACKEND = 'with_backend';
2121
public const RENDERING_WITHOUT_BACKEND = 'without_backend';
2222

23-
private $configHelper;
24-
private $storeManager;
25-
private $request;
26-
2723
public function __construct(
28-
ConfigHelper $configHelper,
29-
StoreManagerInterface $storeManager,
30-
Http $request
31-
) {
32-
$this->configHelper = $configHelper;
33-
$this->storeManager = $storeManager;
34-
$this->request = $request;
35-
}
24+
protected ConfigHelper $configHelper,
25+
protected StoreManagerInterface $storeManager,
26+
protected Http $request
27+
) { }
3628

3729
/**
3830
* Add a rendering context to the vary string to distinguish how which versions of the category PLP should be cached
@@ -45,8 +37,7 @@ public function __construct(
4537
* @throws NoSuchEntityException
4638
*/
4739
public function beforeGetVaryString(HttpContext $subject): array {
48-
$storeId = $this->storeManager->getStore()->getId();
49-
if ($this->request->getControllerName() != 'category' || !$this->configHelper->replaceCategories($storeId)) {
40+
if (!$this->applyCacheContext()) {
5041
return [];
5142
}
5243

@@ -62,4 +53,14 @@ public function beforeGetVaryString(HttpContext $subject): array {
6253

6354
return [];
6455
}
56+
57+
/**
58+
* @return bool
59+
* @throws NoSuchEntityException
60+
*/
61+
protected function applyCacheContext(): bool
62+
{
63+
$storeId = $this->storeManager->getStore()->getId();
64+
return $this->request->getControllerName() == 'category' && $this->configHelper->replaceCategories($storeId);
65+
}
6566
}

Test/Integration/Category/CategoryCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CategoryCacheTest extends \Magento\TestFramework\TestCase\AbstractControll
1717
public static function getCategoryProvider(): array
1818
{
1919
return [
20-
['categoryId' => 20, 'name' => 'Women'],
20+
['categoryId' => 20, 'name' => 'Women'], // not a category controller
2121
['categoryId' => 21, 'name' => 'Women > Tops'],
2222
];
2323
}

0 commit comments

Comments
 (0)