Skip to content

Instantly share code, notes, and snippets.

@werring
Created January 6, 2015 09:02
Show Gist options
  • Select an option

  • Save werring/1508b80ac3e7df83596d to your computer and use it in GitHub Desktop.

Select an option

Save werring/1508b80ac3e7df83596d to your computer and use it in GitHub Desktop.
Magento Category Collection
<?php
/**
* @author T. Werring [email protected]
* @project MagentoVPS
* @created 30/12/14 16:57
*/
require_once 'app/Mage.php';
/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
$app = Mage::app();
for($i=3;$i<=4;$i++){
$category = Mage::getModel('catalog/category')->load($i);
if($category->getLevel() > 1) continue;
$collection = Mage::getResourceModel('catalog/product_collection')
->setStoreId($app->getStore()->getId())
->addCategoryFilter($category)->addAttributeToFilter('status', array('eq' => 1));
printf("%s (%d)=>%s<br/>",$category->getName(),$i,$collection->count());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment