Filtering a Collection in Magento 1

To filter a Collection we will use the function addFieldToFilter

Starting from the principle that you can use either a Magento core collection or a third-party module, you should normally load it by the function getCollection ()

$ collection = Mage :: getModel ('zz_zzcore / restaurant') -> getCollection () -> addFieldToFilter ('product_id', $ product_id); $ objs_ = $ collection -> load ();

In the above example I am filtering the collection that I create by the column "product_id".

For multiple filters you simply multiply the function call addFieldToFilter in sequence

$ collection = Mage :: getModel ('zz_zzcore / restaurant') -> getCollection () -> addFieldToFilter ('field1', $ field1) -> addFieldToFilter ('field2', $ field2); 

Rate This Article!

Click on the stars to give a note of 1 to 5.

1 star2 stars3 stars4 stars5 stars (No Ratings Yet)
Loading ...

Doubts? Make a comment below or send us a message by clicking here.

Your email address will not be published. Required fields are marked with *