Magento 1.9.2 Tambahkan navigasi layer untuk memajukan pencarian

12

Saya telah mengikuti 3 langkah untuk navigasi lapisan pencarian lanjutan, tetapi tidak berfungsi. Ada ide / saran ATAU Bagaimana menerapkan navigasi lapisan dalam pencarian lanjutan?

1) Di local.xml kami di bawah tag menambahkan catalogsearch_advanced_result.

<reference name="left">
      <block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
 </reference>

2) Menggantikan fungsi prepProductCollection dari catalogsearch / model / Layer.php dengan

public function prepareProductCollection($collection){

    if(Mage::helper('catalogsearch')->getQuery()->getQueryText())//for normal search we get the value from query string q=searchtext
        return parent::prepareProductCollection($collection);
    else{

        $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
        /**
         * make sure you cross check the $_REQUEST with $attributes
         */
        $attributes = Mage::getSingleton('catalog/product')->getAttributes();

        Mage::log(print_r($_REQUEST,1));
        foreach($attributes as $attribute){
            $attribute_code = $attribute->getAttributeCode();
            //Mage::log("--->>". $attribute_code);
            if($attribute_code == "price")//since i am not using price attribute
                continue;

            if (empty($_REQUEST[$attribute_code])){
                //Mage::log("nothing found--> $attribute_code");
                continue;
            }
            if(!empty($_REQUEST[$attribute_code]) && is_array($_REQUEST[$attribute_code]))
                $collection->addAttributeToFilter($attribute_code, array('in' => $_REQUEST[$attribute_code]));
            else
            if(!empty($_REQUEST[$attribute_code]))
                $collection->addAttributeToFilter($attribute_code, array('like' => "%" . $_REQUEST[$attribute_code] . "%"));
        }

        $collection->setStore(Mage::app()->getStore())
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addStoreFilter()
        ->addUrlRewrite();

        //Mage::log($collection->getSelect()->__toString());

        Mage::getSingleton('catalogsearch/advanced')->prepareProductCollection($collection);    
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
    }

    return $this;
}

3) Menggantikan getProductCollection, fungsi getSearchCriterias dari katalogsearch / model / Advanced.php dengan

public function getProductCollection(){

    if (is_null($this->_productCollection)) {
        $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addMinimalPrice()
            ->addStoreFilter();
            Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
            Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);

        if(isset($_GET['cat']) && is_numeric($_GET['cat'])) 
            $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['cat']),true);
    }
    return $this->_productCollection;
}

public function getSearchCriterias()
{
    $search = parent::getSearchCriterias();
    /* display category filtering criteria */
    if(isset($_GET['cat']) && is_numeric($_GET['cat'])) {
        $category = Mage::getModel('catalog/category')->load($_GET['cat']);
        $search[] = array('name'=>'Category','value'=>$category->getName());
    }
    return $search;
}
Kishor Hase
sumber

Jawaban:

1

Buat file baru dalam model Layer lokal atau ganti dalam aplikasi modul / kode lokal / Mage / CatalogSearch / Model / Layer.php file dan Ubah fungsi prepProductCollection

    public function prepareProductCollection($collection)
    {
        if(Mage::helper('catalogsearch')->getQuery()->getQueryText())
        {
            $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
            ->setStore(Mage::app()->getStore())
            ->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addStoreFilter()
            ->addUrlRewrite();
        }
        else
        {
            $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
            $attributes = Mage::getSingleton('catalog/product')->getAttributes();
            foreach($attributes as $attribute)
            {
                $attribute_code = $attribute->getAttributeCode();
                if($attribute_code == "price")
                continue;
                if (empty($_REQUEST[$attribute_code])){continue;}
                if(!empty($_REQUEST[$attribute_code]) && is_array($_REQUEST[$attribute_code]))
                    $collection->addAttributeToFilter($attribute_code, array('in' => $_REQUEST[$attribute_code]));
                else
                if(!empty($_REQUEST[$attribute_code]))
                $collection->addAttributeToFilter($attribute_code, array('like' => "%" . $_REQUEST[$attribute_code] . "%"));
            }
            $collection->setStore(Mage::app()->getStore())
            ->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addStoreFilter()
            ->addUrlRewrite();
            Mage::getSingleton('catalogsearch/advanced')->prepareProductCollection($collection);    
        }
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
        return $this;
    }

Setelah itu lakukan hal yang sama dengan app / code / local / Mage / CatalogSearch / Model / Advanced.php dan ubah fungsi getProductCollection dan getSearchCriterias

    public function getProductCollection()
    {
        if (is_null($this->_productCollection)) {
            $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addMinimalPrice()
            ->addStoreFilter();
            Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
            Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
            if(isset($_GET['cat']) && is_numeric($_GET['cat']))
            $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['cat']),true);
        }
        return $this->_productCollection;
    }
    public function getSearchCriterias()
    {
        $search = $this->_searchCriterias;
        if(isset($_GET['cat']) && is_numeric($_GET['cat'])){
            $category = Mage::getModel('catalog/category')->load($_GET['cat']);
            $search[] = array('name'=>'Category','value'=>$category->getName());
        }
        return $search;
    }

Di sini, di bawah ini, navigasi lapisan disiapkan untuk koleksi produk pencarian lanjut sekarang harus menampilkan navigasi lapisan itu menggunakan file tema xml jadi edit file tema Anda atalogsearch.xml dan tambahkan kode di bawah ini dalam menandai.

<reference name="left">
  <block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>

Untuk informasi lebih lanjut, kunjungi tautan ini

Vaibhav Ahalpara
sumber
Ini bekerja seperti pesona!
Nalin Savaliya
0

Untuk menampilkan navigasi berlapis dalam pencarian lanjutan, Anda harus membuat beberapa perubahan pada file inti.

Ikuti tautan ini Saya telah menggunakan proses yang sama dan berfungsi dengan baik.

https://newsinfo-blog.blogspot.in/2016/05/add-layered-navigation-to-advance.html

yudhbir singh
sumber
Coba tambahkan informasi dari tautan itu ke posting Anda, tautannya sudah kadaluwarsa, halaman sudah ditutup.
versedi
Hanya mencari pengunjung, itu menyebalkan: /
Marwen Jelloul
0

Untuk menambahkan navigasi layer untuk memajukan pencarian, ikuti langkah-langkah di bawah ini: 1- Di bawah ini, navigasi layer disiapkan untuk koleksi produk pencarian lanjut sekarang harus menampilkan navigasi layer menggunakan file tema xml jadi edit file themesearch.xml tema Anda dan tambahkan kode di bawah ini dengan tag.

    <reference name="left">
      <block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
    </reference>

2. Override prepareProductCollection function of catalogsearch/model/Layer.php with this

    public function prepareProductCollection($collection)
    {   
        $bac= Mage::helper('catalogsearch')->getQuery()->getQueryText();
        if($bac)
        {
            $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
            ->setStore(Mage::app()->getStore())
            ->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addStoreFilter()
            ->addUrlRewrite();

        } 
        else 
        {

            $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
            $attributes = Mage::getSingleton('catalog/product')->getAttributes();
            foreach($attributes as $attribute)
            {
                $attribute_code = $attribute->getAttributeCode();
                if($attribute_code == "price")
                continue;
                if (empty($_REQUEST[$attribute_code])){continue;}
                if(!empty($_REQUEST[$attribute_code]) && is_array($_REQUEST[$attribute_code]))
                    $collection->addAttributeToFilter($attribute_code, array('in' => $_REQUEST[$attribute_code]));
                else
                if(!empty($_REQUEST[$attribute_code]))
                $collection->addAttributeToFilter($attribute_code, array('like' => "%" . $_REQUEST[$attribute_code] . "%"));
            }
            $collection->setStore(Mage::app()->getStore())
            ->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            ->addStoreFilter()
            ->addUrlRewrite();
            Mage::getSingleton('catalogsearch/advanced')->prepareProductCollection($collection);    
        }
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
        return $this;
    }

3. Than after changing getProductCollection and getSearchCriterias function as below in app/code/core/Mage/CatalogSearch/Model/Advanced.php file.

<?php 
public function getProductCollection()
{
    if (is_null($this->_productCollection)) {
        $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
        ->addMinimalPrice()
        ->addStoreFilter();
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
        if(isset($_GET['cat']) && is_numeric($_GET['cat']))
        $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['cat']),true);
    }
    return $this->_productCollection;
}

public function getSearchCriterias()
{
    $search = $this->_searchCriterias;
    if(isset($_GET['cat']) && is_numeric($_GET['cat'])){
        $category = Mage::getModel('catalog/category')->load($_GET['cat']);
        $search[] = array('name'=>'Category','value'=>$category->getName());
    }
    return $search;
}
Abhinav Singh
sumber