0
votes

In magento, all products from a child-category is being displayed on top/parent categories. For example, i have this set of categories:

Fabric
- Cotton
---- Shirts (1)
--------Half Sleeves (5)

So in total i have 6 products, and when i click on fabric, it shows all 6 products along with sub-categories.

I don't want this, i want to only list categories and don't want to pull products from child-categories.

So, i want a method or way that can list only child-categories when i click Fabric. And only list 5 products when i click half-sleeves.

Btw, all of my categories are already set to Is Anchor = NO.

Here is the snippet from app/design/frontend/base/default/template/catalog/category/view.phtml

$_cat = new Mage_Catalog_Block_Navigation();
$curent_cat = $_cat->getCurrentCategory();
$curent_cat_id = $curent_cat->getId();
$parentId=Mage::getModel('catalog/category')->load($curent_cat_id)->getParentId();

$categoryid = $parentId;//$_category->getId();

$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');


$i=0; 
foreach ($collection as $_product) {........}

Any ideas?

Many Thanks!

2

2 Answers

2
votes

hello Aamir Siddique try this function to get child every time, so when click on fabrics you have to pass id of fabrics to this function to get it's child category, here i am giving function so you can get children array,

function get_child($category_id)
{
    $id=$category_id;
    $i=0;
    $children = Mage::getModel('catalog/category')->getCategories($id);
    foreach ($children as $category)
    {
    $data["cat_data"][$i]["id"]=$category->getId();
    $data["cat_data"][$i]["name"]=$category->getName();
    $i++;
    }
    return $data;
}
0
votes

Did you try change Display Mode of Fabric category to Static block only, then create a static block in which contains link to child categories?