tags:

views:

942

answers:

2

Hi All

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 following 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?

+2  A: 

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.

Alan Storm
Thanks for that Alan - set me off on the right path. Seems that I 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)** - but now the problem is I can't filter by category twice, which I need to do for category pages (filter by current category AND featured category. I previously used the following: **->addCategoryFilter($_category)->addAttributeToFilter('category_ids',array('finset'=>$featuredcategory))** Any ideas on that?
Sam
Long story short? You use the filter method to get one group, and the foreach over the resulting collection and pull out the items you want. If you wanted an "from both" categories situation, just create two collections. Longer Story: I spent a bit looking at the object you're working with, and I didn't see an obvious public interface for doing this. There's a signifigant amount of complicated logic going on (see method <code>_applyProductLimitations</code>) dealing with the the various product and category indexes that magento builds up that doing this in a pure ORM fashion is tricky.
Alan Storm
Yeah was thinking maybe to grab two collections, and use an ** if(stristr($featuredcategory, $currcategory)** type statement to find which products are in both collections. But to do that I'd need to have both collections in a comma separated list I guess - any ideas how to output a collection as a list of sku's?
Sam
A: 

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)
Sam