Magento Expert Forum - Improve your Magento experience

Results 1 to 3 of 3

Implement Original Layered Navigation to custom product collection

  1. #1
    New member
    Join Date
    Feb 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Implement Original Layered Navigation to custom product collection

    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(11)
                        ->
    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($paramimplode(','$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($paramimplode(','$prepare_values));
                            }
                    }
            }
        }

    View more threads in the same category:


  2. #2
    Junior Member Cms_ideas's Avatar
    Join Date
    Jun 2014
    Location
    https://cmsideas.net
    Posts
    385
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    Magento Advanced Layered Navigation - $49
    Best solution for Layered Navigation on website, create professional website
    DEMO: http://cmsideas.net/magento-advanced...avigation.html

    Features:
    - Allow customers to see the selected products faster without multiple page reloading by enabling Ajax navigation, thus improving customers’ experience
    - Allow customers to filter search results by multiple product attributes in each category
    - Show customers’ chosen filters in “Currently shopping by” box on the upper left sidebar for them to make changes if they want without reloading pages
    - Easily install and configure
    - Have user-friendly interface
    - Use price slider with price range as well as input field for inserting prices
    - Control filter display types with many options without problem
    - Manage attributes easily
    - Allow setting or hiding attribute filters for certain categories
    - Allow using various modes for category display
    - Appear a loading icon while waiting for products results
    - Multi-store and multi-language store supported
    DEMO | Magento Advanced Layered Navigation | Magento Packages

    NOTE: From 13/2 to 30/4. Magento Packages now discount 50%- Comprehensive solutions for e-commerce website
    Magento Package 1- Only $142.5 for 5 extensions: Magento Full Page Cache, 20 + Actions Manage Products in Backend, Quick View Pro ,Magento Revolution Slider and Magento Daily Deal .

    Magento packages 2- ONLY $132.5 for Add Columns to Order Grid in Backend, Extended PDF Invoice, Magento Full Page Cache, Magento Advanced Sorting Product List and Magento Mobile Theme

    For more, click: here

  3. #3
    Junior Member paulsimmons's Avatar
    Join Date
    Apr 2014
    Location
    USA
    Posts
    213
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Why dont you try this Free Layered Navigation extension to add multiple filters like price, size, color etc.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •