2

I added an extra category but i don't want to show this in the breadcrumb.

I searched for a while how i can remove a part from it and found the following solution:

In app/code/local/Mage/Page/Block/Html/Breadcrumbs.php I added the following code:

function removeCrumb($crumbName) {
    if ((!isset($this->_crumbs[$crumbName])) || (!$this->_crumbs[$crumbName]['readonly'])) {
    unset($this->_crumbs[$crumbName]);
}
    return $this;
}

Then ,i added the following code in app/code/local/Mage/Catalog/Block/Product/View.php after

$this->getLayout()->createBlock(‘catalog/breadcrumbs’);

$this->getLayout()->getBlock('breadcrumbs')->removeCrumb('home');

Instead of 'home' I can use the word category + the id of the category to remove this part from the breadcrumbs.

This all works fine, but unfortunately only on the product page. When I try to do the same in app/code/local/Mage/Catalog/Block/Category/View.php something strange happens:

instead of 'home - cat1 - cat2' it becomes 'home - cat2 - cat1'.

No idea why.

Does someone knows how to solve this problem for the category page?

I'm using magento 1.7.0.2

1 Answer 1

1

It would be wiser to rewrite the Mage_Catalog_Helper_Data, as it provides the data on what categories will be added to breadcrumbs.

Assuming you know how to rewrite that helper class, here's what you have to do:

  1. Rewrite the class Mage_Catalog_Helper_Data.
  2. Override getBreadcrumbPath method.
  3. Copy the original method but modify these lines:

    // add category path breadcrumb
    foreach ($pathIds as $categoryId) {
        if (isset($categories[$categoryId]) && 
            $categories[$categoryId]->getName() &&
            $categoryId != $YOUR_CATEGORY_ID // Notice the extra category check here...
        ) {
            $path['category'.$categoryId] = array(
                'label' => $categories[$categoryId]->getName(),
                'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : ''
            );
        }
    }
    

Replace $YOUR_CATEGORY_ID variable or set a value for it.

EDIT:

In case you don't know how to do a class rewrite

  1. Open the file Mage_Catalog_Helper_Data.
  2. Find the method getBreadcrumbPath. It starts with something like public function getBreadcrumbPath()
  3. Replace the whole method with this code:

    public function getBreadcrumbPath()
    {
        if (!$this->_categoryPath) {
    
            $path = array();
            if ($category = $this->getCategory()) {
                $pathInStore = $category->getPathInStore();
                $pathIds = array_reverse(explode(',', $pathInStore));
    
                $categories = $category->getParentCategories();
    
                !$category_ids_to_remove = array(YOUR_CATEGORY_ID_1, YOUR_CATEGORY_ID_2);
                // add category path breadcrumb
                foreach ($pathIds as $categoryId) {
                    if (isset($categories[$categoryId]) && 
                        $categories[$categoryId]->getName() &&
                        !in_array($categoryId, $category_ids_to_remove) // Notice the extra category check here...
                    ) {
                        $path['category'.$categoryId] = array(
                            'label' => $categories[$categoryId]->getName(),
                            'link' => $this->_isCategoryLink($categoryId) ? $categories[$categoryId]->getUrl() : ''
                        );
                    }
                }
            }
    
            if ($this->getProduct()) {
                $path['product'] = array('label'=>$this->getProduct()->getName());
            }
    
            $this->_categoryPath = $path;
        }
        return $this->_categoryPath;
    }
    

Replace the text YOUR_CATEGORY_ID to the actual category ID of the category you want to hide. It should work after that.

Please take note that rewrite core classes is extremely not recommended as core files are replaced whenever you update your magento.

7
  • I would suggest creating an observer on Mage_Catalog_Block_Breadcrumbs::_preapareLayout() might be more adventageous so you don't have to rewrite the block. Jun 25, 2015 at 15:55
  • But then in the head block, the title would contain the category that he does not want to display. It would be better to prevent it to be added in breadcrumb instead of removing it after. Jun 25, 2015 at 16:01
  • @DouglasRadburn Thanks for the suggestion, by the way. Just to be clear, I'm suggesting that he would rewrite a helper, not a block. Jun 25, 2015 at 16:02
  • To be honest; I have no idea how to do all this. I followed other instructions I found and came this far, but now I'm stuck.
    – Lucky
    Jun 25, 2015 at 16:32
  • I updated my answer hoping that it would help you... Magento might be too much for you to handle at your stage. Jun 25, 2015 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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