Hi,
I have am showing the categories on my homepage, and they are displayed like this:
Now as you can see when a category has sub-categories (marked with red circle) it will show a "[+]" and it will open the menu of the sub-categories when clicked.
Now my issue is this, I have instances when the sub-categories are hidden from menu
What I need to do, is that if the sub-categories are all hidden, instead of opening the menu and show the [+] sign, it will open the page with the products.
does any one know what variable I need to check for?
Solved! Go to Solution.
@robertbits - okay for that you need to get custom category collection in your block file and then you need to traverse into your template(.phtml) file.
Below is the logic to get the categories which have include_in_menu property is disabled :
protected $_categoryCollection; public function __construct( \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, $data = [] ) { $this->_categoryCollection = $categoryCollectionFactory; parent::__construct($data); } $categories = $this->_categoryCollection->create() ->addAttributeToFilter('include_in_menu', array('eq' => 0); //only categories not included in menu foreach ($categories as $category){ $category->getName(); }
@robertbits - okay for that you need to get custom category collection in your block file and then you need to traverse into your template(.phtml) file.
Below is the logic to get the categories which have include_in_menu property is disabled :
protected $_categoryCollection; public function __construct( \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, $data = [] ) { $this->_categoryCollection = $categoryCollectionFactory; parent::__construct($data); } $categories = $this->_categoryCollection->create() ->addAttributeToFilter('include_in_menu', array('eq' => 0); //only categories not included in menu foreach ($categories as $category){ $category->getName(); }