I am trying to use the original Magento layered navigation instead of the one used in the below code for a custom product collection. The developer who wrote this code is no longer available and I don't know how to replace the custom layered navigation used in the below code with the original one.
If anyone helps on this, very appreciated.
Thanks
PHP Code:
class Designota_Catalogg_Block_Bestseller extends Mage_Catalog_Block_Product_List {
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
$layer->getCurrentCategory()->setIsAnchor(1);
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
$this->_productCollection->addAttributeToFilter('fc_sales', array('gt' => 0));
$this->_productCollection->addOrder('fc_sales');
$this->_prepareFilterParams();
$b = $this->getLayout()->createBlock('catalog/layer_view')->setTemplate('catalog/layer/view.phtml');
$this->getLayout()->getBlock('left')->append($b);
}
return $this->_productCollection;
}
protected function _prepareFilterParams() {
$helper = Mage::helper('catalog/output');
$request = Mage::app()->getRequest();
$attr = array();
$attributes = Mage::getSingleton('catalog/layer')->getFilterableAttributes();
foreach ($attributes as $attribute) {
$attr[$attribute->getAttributeCode()]['type'] = $attribute->getBackendType();
$options = $attribute->getSource()->getAllOptions();
foreach ($options as $option) {
$attr[$attribute->getAttributeCode()]['options'][$helper->formatUrlValue($option['label'])] = $option['value'];
}
}
Mage::register('gan_filter_attributes', $attr);
if (($layerParams = $request->getQuery()) && ! empty($layerParams)) {
foreach ($layerParams as $param => $value) {
if ($param == 'cat') {
$values = explode(',', $value);
$prepare_values = array();
foreach ($values as $_value) {
$category = Mage::getModel('catalog/category')->loadByAttribute('url_key', $_value);
if ($category && $category->getId()) {
$prepare_values[] = $category->getId();
}
}
$request->setQuery($param, implode(',', $prepare_values));
}
elseif (isset($attr[$param]) && ! in_array($attr[$param]['type'], array('price', 'decimal'))) {
$values = explode(',', $value);
$prepare_values = array();
foreach ($values as $_value) {
if (isset($attr[$param]['options'][$_value])) {
$prepare_values[] = $attr[$param]['options'][$_value];
}
}
$request->setQuery($param, implode(',', $prepare_values));
}
}
}
}
}
View more threads in the same category:
Bookmarks