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.
When rendering “stops” like that it almost always means Magento encountered a PHP error while trying to
includein the phtml file. Take a look at your PHP and/or Apache error logs and see what PHP is complaining about. There’s too many variables to troubleshoot things without that information.If you absolutely can’t get at your error logs, delete your entire phtml file and then add code back line by line, block by block, until you can reproduce your problem, and then figure out what’s wrong with the last bit you just added.