1

I have a custom product collection (i.e) list of products which is based on the two attributes's values. Page is replicating the catalog page by the below xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <customization_index_index>
        <reference name="root">
            <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="customization/product_searchbycity" name="searchbycity" as="searchbycity" template="catalog/product/list.phtml">

            </block>
        </reference>
        <!--<reference name="left">
            <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml"/>
        </reference>-->
        <reference name="left">
            <block type="customization/citysearch_layer" name="citysearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
        </reference>
    </customization_index_index>
</layout>

Now I need the layered navigation in the left for the same collection. Below is the block.

<?php

class Probytes_Customization_Block_Citysearch_Layer extends Mage_Catalog_Block_Layer_View
{

    protected function _construct()
    {
        parent::_construct();

        /* To get picked up by Mage_Catalog_Product_List::getLayer() */
        Mage::register('current_layer', $this->getLayer(), true);
    }

    public function getLayer()
    {
        return Mage::getSingleton('customization/citysearch_layer');
    }
    protected function _getProductCollection()
    {  

       if (is_null($this->_productCollection)) 
        {
            $layer = $this->getLayer();
            $productCollection = $layer->getProductCollection();
            $this->_productCollection = $productCollection;
        }
        return $this->_productCollection;
    }

}

It's the model

class Probytes_Customization_Model_Citysearch_Layer extends Mage_Catalog_Model_Layer {

    public function prepareProductCollection($collection)
    {
            //parent::prepareProductCollection($collection);
            //Mage::getModel('customization');
            $data['address'] = Mage::app()->getRequest()->getParam('city-to-search');
            $model = Mage::getModel('customization/citysearch');
            $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
            $collection->addAttributeToFilter('status',1)
                        ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
            //$collections = Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
            $collection = $model->searchResult($data,$collection);
            return $this;
    }
    public function getProductCollection()
{

    if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
        $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
    } else {

        $data['address'] = Mage::app()->getRequest()->getParam('city-to-search');
            $model = Mage::getModel('customization/citysearch');
            $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
            $collection->addAttributeToFilter('status',1)
                        ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
            //$collections = Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
            $collection = $model->searchResult($data,$collection);
    }
    return $collection;
} 

}

I tried like this layered navigation for custom product collection on custom page

But not working, I am getting empty array in the left navigation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.