cancel
Showing results for 
Search instead for 
Did you mean: 

category won't open of the subcategories are not included in menu

SOLVED

category won't open of the subcategories are not included in menu

Hi,

 

I have am showing the categories on my homepage, and they are displayed like this:category.JPG

 

 

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 menucategory2.JPG

 

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: category won't open of the subcategories are not included in menu

@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();
}
if issue solved,Click Kudos & Accept as Solution

View solution in original post

1 REPLY 1

Re: category won't open of the subcategories are not included in menu

@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();
}
if issue solved,Click Kudos & Accept as Solution