I want to filter reports/product_collection
by attribute manufacturer
.
I try with this:
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->joinAttribute('manufacturer','catalog_product/manufacturer','entity_id',null,'left')
->addAttributeToFilter($attr, array('eq' => $attr_id))
->setStoreId($storeId)
->addStoreFilter($storeId)
->addViewsCount($from, $to)
->setPageSize($productCount);
Mage::getSingleton('catalog/product_status')
->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')
->addVisibleInCatalogFilterToCollection($_productCollection);
But the lines:
->joinAttribute('manufacturer','catalog_product/manufacturer','entity_id',null,'left')
->addAttributeToFilter($attr, array('eq' => $attr_id))
Do not have any effect. What am I doing wrong?
EDIT: Here's the SOLUTION, including a filter to grouped products. Thanks to Amit! For pointing me there!
$_reportIds = Mage::getResourceModel('reports/product_collection')
->setStoreId($storeId)
->addStoreFilter($storeId)
->addViewsCount($from, $to)
->getColumnValues('entity_id');
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('entity_id', array('in' => array($_reportIds)))
->addAttributeToFilter('type_id', array('eq' => 'grouped'))
->addAttributeToFilter('manufacturer', array('eq' => $attr_id));
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_productCollection);
Best Answer
There are other way,you can do.
Mage::getModel('catalog/product')->getCollection()
and then filterthat collection using first set product ids
3.Now that collection by manufacturer attributeCode may be: