The problem not in EAV based entities. Method addFieldToFilter()
is available only in Varien_Data_Db_Collection
, that EAV and standard ORM models extend. If you'd like to have your admin grid module working with your collection in the same way as it works with DB collection, you need to implement two methods:
addFieldToFilter($filterName, $conditionArray)
setSort($fieldName, $direction)
Example of such custom collection implementation you can find in Varien_Data_Collection_Filesystem
class that utilizes FS based collections. This kind of collection, for instance, used in Mage_Backup
module to show grid with backup files.
Sincerely,
Ivan
When adding the product attribute, set used_in_product_listing
, used_for_sort_by
and filterable
to true
.
You can do that with the following update script:
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();
$installer->updateAttribute('catalog_product', 'product_type', 'used_in_product_listing', 1);
$installer->updateAttribute('catalog_product', 'product_type', 'used_for_sort_by', 1);
$installer->updateAttribute('catalog_product', 'product_type', 'is_filterable', 1);
$installer->endSetup();
Thats all, if if you are NOT using the flat catalog.
If you enable the flat catalog product feature, then you need to ensure that your custom source model implements the methods getFlatColums()
, getFlatIndexes()
and getFlatUpdateSelect()
.
If they are missing, your attribute won't be included in the generated flat tables, even if used_in_product_listing
is enabled.
Have a look at the class Mage_Eav_Model_Entity_Attribute_Source_Boolean
for an example. You can probably copy over the methods with minimal adjustments into your custom source model from there. Otherwise, please ask a new question.
Best Answer
Use
addFieldToFilter
instead ofaddFilter
: