Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not include categories in menu which are not active in current storeview #114

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions Helper/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,29 @@ class Menu extends \Magento\Framework\App\Helper\AbstractHelper
protected $categoryCollectionFactory;

/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magefan\Blog\Model\Url $url
* @param \Magento\Framework\Registry $registry
* @param \Magefan\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;

/**
* Menu constructor.
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magefan\Blog\Model\Url $url
* @param \Magento\Framework\Registry $registry
* @param \Magefan\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magefan\Blog\Model\Url $url,
\Magento\Framework\Registry $registry,
\Magefan\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
\Magefan\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
$this->url = $url;
$this->registry = $registry;
$this->categoryCollectionFactory = $categoryCollectionFactory;
$this->_storeManager = $storeManager;
parent::__construct($context);
}

Expand Down Expand Up @@ -98,8 +107,14 @@ public function getBlogNode($menu = null, $tree = null)
? $this->getCurrentCategory()->getId()
: 0;

$storeId = $this->getStoreId();

foreach ($items as $item) {
$parentId = (int) $item->getParentId();

if(!$item->isVisibleOnStore($storeId)){
continue;
}

if (!isset($addedNodes[$parentId])) {
continue;
Expand Down Expand Up @@ -147,4 +162,14 @@ protected function getCurrentCategory()
{
return $this->registry->registry('current_blog_category');
}

/**
* Get store identifier
*
* @return int
*/
public function getStoreId()
{
return $this->_storeManager->getStore()->getId();
}
}