Created
August 17, 2016 14:30
-
-
Save euperia/d17df77ff5f7cad5dd87fd61bccf36d3 to your computer and use it in GitHub Desktop.
How to use Group By on a Magento Collection
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 | |
$collection = Mage::getModel('sales/order_item')->getCollection(); | |
$collection | |
->addAttributeToFilter('updated_at', array('gt' => $this->reportStartDate)) | |
->addAttributeToFilter('updated_at', array('lt' => $this->reportEndDate)); | |
// this is where we add the group by | |
$collection->getSelect()->group('main_table.sku'); | |
$collection->setOrder('updated_at', 'DESC'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment