<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog for the Web Programmers &#187; Search by Category in Magento</title>
	<atom:link href="http://blog.chandanweb.com/tags/search-by-category-in-magento/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.chandanweb.com</link>
	<description>A useful blog with code assitance on Typo3, Drupal, PHP, Apache, OpenSSL and PHP Frameworks</description>
	<lastBuildDate>Thu, 08 Jul 2010 05:44:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Adding search by Category feature to Magento Advanced search and catlog search in Product list view</title>
		<link>http://blog.chandanweb.com/magento/adding-search-by-category-feature-to-magento-advanced-search-and-catlog-search-in-product-list-view</link>
		<comments>http://blog.chandanweb.com/magento/adding-search-by-category-feature-to-magento-advanced-search-and-catlog-search-in-product-list-view#comments</comments>
		<pubDate>Fri, 29 Jan 2010 06:28:52 +0000</pubDate>
		<dc:creator>spabhat</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Easily Adding Features to Magento]]></category>
		<category><![CDATA[Easily Extending Features of Magento]]></category>
		<category><![CDATA[Magento Upgrade Safe]]></category>
		<category><![CDATA[Search by Category in Magento]]></category>

		<guid isPermaLink="false">http://blog.chandanweb.com/magento/adding-search-by-category-feature-to-magento-advanced-search-and-catlog-search-in-product-list-view</guid>
		<description><![CDATA[I recently had to add a search form in the Magento product list view and I found the following Wiki article: http://www.magentocommerce.com/wiki/how-to/how_to_add_search_by_category_to_advanced_search This article would work 100% perfect, however the steps given in article is not really upgrade safe. There were hence two options either to include these steps in a seperate magento module, or [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to add a search form in the Magento product list view and I found the following Wiki article:</p>
<p><a href="http://www.magentocommerce.com/wiki/how-to/how_to_add_search_by_category_to_advanced_search">http://www.magentocommerce.com/wiki/how-to/how_to_add_search_by_category_to_advanced_search</a></p>
<p>This article would work 100% perfect, however the steps given in article is not really upgrade safe.</p>
<p>There were hence two options either to include these steps in a seperate magento module, or to follow the steps I have given here. <br/>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. <br/>This step also protects us from our work being over-written when we make a magento upgrade.</p>
<p><strong>Step 1: <br/></strong> Create a new folder called <strong>&#8220;Mage&#8221;</strong> inside <strong>app/code/local</strong> <br/><br/>Now we have anew folder <strong>app/code/local/Mage</strong> <br/><br/><strong>Step 2:</strong> <br/>If I see the steps given in Magento wiki, we notice that the they are extending the features of the <strong>CatalogSearch</strong> module that is located in the namespace <strong>Mage</strong>, <br/>So just go to <strong>&#8220;app/code/core/Mage&#8221;</strong> and copy the entire folder named <strong>&#8220;CatalogSearch&#8221;</strong> into <strong>app/code/local/Mage <br/><br/></strong> Now we have the entire <strong>&#8220;CatalogSearch&#8221;</strong> module located in <strong>app/code/local/Mage/CatalogSearch</strong></p>
<p><strong>Step 3: <br/></strong> Now all we need to do is follow the exact steps given in the wiki article, <strong>however make sure to edit files located in app/code/local/Mage/CatalogSearch only. <br/><br/></strong> Link to the wiki: <a href="http://www.magentocommerce.com/wiki/how-to/how_to_add_search_by_category_to_advanced_search">http://www.magentocommerce.com/wiki/how-to/how_to_add_search_by_category_to_advanced_search</a></p>
<p>How to add catalog search in Magento product list view or the Search by category feature in Magento product list view.</p>
<p>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. <br/></p>
<p>Add the following code to</p>
<p>&#8220;app\design\frontend\<strong>YOURPACKAGENAME</strong>\default\template\catalog\product\list\toolbar.phtml&#8221; <br/>OR <br/>&#8220;app\design\frontend\<strong>YOURPACKAGENAME</strong>\default\template\catalog\product\list.phtml&#8221; <br/></p>
<blockquote><p>&lt;?php if( !isset($_GET['category']) ): ?&gt; <br/>&lt;form action=&#8221;&lt;?echo $this-&gt;getUrl(&#8216;catalogsearch/advanced/result&#8217;)?&gt;&#8221; method=&#8221;get&#8221; id=&#8221;category_search_form&#8221;&gt; <br/>&lt;?php <br/><br/>if ($this-&gt;helper(&#8216;catalog/data&#8217;)-&gt;getCategory()) { <br/>$_ccat = $this-&gt;helper(&#8216;catalog/data&#8217;)-&gt;getCategory(); <br/>} else { <br/>$_ccats = $this-&gt;helper(&#8216;catalog/data&#8217;)-&gt;getProduct()-&gt;getCategoryIds(); <br/>$_ccat = Mage::getModel(&#8216;catalog/category&#8217;)-&gt;load($_ccats[0]); <br/>}; <br/>$_ccatID = $_ccat-&gt;getId(); <br/>?&gt; <br/>&lt;input type=&#8221;hidden&#8221; id=&#8221;category_search_field&#8221; name=&#8221;category&#8221; value=&#8221;&lt;?php echo $_ccatID ?&gt;&#8221; /&gt; <br/>&lt;div class=&#8221;left&#8221;&gt; <br/>&lt;input name=&#8221;name&#8221; id=&#8221;searchcat&#8221; value=&#8221;&lt;?php echo $this-&gt;__(&#8216;Search Category&#8217;) ?&gt;&#8221; title=&#8221;Name&#8221; class=&#8221;input-text &#8221; type=&#8221;text&#8221; /&gt; <br/>&lt;input type=&#8221;image&#8221; alt=&#8221;&lt;?php echo $this-&gt;__(&#8216;Search&#8217;) ?&gt;&#8221; src=&#8221;&lt;?php echo $this-&gt;getSkinUrl(images/ico_s_search.png&#8217;)?&gt;&#8221; class=&#8221;cw_buttonicon&#8221; /&gt; <br/>&lt;/div&gt; <br/>&lt;/form&gt; <br/>&lt;script type=&#8221;text/javascript&#8221;&gt; <br/>//&lt;![CDATA[ <br/>var searchForm = new Varien.searchForm('category_search_form', 'searchcat', '&lt;?php echo $this-&gt;__('Search Category') ?&gt;'); <br/>searchForm.initAutocomplete('&lt;?php echo $this-&gt;helper('catalogSearch')-&gt;getSuggestUrl() ?&gt;', 'search_autocomplete'); <br/>//]]&gt; <br/>&lt;/script&gt; <br/>&lt;?php endif ?&gt;</p>
</blockquote>
<p><strong>Note:</strong> <br/><strong>1.</strong>The first if statement <strong>&lt;?php if( !isset($_GET['category']) ): ?&gt;</strong> makes sure that we will not have two forms in the advanced search result page. <br/>You should retain this if statement because when we are in advanced search we will no longer be in the previously selected category! <br/><strong><br/>2.</strong> You may need to change the path of search image.</p>
<p><strong>3.</strong> I have also included the autocomplete feature, so be careful if you are changing the name or ID attribute of the form or the input tags.</p>
<p>Hope this article would be useful, kindly do not forget to write your comments here. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chandanweb.com/magento/adding-search-by-category-feature-to-magento-advanced-search-and-catlog-search-in-product-list-view/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
