Post by IvaWebsite » Fri May 18, 2012 10:01 pm

I would really appreciate some help - I’ve searched all extensions and forum but this subject doesn’t appear to be covered.
Is it possible for search results to display category names that match the search as well as products?
I like many OpenCart users have the same product in many different categories, so having the search results split into product matches and Category matches would benefit many stores.
Last edited by IvaWebsite on Sun May 20, 2012 12:11 am, edited 1 time in total.




Fri May 18, 2012 9:25 pm
Location - UK

Post by NigGuis » Sat May 19, 2012 10:48 pm

I have searched the web for weeks for this option also. There's no eCommerce software that offers this as standard. I am really surprised as I have found many, many posts asking for it.
For example a website that sells printer ink- the printer cartridge is listed as the product and the many printers that it fits are listed as categories. So the one printer cartridge is in many different categories which are the printer models that it fits. A cartridge model search automatically brings up the cartridge in a search, But like most searches the printer model is used for a search where no results are displayed?
Also generally a printer will take more than one cartridge so that's why a category search is essential. As you open the printer model/category and all the cartridges that fit can be listed.
For this to work perfectly you would need any matching categories from the search to be displayed in a separate results box.
Not sure how easy this would be to do? but I know for sure that loads of sites would find it very useful.

Cheers Mark



Sat May 19, 2012 10:13 pm
Location - UK

Post by NMB123 » Sun May 20, 2012 12:06 am

I have also been looking for this mod. which is essential for me.
If anyone can resolve this you will be helping many in the OpenCart Community, I’ll also throw in a great hosting package for a year at a value of £90 / 140$USD It has unlimited webspace, usage, email, etc. it also has OpenCart along with many others pre installed with 1 click install (it’s the HomePro)

Regards John



Sat May 19, 2012 11:35 pm
Location - UK

Post by DesiDil4ever » Fri Jun 29, 2012 8:59 am

I am not a programmer but a simple user...the only thing I could figure that resembled ur needs would be in category.php & category.tpl files....take a look it has exactly what u r looking for....try altering that code



Fri Jun 22, 2012 7:27 am

Post by sulletf » Wed Apr 17, 2013 9:17 pm


It's been a while since your comments but are you still interested in a solution to your problem ?




Wed Apr 17, 2013 9:13 pm

Post by Hichamb1987 » Sat May 11, 2013 5:41 pm


still having problems with this issue (posted above).

I also would like to search for products, however in my store the products are linked to the categories and customers ussualy are familiair with the category rather than the productname. Is it possible to show results (products) just by searching with the categoryname.




Sat May 11, 2013 5:38 pm

Post by PaulD123 » Wed Oct 16, 2013 9:56 pm

This might help, had the same thing today.

Using the search sql from the getCategories in the category model I added a WHERE clause to have 'LIKE = $search", then used that in the search controller (I know I should have put it in a model really) and then used the $search collected on that page, put the results in an array called cats and passed that to the search template. You can then format it how you like.

It looked like this in the search controller after the first if($search) : around line 203

// my bit added
// copied from category model
$sql = "SELECT * FROM oc_category c LEFT JOIN oc_category_description cd ON (c.category_id = cd.category_id) LEFT JOIN oc_category_to_store c2s ON (c.category_id = c2s.category_id) WHERE cd.language_id = '1' AND c2s.store_id = '0' AND LIKE '%".$search."%' AND c.status = '1' ORDER BY c.sort_order, LCASE(";

$query = $this->db->query($sql);
$categories = $query->rows;

$cats = array();
$i = 0;
// run through collected data to create links for page
if ($categories) {
foreach ($categories as $cat) {
$cats[$i]['name'] = $cat['name'];
$cats[$i]['link'] = $this->url->link('product/category', 'path=' . $cat['category_id']);
$this->data['cats'] = $cats;
} else {
// set to false if nothing found
$this->data['cats'] = false;

// my bit end

and then you can use it however you like in the search template: I did it like this:

<?php // my bit ?>
<?php if ($cats) { ?>

// loop through all the cats returned and output however you want
<?php foreach ($cats as $cat) { ?>
<li style="display: inline; padding: 8px;"><a href="<?php echo $cat['link']; ?>"><?php echo $cat['name']; ?></a>&nbsp;</li>
<?php } ?>

<br style="clear: both;" />
<hr />

<?php } else { ?>
// this should really be read from a language file
<div class="content">There are no categories that match your search criteria.</div>
<?php } ?>

Warning: I hardcoded the language I was using and the store ID as I only have English and one store. But to put them back in just go to the scategories model and put the 'get db config' and language and store config stuff and put them back in. the only change was the adding of the WHERE clause for the search term.

It worked! Da Daa - I love opencart!!!!!

Hope that helps somewhat.


PS It all looks a bit untidy here but I only have 2 mins left before I have to go. However if you need any help I will try if I can but I am not a 'hard-core' programmer by any means. Just post here and if I can help i will.



Tue Jul 05, 2011 11:58 pm

Post by alarsdes » Sat Jul 02, 2016 1:26 am

I am looking for category in search result for opencart 2.0.31
Could you help me

I bought an extention that should do the work, but that extention is not working.
Hope you can help me

Active Member


Thu Aug 25, 2011 3:36 pm
Who is online

Users browsing this forum: No registered users and 7 guests