Adding layered navigation block to custom page
-
16-10-2019 - |
문제
In Magento, the Layered Navigation block works nicely in the product list page.
How can this block be successfully copied to a custom page, where there is a custom list of products?
Note: Just adding the block to the XML, and calling it's getChildHtml('blockname')
doesn't do the trick.
해결책
Basically what you have to do is extend/overwrite
from Mage_Catalog_Block_Product_List (List.php)
and rewrite the getProductCollection()
method:
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
// Build collection and set it
$collection = "...";
$this->setProductCollection($collection);
}
return $this->_productCollection;
}
When that was done I had overwritten both the Mage_Catalog_Model_Layer
class and the Mage_Catalog_Model_Category
and introduced a new variable:
protected $_customProductCollection;
I have overwritten the getProductCollection()
in both classes and I added this in the beginning of the method:
if(isset($this->_customProductCollection)){
return $this->_customProductCollection;
}
I have also a method that allows me to set this "customProductCollection"
inside both these classes. Once It's set, the rest of the data of the layered navigation/category is based on this collection.
Check out the initial question+answer here.
Good luck ;)