Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created March 27, 2014 17:36
Show Gist options
  • Select an option

  • Save ryaan-anthony/9813337 to your computer and use it in GitHub Desktop.

Select an option

Save ryaan-anthony/9813337 to your computer and use it in GitHub Desktop.
/**
* Get collection size
*
* @return int
*/
public function getSize()
{
if (is_null($this->_totalRecords)) {
$sql = $this->getSelectCountSql();
$this->_totalRecords = $this->getConnection()->fetchOne($sql, $this->_bindParams);
}
return intval($this->_totalRecords);
}
/**
* Get SQL for get record count
*
* @return Varien_Db_Select
*/
public function getSelectCountSql()
{
$this->_renderFilters();
$countSelect = clone $this->getSelect();
$countSelect->reset(Zend_Db_Select::ORDER);
$countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
$countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
$countSelect->reset(Zend_Db_Select::COLUMNS);
$countSelect->columns('COUNT(*)');
return $countSelect;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment