Skip to content

Commit 8fe831f

Browse files
wip
1 parent 02d1a1f commit 8fe831f

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Block/Menu.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function __construct(
9999
Context $httpContext,
100100
array $data = []
101101
) {
102+
$data['attached_node_type_caches'] = $data['attached_node_type_caches'] ?? ['category'];
102103
parent::__construct($context, $data);
103104
$this->menuRepository = $menuRepository;
104105
$this->nodeRepository = $nodeRepository;
@@ -119,11 +120,20 @@ public function __construct(
119120
*/
120121
public function getIdentities()
121122
{
122-
return [
123+
$tags = [
123124
\Snowdog\Menu\Model\Menu::CACHE_TAG . '_' . $this->loadMenu()->getId(),
124125
Block::CACHE_TAG,
125126
\Snowdog\Menu\Model\Menu::CACHE_TAG
126127
];
128+
if ($this->canGatherEntityCacheTags()) {
129+
foreach ($this->_data['attached_node_type_caches'] as $provider) {
130+
$nodeTypeEntityCacheTags = $this->nodeTypeProvider->getProvider($provider)->getEntityCacheTags();
131+
if (!empty($nodeTypeEntityCacheTags)) {
132+
$tags = array_merge($tags, $nodeTypeEntityCacheTags);
133+
}
134+
}
135+
}
136+
return $tags;
127137
}
128138

129139
protected function getCacheLifetime()
@@ -530,6 +540,11 @@ private function getSubmenuTemplate()
530540
return $this->getMenuTemplate($baseSubmenuTemplate);
531541
}
532542

543+
private function canGatherEntityCacheTags()
544+
{
545+
return !empty($this->_data['attached_node_type_caches']);
546+
}
547+
533548
public function getCustomerGroupId()
534549
{
535550
return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP);

Block/NodeType/Category.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class Category extends AbstractNode
4343
* @var array
4444
*/
4545
private $categories;
46+
/**
47+
* @var array
48+
*/
49+
private $cacheTags;
4650

4751
/**
4852
* @var array
@@ -112,7 +116,8 @@ public function fetchData(array $nodes)
112116
$this->nodes,
113117
$this->categoryUrls,
114118
$this->categories,
115-
$this->categoryProductCounts
119+
$this->categoryProductCounts,
120+
$this->cacheTags
116121
] = $this->_categoryModel->fetchData($nodes, $storeId);
117122

118123
}
@@ -226,4 +231,9 @@ public function getLabel()
226231
{
227232
return __("Category");
228233
}
234+
235+
public function getEntityCacheTags()
236+
{
237+
return $this->cacheTags;
238+
}
229239
}

Model/NodeType/Category.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Snowdog\Menu\Model\NodeType;
1212

1313
use Magento\Catalog\Api\Data\CategoryInterface;
14+
use Magento\Catalog\Model\Category as CategoryModel;
1415
use Magento\Framework\EntityManager\MetadataPool;
1516
use Magento\Framework\Profiler;
1617
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
@@ -123,10 +124,11 @@ public function fetchData(array $nodes, $storeId)
123124
$categoryUrls = $this->getResource()->fetchData($storeId, $categoryIds);
124125
$categories = $this->getCategories($storeId, $categoryIds);
125126
$categoryProductCounts = $this->getResource()->getCategoriesProductCount($categoryIds);
127+
$cacheTags = preg_filter('/^/', 'cat_c_p' . '_', $categoryIds);
126128

127129
$this->profiler->stop(__METHOD__);
128130

129-
return [$localNodes, $categoryUrls, $categories, $categoryProductCounts];
131+
return [$localNodes, $categoryUrls, $categories, $categoryProductCounts, $cacheTags];
130132
}
131133

132134
/**

0 commit comments

Comments
 (0)