Created
February 20, 2015 08:42
-
-
Save aleron75/d383333c73ed41f6d93b to your computer and use it in GitHub Desktop.
Copy a Magento collection
This file contains 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
$originalCollection = Mage::getModel('catalog/product') | |
->getCollection(); | |
$newCollection = Mage::getModel('catalog/product') | |
->getCollection(); | |
$selectParts = array( | |
Varien_Db_Select::DISTINCT, | |
Varien_Db_Select::COLUMNS, | |
Varien_Db_Select::UNION, | |
Varien_Db_Select::FROM, | |
Varien_Db_Select::WHERE, | |
Varien_Db_Select::GROUP, | |
Varien_Db_Select::HAVING, | |
Varien_Db_Select::ORDER, | |
Varien_Db_Select::LIMIT_COUNT, | |
Varien_Db_Select::LIMIT_OFFSET, | |
Varien_Db_Select::FOR_UPDATE, | |
); | |
$originalSelect = $originalCollection->getSelect(); | |
$newSelect = $newCollection->getSelect(); | |
foreach ($selectParts as $part) { | |
$newSelect->setPart( | |
$part, | |
$originalSelect->getPart($part) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man! i was facing some problems cloning both the collection or the select, but this way i solved (actually doing that broke the ordering in toolbar and the pagination in the pager)