How to search by product code in opencart 1.5.2.x

Posted by Flo on 08 May 2012

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(pd.name) LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%' OR LCASE(pd.description) LIKE '%" . $this->db->escape(utf8_strtolower($word)) . "%'";
} else {
$implode[] = "LCASE(pd.name) 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(pd.name) 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(pd.name) 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.