is it possible to get the category view on a page i want? (e.g. homepage could show one) and if that works - is it possible to get more then one category shown on one page? (i don’t want to write a really new module doing all the things which category ->productlist rendering already does ... )
In last release you will need to customize a bit.
In file app/code/core/Mage/Catalog/Block/Product/List.php replace method _getProductCollection() with:
protected function _getProductCollection() { if (is_null($this->_productCollection)) { $collection = Mage::getSingleton('catalog/layer'); if ($this->getShowRootCategory()) { $this->setCategoryId(Mage::getStoreConfig('catalog/category/root_id')); } if ($this->getCategoryId()) { $category = Mage::getModel('catalog/category')->load($this->getCategoryId()); $collection->setCurrentCategory($category); } $this->_productCollection = $collection->getProductCollection(); } return $this->_productCollection; }
Now you can put in your static page or static block this tag:
but if i do this only the first category i put in will be rendered:
i don’t use static page for this since i try some other things but i think static blocks also won’t work here.
public function indexAction() { $this->loadLayout();
THANK YOU, THANK YOU, THANK YOU!!! I’ve been trying to fix something completely different for the past 8 hours, and your single comment about switching from Singleton to Model *finally* fixed it!!! I can’t believe I overlooked this one thing ... argh!! But thank you for sharing!
public function getCacheTags()
{
return array(Mage_Catalog_Model_Product::CACHE_TAG);
}
public function getCacheKey()
{
$category = Mage::getModel(’catalog/category’)->load($this->getCategoryId());
return $this->getRequest()->getRequestUri();
}
Hi in your technique below, it doesn’t work for me unless i add the template
here is the code with the template:
{{block type="catalog/product_list" category_id="506" template="catalog/category/view.phtml" }} (id 506 is a category with 5 sub categories.)
but then I get a call to member function getImageUrl() on a non object in <path to above template file>, if I change the template path to point to catalog/product/list.phtml” it then works fine, but it dosnt show categories any more but only products.
I am using Magento ver. 1.3.2.4
any help is appreciated.
Thanks.
Moshe - 22 November 2007 05:29 AM
In last release you will need to customize a bit.
In file app/code/core/Mage/Catalog/Block/Product/List.php replace method _getProductCollection() with:
protected function _getProductCollection() { if (is_null($this->_productCollection)) { $collection = Mage::getSingleton('catalog/layer'); if ($this->getShowRootCategory()) { $this->setCategoryId(Mage::getStoreConfig('catalog/category/root_id')); } if ($this->getCategoryId()) { $category = Mage::getModel('catalog/category')->load($this->getCategoryId()); $collection->setCurrentCategory($category); } $this->_productCollection = $collection->getProductCollection(); } return $this->_productCollection; }
Now you can put in your static page or static block this tag: