magento get category list according to store_id

magento get category list according to store_id

In this post we will show you magento get category list according to store id, hear for magento get category list according to store id we will give you demo and example for implement.

code for get category list according to store_id

<?php

$store_id = 1;
$get_store_categories_result = array();
$total_menu = $total_cat = 0;
try {
$get_store_root_category_id = Mage::app()->getStore($store_id)->getRootCategoryId();
$get_store_category_collection = Mage::getModel('catalog/category')->load($get_store_root_category_id);
$get_store_categories = $get_store_category_collection->getCollection()
->addAttributeToSelect(array('name', 'image', 'description','store'))
->addIdFilter($get_store_category_collection->getChildren());
foreach($get_store_categories as $current_category_val)
{
$get_store_categories_result["categories"][$total_cat] = array(
"id" => $current_category_val->getId(),
"name" => $current_category_val->getName(),
"image" => Mage::getModel('catalog/category')->load($current_category_val->getId())->getImageUrl(),
"caturl" => $current_category_val->getUrl()
);
$total_cat = $total_cat + 1;
}
$get_store_categories_result["total"] = $total_cat;
}
catch(Exception $exception) {
}
$total_menu =  $get_store_categories_result['total'];
/*
// display all category root
echo "<pre>";
print_r($get_store_categories_result);
echo "</pre>"; */
?>

<div class="container">
<h2>magento get category list according to store_id</h2>
<ul class="submainnav submega-nav">
<?php
if($total_menu  > 0)
{
foreach ($get_store_categories_result['categories'] as $key => $value)
{
?>
<li class="submainnavli">
<a class="submenu-link" href="<?php echo  $value['caturl']; ?>" id="submenus<?php echo $key; ?>">
<span class="submenu-title"><?php echo  $value['name']; ?></span>
</a>
</li>
<?php
}
}
else
{
?>
<li class="submainnavli">No Categories Found</li>
<?php
}
?>
</ul>
</div>

Hope this code and post will helped you for implement magento get category list according to store_id. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

7  +  2  =  

We accept paid advance and paid guest Posting on our Site : Contact US