Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. app/etc/modules/ModuleName_All.xml
  2.  
  3. <?xml version="1.0"?></pre>
  4. <config>
  5. <modules>
  6. <ModuleName_Catalog>
  7. <active>true</active>
  8. <codePool>local</codePool>
  9. </ModuleName_Catalog>
  10. </modules>
  11. </config>
  12.  
  13.  
  14. app/code/local/ModuleName/Catalog/etc/config.xml
  15.  
  16. <?xml version="1.0"?>
  17. <config>
  18. <modules>
  19. <ModuleName_Catalog>
  20. <version>0.1.0</version>
  21. </ModuleName_Catalog>
  22. </modules>
  23. <global>
  24. <blocks>
  25. <ModuleName_catalog>
  26. <class>ModuleName_Catalog_Block</class>
  27. </ModuleName_catalog>
  28. </blocks>
  29. <models>
  30. <catalog_resource_eav_mysql4>
  31. <rewrite>
  32. <product_collection>
  33. ModuleName_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
  34. </product_collection>
  35. </rewrite>
  36. </catalog_resource_eav_mysql4>
  37. </models>
  38. </global>
  39. </config>
  40.  
  41.  
  42. app/code/local/ModuleName/Catalog/Block/Product/Listcategories.php
  43.  
  44.  
  45. <?php
  46. class ModuleName_Catalog_Block_Product_Listcategories
  47. extends Mage_Catalog_Block_Product_List{
  48.  
  49. //same function from Mage_Catalog_Block_Product_List
  50. protected function _getProductCollection(){
  51.  
  52. // get simple product collection
  53. $this->_productCollection = Mage::getModel('catalog/product')->getCollection();
  54. $this->_productCollection->addAttributeToSelect('*');
  55.  
  56. // if we receive categories parameter we filter with our custom function addCategoriesFilter
  57. // currently there's a addCategoryFilter, but only accepts 1 category
  58. // if no param is passed, simply show everything
  59. if($this->getCategories()!="")
  60. $this->_productCollection->addCategoriesFilter($this->getCategories());
  61.  
  62. return $this->_productCollection;
  63. }
  64. }
  65. ?>
  66.  
  67.  
  68.  
  69. app/code/local/ModuleName/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php
  70. <?php
  71. class ModuleName_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
  72. extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection{
  73.  
  74. public function addCategoriesFilter($categories){
  75.  
  76. $alias = 'cat_index';
  77. $categoryCondition = $this->getConnection()->quoteInto(
  78. $alias.'.product_id=e.entity_id AND '.$alias.'.store_id=? AND ',
  79. $this->getStoreId()
  80. );
  81.  
  82. $categoryCondition.= $alias.'.category_id IN ('.$categories.')';
  83.  
  84. $this->getSelect()->joinInner(
  85. array($alias => $this->getTable('catalog/category_product_index')),
  86. $categoryCondition,
  87. array('position'=>'position')
  88. );
  89.  
  90. $this->_categoryIndexJoined = true;
  91. $this->_joinFields['position'] = array('table'=>$alias, 'field'=>'position' );
  92.  
  93. return $this;
  94.  
  95. }
  96. }
  97. ?>
  98.  
  99.  
  100. This is what I have tried to load in a cms page:
  101.  
  102. <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