Skip to content

Instantly share code, notes, and snippets.

@werring
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save werring/3237b20eeae60d818f13 to your computer and use it in GitHub Desktop.

Select an option

Save werring/3237b20eeae60d818f13 to your computer and use it in GitHub Desktop.
<?php
require_once 'app/Mage.php';
/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
$app = Mage::app();
printf("Current ID: %d<br/>",$app->getStore()->getRootCategoryId());
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addStoreFilter();
$i=0;
for($i=1;$i<20;$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));
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
printf("%s (%d)=>%s<br/>",$category->getName(),$i,$collection->count());
}
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment