I have one collection in a method where I want to perform two different operations on this collection. So, I want two separate copies of same collection, and then assign one of the two collections to original collection again and return it.
To make this simple, suppose I have an object collection called $collection
.
Now, I am trying it with PHP cloning as I don't know if there is any Magento collection cloning inbuilt or not.
$coll1 = clone $collection;
$coll2 = clone $collection;
Now I am trying to perform different operations on these two separate clones of the original collection, something like.
$coll1->getSelect()->where('some where condition');
$coll2->getSelect()->where('some different where condition');
if($coll1->count() == 0) {
$collection = $coll2;
} else {
$collection = $coll1;
}
But the weird thing is, both these cloned collections have both the where conditions assigned! $coll1 condition is applied to $coll2 along with $coll2's condition, and vice versa.
Does anyone know how to achieve this?
Thanks!