Latest Articles
So far this was never an issue, there were problems with uploading modules via the installer because of the ftp connection but you could allways install ocmods without any issue. However, some .. Read More
People had this issue so many times I thought I would write a bit about it. The  types of issues with opencart's 2.x modification system that I identified so far are: 1. Old Vqmod .. Read More
This small tutorial will show you how to manually add custom links to the default top menu in opencart. If you dont want to go trough all the hustle and would like to be able to completly customize.. Read More
To enable seo urls in opencart navigate in admin to system > settings , edit the store and on the server tab of the store settings you will find "Use SEO urls", set it to yes. So far e.. Read More
All Articles

How to search by product code in opencart 1.5.2.x

By default the opencart search only works for product name and if selected, it also searches in the product description.

If you want the search to also work for the product code (model), here are the modifications you need to make in order for it to work.

Edit the file catalog/model/catalog/product.php and 2 times you will find this code:

foreach ($words as $word) {
if (!empty($data['filter_description'])) {
$implode[] = "LCASE( LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%' OR LCASE(pd.description) LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%'";
} else {
$implode[] = "LCASE( LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%'";

and both times, replace it with the following code: 

foreach ($words as $word) {
if (!empty($data['filter_description'])) {
$implode[] = "LCASE( LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%' OR LCASE(pd.description) LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%' OR LCASE(p.model) LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%'";
} else {
$implode[] = "LCASE( LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%' OR LCASE(p.model) LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%'";

And that is all, now the search function will also work for product code.

Posted by Flo

Related Articles

Many people ask about the setting on how many products are beeing displayed per row in opencart modules or category listings. Well there is no such setting, I mean there might be in some custom themes but now Im reffering strictly to the opencart default theme. The number of products displayed per row is influenced by the width of the individual product box which is set in the stylesheet.css of the default theme (catalog/view/theme/default/stylesheet/stylesheet.css). Change the number of products per row for modules display (Like latest, Featured, Bestsellers):  In stylesheet.c..
6 comments on this article - view comments

15 Comments To "How to search by product code in opencart 1.5.2.x"

ali On 10 Oct 2014
Thumbs up man , its works like charm , :) Reply to this comment
Kee On 31 Oct 2013
You are a star............................! Reply to this comment
Milos On 05 Sep 2013
Thank you very much for your help. Reply to this comment
Flo On 16 Nov 2012
You select the category from the dropdown on the search page Reply to this comment
Dawood Khan On 16 Nov 2012
How to search by category name in default Reply to this comment
zura On 04 Nov 2012
How to search by product attributes? please help someone. I have 6 attributes and the important information is in this attributes. how to search in this information? all of attributes are in ocproduct_attribute string 'text' Reply to this comment
Arif Shaik On 17 Oct 2012
Thank you for this it works great..! i am looking for search on product model please help for that..i am using OC 1.5.3x Reply to this comment
Gareth Williams On 03 Oct 2012
I've created a vqmod for the above and it's available here:- Reply to this comment
Ross On 02 Oct 2012
Thanks, great bit of code. It would be even better if someone could write a vqmod for it :-) Reply to this comment
simon On 19 Sep 2012
thank you !!! just what i needed, working great Reply to this comment

Write a comment

Your Name:

Enter the code in the box below:

Your Comment:
Note: HTML is not translated!