/** * Prepare products collection, defined collection filters (category, product type) * * @return Mage_Adminhtml_Block_Widget_Grid */ protected function _prepareCollection() { /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ $collection = Mage::getResourceModel('catalog/product_collection')->setStoreId(0)->addAttributeToSelect('name'); if ($categoryId = $this->getCategoryId()) { $category = Mage::getModel('catalog/category')->load($categoryId); if ($category->getId()) { // $collection->addCategoryFilter($category); $productIds = $category->getProductsPosition(); $productIds = array_keys($productIds); if (empty($productIds)) { $productIds = 0; } $collection->addFieldToFilter('entity_id', array('in' => $productIds)); } } if ($productTypeId = $this->getProductTypeId()) { $collection->addAttributeToFilter('type_id', $productTypeId); } $this->setCollection($collection); return parent::_prepareCollection(); }