2

I want to deploy following logic ;

 - Load product collection

  *start loop*


 - Extract the value with which I filter collection.



 - Filter based on above attribute to see if the product is there.



 - Reset the collection so I can use the same collection for filtering
   again


    *end loop*

But I do not know how to reset filters in a collection such as addFieldtoFilter, addAttribute to filter etc.
Any help would be appreciated.

1

Use clone http://php.net/manual/en/language.oop5.cloning.php

$_collection = $this->getLayer()->getProductCollection();
$collection = clone $_collection;
// your action here $collection->load() ->addFieldtoFilter etc.
foreach($collection as $product) {
 // do something
}

$_collection - is not change

1
  • best solution I have got +1.. Thanks man :) May 8 '19 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.