magento get categories using store id

magento get categories using store id

In this post we will show you magento get categories using store id, hear for magento get categories using store id we will give you demo and example for implement.

code for get categories using 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 categories by 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 categories using 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 *

  +  22  =  26

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