As the title suggests, I’d like to call my collection, store it into different variables, then manipulate the variables but leaving the original collection intact. The code should be something like this:
$collection = $this->collection->create()->addFieldToFilter('attribute', 'value');
$originalCollection = $collection;
$columnValues = $collection->joinLeft($table, $on, $columns)->reset(Zend_Db_Select::COLUMNS)->columns(['fieldname1']);
$firstItem = $originalCollection->getFirstItem()->getData();
$this->logger->log($columnValues[0]);
$this->logger->log($firstItem);
In this instance, I’d like the first log to print only the first “fieldname1” while the second log to print the whole first item of the original collection.
Instead, what I get is that $columnValues[0] and $firstItem are the same so $firstItem also prints only fieldname1.
Is there a way to copy the original collection in a variable to preserve it from the subsequent modifications?