Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2011 07:27
Show Gist options
  • Save anonymous/998557 to your computer and use it in GitHub Desktop.
Save anonymous/998557 to your computer and use it in GitHub Desktop.
$result = Mage::getModel('customer/customer')->getCollection()
->join(array('pet' => $this->getTable('partners_earn_transactions')), $this->getTable('customer_entity').'.entity_id = `pet`.customer_id')
->addExpressionFieldToSelect('transaction_count', 'COUNT({{pet.id}})')
->addAttributeToFilter('country_id', $country_code)
->addFieldToFilter('is_active', 1)
->addAttributeToSort('COUNT({{pet.id}})')
->addAttributeToSort('SUM({{pet.points}})')
->groupByAttribute($this->getTable('customer_entity').'.entity_id')
->limit(5)
->load();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment