Magento Advanced Collection Filters

Online Magento tutorial, Magento Programming

I always seem to end up in a position where I need more specific information from a collection than addFilter() can give me. Functions like addAttributeToFilter() are great if you’re working with EAV-based collections like products and categories, but they don’t work with a lot of core Magento collections. In this post I’ll go into some detail on how to use the ->getSelect() function to filter collection results. This post comes with a warning: The methods detailed below are intended primarily for data output, not data manipulation. Be careful saving models returned from your original collection.

Calling $collection->getSelect() on your collection will return a model of class type Varien_Db_Select. This model represents the SQL query that is performed to select your collection. I’ve created a module called Mby_Testmodule, and within it I have a model of type testmodule/comment. Let’s get the Select element and play with it a bit.

<?php

View original post 330 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s