2

I want to fetch only some categories products when user search front end. So how catalog search query join with category table related product onyl

2

This is not really a perfect practice, however, if we are not aware of writing a magento module then this can be a very quick alternative. This step also protects us from our work being over-written when we make a magento upgrade.

Step 1: Create a new folder called “Mage” inside app/code/local

Now we have anew folder app/code/local/Mage

Step 2: If I see the steps given in Magento wiki, we notice that the they are extending the features of the CatalogSearch module that is located in the namespace Mage, So just go to “app/code/core/Mage” and copy the entire folder named “CatalogSearch” into app/code/local/Mage

Now we have the entire “CatalogSearch” module located in app/code/local/Mage/CatalogSearch

Step 3: Now all we need to do is follow the exact steps given in the wiki article, however make sure to edit files located in app/code/local/Mage/CatalogSearch only.

How to add catalog search in Magento product list view or the Search by category feature in Magento product list view.

This simply involves adding a search form in prodcut list view we however need to ensure that the category id is passed to the advanced search form using a hidden input.

Add the following code to

“app\design\frontend\YOURPACKAGENAME\default\template\catalog\product\list\toolbar.phtml”
OR
“app\design\frontend\YOURPACKAGENAME\default\template\catalog\product\list.phtml”

    <?php if( !isset($_GET[‘category’]) ): ?>
    <form action=”<?echo $this->getUrl(‘catalogsearch/advanced/result’)?>” method=”get” id=”category_search_form”>
    <?php

    if ($this->helper(‘catalog/data’)->getCategory()) {
    $_ccat = $this->helper(‘catalog/data’)->getCategory();
    } else {
    $_ccats = $this->helper(‘catalog/data’)->getProduct()->getCategoryIds();
    $_ccat = Mage::getModel(‘catalog/category’)->load($_ccats[0]);
    };
    $_ccatID = $_ccat->getId();
    ?>
    <input type=”hidden” id=”category_search_field” name=”category” value=”<?php echo $_ccatID ?>” />
    <div class=”left”>
    <input name=”name” id=”searchcat” value=”<?php echo $this->__(‘Search Category’) ?>” title=”Name” class=”input-text ” type=”text” />
    <input type=”image” alt=”<?php echo $this->__(‘Search’) ?>” src=”<?php echo $this->getSkinUrl(images/ico_s_search.png’)?>” class=”cw_buttonicon” />
    </div>
    </form>
    <script type=”text/javascript”>
    //<![CDATA[
    var searchForm = new Varien.searchForm(‘category_search_form’, ‘searchcat’, ‘<?php echo $this->__(‘Search Category’) ?>’);
    searchForm.initAutocomplete(‘<?php echo $this->helper(‘catalogSearch’)->getSuggestUrl() ?>’, ‘search_autocomplete’);
    //]]>
    </script>
    <?php endif ?>

Note: 1.The first if statement makes sure that we will not have two forms in the advanced search result page. You should retain this if statement because when we are in advanced search we will no longer be in the previously selected category!

  1. You may need to change the path of search image.

3.Also included the autocomplete feature, so be careful if you are changing the name or ID attribute of the form or the input tags.

  • I find a query in fulltext.php , how can i apply join here. Actually i want only those products after search which are present in current alloted category to store. – Mathew Sep 11 '15 at 7:18
  • Because i have multiple store setup in my website and after search from any store i get other products also from other stores. – Mathew Sep 11 '15 at 7:20
  • 1
    Go to this file : /app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php and find public function prepareResult($object, $queryText, $query) in this function you can seen on line no 368 here you can put some your quires.I am not sure if it will work.make sure do not modify core files – Arunendra Sep 11 '15 at 7:30
  • Also you can get help from here : arabgento.com/en/… – Arunendra Sep 11 '15 at 7:34
  • Yes i find this line of code, but here not able to join with category related products. – Mathew Sep 11 '15 at 7:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.