2

I'm trying to get the shop by filters to display a new section called category. I managed to edit template/category/layer/view.phtml to get it to display the category section but the subcategories display all the options including subcategories, subsubcategories, and so on. I only want to display the categories that are one level higher than the main category. Sort of what it looks like in a dropdown navigation menu. I've also tried several coding strategies inside template/category/layer/filter.phtml. I've gotten close but managed to mess up the main navigation in the process.

The category filter needs to work for all product selections from the main menu, so I don't want to modify all 1800 products to add a field that contains the parent category. I've gotten so close to getting it to work but I have problems using getLevel, and getID on certain variables.

  • Have any of the proposed solutions worked for you? – Amasty Jul 30 '14 at 21:37
  • Figured it out! It involves modifying template catalog layer view.phtml – DraganAscii Jul 30 '14 at 22:05
  • I figured out the problem on my own, so none of the proposed solutions in this forum worked for me. But thanks for the help everybody! – Brian Aug 2 '14 at 15:47
1

Categories in layered navigation do not work like attributes and are not 'filterable' - and as such we usually recommend setting up a dropdown or multiselect attribute type to apply to products so that you can provide filtering of this level.

It's not "sexy" and it's not a code-based solution, but it gets the job done.

|improve this answer|||||
1

Unless you have some layered navigation extension that does the job for you, you can rewrite the categories filter model Mage_Catalog_Model_Layer_Filter_Category, not the template to show parent category and subcategories.

And then modify the method like

protected function _getItemsData()
{
    if ('catalogsearch' == Mage::app()->getRequest()->getModuleName()) {
        $items = parent::_getItemsData();

    }


    $currentCategory = $this->getCategory();

    $root = Mage::getModel('catalog/category')
            ->load($this->getLayer()->getCurrentStore()->getRootCategoryId()) ;

    $categories = $isStatic2LevelTree ? $root->getChildrenCategories() : $currentCategory->getChildrenCategories();


    if ($isStatic2LevelTree)
        $this->getLayer()->setCurrentCategory($root);

    $this->getLayer()->getProductCollection()
        ->addCountToCategories($categories);


    $data = array(); 
    ....
    ....
    //TODO add your logic here
|improve this answer|||||
0

Brian, First of all....Magento Layernation only show it subcategory.It did not provide show current category parent category...

Show if you...

current category  parent category then follow below.But it not provide product count on basic of current category product Collection
$parentId = Mage::registry('current_category')->getParentCategory()->getId();
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.