Magento help with creating model in custom class

Posted by dardub on Stack Overflow See other posts from Stack Overflow or by dardub
Published on 2010-05-21T21:34:47Z Indexed on 2010/05/24 16:51 UTC
Read the original article Hit count: 200

Filed under:
|

I'm trying to add some custom filter methods to my magento module. I though it would be simple but I can't figure out why it's not working.

My model which extends the catalog/product class contains this:

public function filterProdType($prod_id)
{
   $this->addAttributeToFilter('attribute_set_id', $prod_id); 

}

Then in my template I have this:

 $collection = Mage::getModel('configurator/product')->getCollection()->addAttributeToSelect('*');


 $collection->filterProdType(50)->addAttributeToFilter('type_id', 'bundle');

 foreach ($collection as $item){
     echo $item->getName() . ', ';
 }

Just to try things out.

But I don't get any results, no error, and it doesn't finish rendering the page (missing footer).

When I do this instead, it works:

 $collection = Mage::getModel('configurator/product')->getCollection()->addAttributeToSelect('*');


 $collection->addAttributeToFilter('attribute_set_id', 50)->addAttributeToFilter('type_id', 'bundle');

 foreach ($collection as $item){
     echo $item->getName() . ', ';
 }

I'm just wondering what I'm missing.

UPDATE:

I didn't realize error reporting was turned off, after turning it on I get the error:

Fatal error: Call to undefined method 
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::filterProdType() 

I assumed after instantiating $collection using my custom model, it would find my new method.

© Stack Overflow or respective owner

Related posts about php

Related posts about magento