Skip to content

Instantly share code, notes, and snippets.

@deniscsz
Forked from aleron75/collection_copy
Created May 6, 2018 20:44
Show Gist options
  • Save deniscsz/fa6c138d824a18589a2b1dfaf55847a7 to your computer and use it in GitHub Desktop.
Save deniscsz/fa6c138d824a18589a2b1dfaf55847a7 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)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment