Return to Snippet

Revision: 63309
at April 24, 2013 06:11 by tomle123


Initial Code
//get the current category
$_currentCategory = Mage::getModel('catalog/category')->load(Mage::registry('current_category')->getId());

//spit out the collection filtered by store then by category
$_productCollection = Mage::getResourceModel('catalog/product_collection')
    ->addStoreFilter()
    ->addCategoryFilter($_currentCategory);

//get all categories
$categories = Mage::getModel('catalog/category')->load($parent_category_id)->getAllChildren();

foreach ($categories as $_category)
{
    $cur_category = Mage::getModel(���¢�¯�¿�½�¯�¿�½catalog/category���¢�¯�¿�½�¯�¿�½)->load($_category->getId());
    //get all products associated with the current category
    $products = Mage::getResourceModel(���¢�¯�¿�½�¯�¿�½catalog/product_collection���¢�¯�¿�½�¯�¿�½)
        ->addCategoryFilter($_category)
        ->addAttributeToSelect(���¢�¯�¿�½�¯�¿�½some_attributes���¢�¯�¿�½�¯�¿�½);
    foreach ( $products as $productModel )
    {
            $_product = Mage::getModel(���¢�¯�¿�½�¯�¿�½catalog/product���¢�¯�¿�½�¯�¿�½)->load($productModel->getId());
        //do something useful with this $_product object
        //$_product->getName(), $_product->getId() etc.
    }

}

Initial URL


Initial Description
filter out by category ID in Magento

Initial Title
filter out by category

Initial Tags
category, filter, magento

Initial Language
PHP