Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app/etc/modules/ModuleName_All.xml
- <?xml version="1.0"?></pre>
- <config>
- <modules>
- <ModuleName_Catalog>
- <active>true</active>
- <codePool>local</codePool>
- </ModuleName_Catalog>
- </modules>
- </config>
- app/code/local/ModuleName/Catalog/etc/config.xml
- <?xml version="1.0"?>
- <config>
- <modules>
- <ModuleName_Catalog>
- <version>0.1.0</version>
- </ModuleName_Catalog>
- </modules>
- <global>
- <blocks>
- <ModuleName_catalog>
- <class>ModuleName_Catalog_Block</class>
- </ModuleName_catalog>
- </blocks>
- <models>
- <catalog_resource_eav_mysql4>
- <rewrite>
- <product_collection>
- ModuleName_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
- </product_collection>
- </rewrite>
- </catalog_resource_eav_mysql4>
- </models>
- </global>
- </config>
- app/code/local/ModuleName/Catalog/Block/Product/Listcategories.php
- <?php
- class ModuleName_Catalog_Block_Product_Listcategories
- extends Mage_Catalog_Block_Product_List{
- //same function from Mage_Catalog_Block_Product_List
- protected function _getProductCollection(){
- // get simple product collection
- $this->_productCollection = Mage::getModel('catalog/product')->getCollection();
- $this->_productCollection->addAttributeToSelect('*');
- // if we receive categories parameter we filter with our custom function addCategoriesFilter
- // currently there's a addCategoryFilter, but only accepts 1 category
- // if no param is passed, simply show everything
- if($this->getCategories()!="")
- $this->_productCollection->addCategoriesFilter($this->getCategories());
- return $this->_productCollection;
- }
- }
- ?>
- app/code/local/ModuleName/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php
- <?php
- class ModuleName_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
- extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection{
- public function addCategoriesFilter($categories){
- $alias = 'cat_index';
- $categoryCondition = $this->getConnection()->quoteInto(
- $alias.'.product_id=e.entity_id AND '.$alias.'.store_id=? AND ',
- $this->getStoreId()
- );
- $categoryCondition.= $alias.'.category_id IN ('.$categories.')';
- $this->getSelect()->joinInner(
- array($alias => $this->getTable('catalog/category_product_index')),
- $categoryCondition,
- array('position'=>'position')
- );
- $this->_categoryIndexJoined = true;
- $this->_joinFields['position'] = array('table'=>$alias, 'field'=>'position' );
- return $this;
- }
- }
- ?>
- This is what I have tried to load in a cms page:
- <p>{{block type="ModuleName_catalog/product_Listcategories" categories="10,13,16" template="catalog/product/list.phtml"}}</p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement