Last active
October 27, 2020 17:49
-
-
Save proxium/a8076222bd771d247d52 to your computer and use it in GitHub Desktop.
Product Count Per Category in Magento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param $category | |
* @return int | |
*/ | |
public function getProductCount($category) | |
{ | |
$productTable = Mage::getSingleton('core/resource')->getTableName('catalog/category_product'); | |
$select = $this->getReadConnection()->select() | |
->from( | |
array('main_table' => $productTable), | |
array(new Zend_Db_Expr('COUNT(main_table.product_id)')) | |
) | |
->where('main_table.category_id = :category_id'); | |
$bind = array('category_id' => (int)$category->getId()); | |
$counts = $this->getReadConnection()->fetchOne($select, $bind); | |
return intval($counts); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment