Magento – Magento get products by website id and store id

product-listproductsstoreswebsites

I am working in magento one website multiple stores platform, i successfully created one website with 3 stores and 3 store view. I assigned a category to my default store and products in it, but i getting other products also. Let me know how i can go to correct direction.

$collection = Mage::getModel('catalog/product')->setStoreId($storeId)->getCollection()->addAttributeToSelect('*')->addWebsiteFilter($website_id)->addAttributeToFilter‌​('type_id', array('eq' => 'simple'));
$collection->getSelect()->limit(8);

Best Answer

Try this

$websiteIds = array(Mage::app()->getStore()->getWebsiteId());
$storeId = Mage::app()->getStore()->getStoreId();

$collection = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToSelect('*');
$collection->addStoreFilter($storeId);
$collection->addWebsiteFilter($websiteIds);
Related Topic