Skip to content

Instantly share code, notes, and snippets.

@aleron75
Created February 20, 2015 08:42
Show Gist options
  • Save aleron75/d383333c73ed41f6d93b to your computer and use it in GitHub Desktop.
Save aleron75/d383333c73ed41f6d93b to your computer and use it in GitHub Desktop.
Copy a Magento collection
$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)
);
}
@andreaschiffo
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment