Filtering by category in Magento 1.4
I have a custom module I made to show featured products on the homepage. I set it up to show products that are in a ‘featured’ category. It works fine in 1.3, but now in 1.4 I get the 开发者_StackOverflowfollowing error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘e.category_ids’ in ‘where clause’
Here’s my code:
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', $visibility)
->addAttributeToFilter('category_ids',array('finset'=>$featuredcategory))
$_productCollection->load();
The featured category is specified from the admin.
Anyone any ideas what might be up?
Looks like the reports/product_collection
Model doesn't have a category_ids attribute anymore.
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*');
$_productCollection->load();
foreach($_productCollection as $item)
{
var_dump(array_keys($item->getData()));
exit;
}
You'll need to find a different Model to grab the information you need.
Just to clarify the answer. You can get it to work by defining the featured category first:
$_featcategory = Mage::getModel('catalog/category')->load($featuredcategory);
and then using the normal category filter:
->addCategoryFilter($_featcategory)
精彩评论