Magento – Problem with addWebsiteFilter and addStoreFilter

magento-1.9product-collectionprogrammatically

I am working on my product collection query. I used "addWebsiteFilter" and "addStoreFilter" in my collection query. The problem is addWebsiteFilter supports array of website ids but addStoreFilter not supporting array of store ids so my query return error. Is any other method which supports array of store id for filtering product collection.

$collection_new = Mage::getModel('catalog/product')                          
->getCollection()           
->addAttributeToSelect(array('description','price'))
->addWebsiteFilter($web_id)
->addStoreFilter($storeId)
->addAttributeToFilter('status', 1);

Best Answer

In magento, addStoreFilter() does not filter the collection by multiple stores . We are able to filter the product collection by one store only.

You can see.the logic at Mage_Catalog_Model_Resource_Product_Collection.

    public function addStoreFilter($store = null)
    {
        if ($store === null) {
            $store = $this->getStoreId();
        }
        $store = Mage::app()->getStore($store);

        if (!$store->isAdmin()) {
            $this->_productLimitationFilters['store_id'] = $store->getId();
            $this->_applyProductLimitations();
        }

        return $this;
    }

Magento does not have any function which will filter the collection by mutiple store id