Tuesday 14 May 2013

Get Top Parent category id from sub-child category in magento

// Get Parent Category Id

<?php
$_cat = new Mage_Catalog_Block_Navigation();
$curent_cat = $_cat->getCurrentCategory();
$curent_cat_id = $curent_cat->getId();?>


<?php $parentId=Mage::getModel('catalog/category')->load($curent_cat_id)->getParentId();
echo $parentId; // $parentId will print your current category's parent Id
?>




   // Get Top Parent Category Id

    $_cat = new Mage_Catalog_Block_Navigation();
    $curent_cat = $_cat->getCurrentCategory();  // Get Current Category
    $category_ids = $_cat->getCurrentCategory()->getParentCategory()->getPath(); 
    // Get Parent Category detail
    $cat_id = explode('/',$category_ids);   
    $top_parent_id = $cat_id[2];     // Get Parent Category Id
    echo  $top_parent_id; // $top_parent_id will print your current category's top parent Id.

   Suppose you click on Submenu 2.2.3 page and you want to find Top parent category id (Get Category Id)

No comments:

Post a Comment

Thanks for visit blog.