Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwaclawczyk committed Dec 20, 2024
1 parent 02d1a1f commit 8fe831f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
17 changes: 16 additions & 1 deletion Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function __construct(
Context $httpContext,
array $data = []
) {
$data['attached_node_type_caches'] = $data['attached_node_type_caches'] ?? ['category'];
parent::__construct($context, $data);
$this->menuRepository = $menuRepository;
$this->nodeRepository = $nodeRepository;
Expand All @@ -119,11 +120,20 @@ public function __construct(
*/
public function getIdentities()
{
return [
$tags = [
\Snowdog\Menu\Model\Menu::CACHE_TAG . '_' . $this->loadMenu()->getId(),
Block::CACHE_TAG,
\Snowdog\Menu\Model\Menu::CACHE_TAG
];
if ($this->canGatherEntityCacheTags()) {
foreach ($this->_data['attached_node_type_caches'] as $provider) {
$nodeTypeEntityCacheTags = $this->nodeTypeProvider->getProvider($provider)->getEntityCacheTags();
if (!empty($nodeTypeEntityCacheTags)) {
$tags = array_merge($tags, $nodeTypeEntityCacheTags);
}
}
}
return $tags;
}

protected function getCacheLifetime()
Expand Down Expand Up @@ -530,6 +540,11 @@ private function getSubmenuTemplate()
return $this->getMenuTemplate($baseSubmenuTemplate);
}

private function canGatherEntityCacheTags()
{
return !empty($this->_data['attached_node_type_caches']);
}

public function getCustomerGroupId()
{
return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP);
Expand Down
12 changes: 11 additions & 1 deletion Block/NodeType/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class Category extends AbstractNode
* @var array
*/
private $categories;
/**
* @var array
*/
private $cacheTags;

/**
* @var array
Expand Down Expand Up @@ -112,7 +116,8 @@ public function fetchData(array $nodes)
$this->nodes,
$this->categoryUrls,
$this->categories,
$this->categoryProductCounts
$this->categoryProductCounts,
$this->cacheTags
] = $this->_categoryModel->fetchData($nodes, $storeId);

}
Expand Down Expand Up @@ -226,4 +231,9 @@ public function getLabel()
{
return __("Category");
}

public function getEntityCacheTags()
{
return $this->cacheTags;
}
}
4 changes: 3 additions & 1 deletion Model/NodeType/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Snowdog\Menu\Model\NodeType;

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

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

return [$localNodes, $categoryUrls, $categories, $categoryProductCounts];
return [$localNodes, $categoryUrls, $categories, $categoryProductCounts, $cacheTags];
}

/**
Expand Down

0 comments on commit 8fe831f

Please sign in to comment.