Reputation: 11
I have 5 stores in a magento website.
I want to list all the root categories of all the stores with their thumbnail images and link the thumbnail image to the store's home page.
for example:
WEBSITE:
store1 -> category1
store2 -> category2
store3 -> category3
I have already got the codes working but I am not being able to use addAttributeToFilter() so that I can list only those categories which are active. Currently the following code displays all the root categories whether ACTIVE or NOT.
<?php
$groups = $this->getGroups();
$cnt = count($groups);
?>
<?php if($cnt > 1): ?>
<div class="container">
<?php foreach ($groups as $_group): ?>
<?php
$storeId = $_group->getId();
$store_url = Mage::app()->getStore($storeId)->getHomeUrl();
$root_cat = Mage::app()->getStore($storeId)->getRootCategoryId();
$category_model = Mage::getModel('catalog/category')->load($root_cat); // here I used addAttributeToFilter() and gave me error
$_category = $category_model;
$_img_path = Mage::getBaseUrl('media').'catalog/category/';
$_no_of_columns = ($this->no_of_columns) ? $this->no_of_columns : 6;
?>
<?php if ($_i++ % $_no_of_columns == 0): ?>
<div class="row slide">
<?php endif; ?>
<?php if ($_imgUrl = $_category->getThumbnail()): ?>
<div class="span2">
<a href="<?php echo $store_url ?>" title="<?php echo $_category->getName(); ?>">
<img class="img-polaroid" src="<?php echo $_img_path.$_imgUrl; ?>" />
</a>
<h6>
<a href="<?php echo $store_url; ?>" title="<?php echo $_category->getName(); ?>">
<?php echo $_category->getName(); ?>
</a>
</h6>
</div>
<?php endif; ?>
<?php if ($_i % $_no_of_columns == 0 || $_i == $_cat_count): ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
Upvotes: 0
Views: 251
Reputation: 23205
Your code is using a category model, not a category collection. Models represent one entity and do not have any filters. By load()
ing the model you are applying all data to the instance, so you should be able to call $category_model->getIsActive()
to determine if the active flag is no (0) or yes (1).
Upvotes: 1