0

My categories and subcategories hierarchy to a product listing page :

  • Products
    • Refrigerator
      • back-bar fridges
        • Product listing(here)

Now, what i'm trying to get is while i'm in product listing page i want to get all the parent categories and subcategories with respective links.

I got answer from this question But, i failed to get all parent items (subcategories and subcategories)

$path = $category->getPath();          
What i get is : 0(root)/2(Magento root)/444(products)

And it escapes all the middle subcategories. In my case it escaped Refrigerator/backbar fridges

  • Are you looking for only all the parent and child categories of the given category where you product is listed? – musicliftsme Mar 8 '15 at 5:54
0

this will show like breadcrum.

I know this is quite old, but I'd like to share my solution anyway as it doesn't override/clone any core files.

In your custom module add the following to your config.xml:

<config>
    ...
    <frontend>
        <events>
            <catalog_controller_product_init>
                <observers>
                    <breadcrumb_categorypath_product_init>
                        <type>singleton</type>
                        <class><Your Namespace>_<Your Module>_Model_Observer</class>
                        <method>fullBreadcrumbCategoryPath</method>
                    </breadcrumb_categorypath_product_init>
                </observers>
            </catalog_controller_product_init>
        </events>
    </frontend>
</config>

Create an Observer.php in /app/code/local///Model/

Add the following to your Observer.php:

class <Your Namespace>_<Your Module>_Model_Observer {
    public function fullBreadcrumbCategoryPath(Varien_Event_Observer $observer) {
        $current_product = Mage::registry('current_product');

        if( $current_product ) {
            $categories = $current_product->getCategoryCollection()->addAttributeToSelect('name')->setPageSize(1);
            foreach( $categories as $category ) {
                Mage::unregister('current_category');
                Mage::register('current_category', $category);
            }
        }
    }

I hope this will help you.

0

Try this to get all active categories:

$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter();
0

May be this give help you a bit.

<?php 

$parentCategoryId = 222;
$cat = Mage::getModel('catalog/category')->load($parentCategoryId);
$subcats = $cat->getChildren();

// Get 1 Level sub category of Parent category
foreach(explode(',',$subcats) as $subCatid)
              {
                $_category = Mage::getModel('catalog/category')->load($subCatid);
  if($_category->getIsActive()) {
    echo '<li><a href="'.$_category->getURL().'" title="View the products for the "'.$_category->getName().'" category">'.$_category->getName().'</a><li>';

  }
}
*/
?>

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.