Post by SiteE@se » Thu Apr 16, 2009 9:15 pm

Not quite sure where to look to change code so that Search also looks at data included for a product's model (still finding my way around v1.x). Can anyone point me in the right direction?

Thanks, folks :)
Last edited by i2Paq on Sun Feb 21, 2010 7:06 pm, edited 1 time in total.
Reason: Topic title adjusted + moved

Active Member

Posts

Joined
Mon Dec 17, 2007 7:40 am
Location - UK

Post by phpuk » Fri Apr 17, 2009 1:14 am

Hi,

Open: catalog/model/catalog/product.php

Replace line 81:

Code: Select all

$sql .= " AND pd.name LIKE '%" . $this->db->escape($keyword) . "%'";
with:

Code: Select all

$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";
and line 117:

Code: Select all

$sql .= " AND pd.name LIKE '%" . $this->db->escape($keyword) . "%'";
with:

Code: Select all

$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";
There you go. You should now be able to search by product model as well as product name straight from the keyword search.

Daniel:
Can you please add this to the core so we can use it in replace of SKU as it was decided not to add SKU functionality.

Phil.

Global Moderator

Posts

Joined
Wed Mar 25, 2009 10:57 am

Post by SiteE@se » Fri Apr 17, 2009 3:58 am

phpuk wrote:Hi,

There you go. You should now be able to search by product model as well as product name straight from the keyword search.

Daniel:
Can you please add this to the core so we can use it in replace of SKU as it was decided not to add SKU functionality.

Phil.
Many thanks, Phil. Can I second your request to Daniel?

Chris

Active Member

Posts

Joined
Mon Dec 17, 2007 7:40 am
Location - UK

Post by maddog986 » Fri Apr 17, 2009 5:21 am

x3 on the request!

New member

Posts

Joined
Fri Apr 03, 2009 5:25 am

Post by aniketvsawant » Wed Aug 12, 2009 8:35 pm

Hi Daniel,

Can you please add / post the functionality to integrate the SKU number with product details in current opencart 1.5.14

Thanks in advance.

Newbie

Posts

Joined
Wed Aug 12, 2009 3:02 pm

Post by Qphoria » Wed Aug 12, 2009 8:56 pm

1.5.14? Are you sure you're running OpenCart?

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by aniketvsawant » Thu Aug 13, 2009 7:52 pm

oh sorry, i apologies, the version is 1.2.9....

Newbie

Posts

Joined
Wed Aug 12, 2009 3:02 pm

Post by jlg89 » Wed Aug 19, 2009 5:30 am

Yes! Full search across all product fields should be the default, optimally with administrative and/or user-level capability of limiting the search to certain fields. Please incorporate this into the core.

New member

Posts

Joined
Tue Aug 04, 2009 11:32 am

Post by jfima » Wed Nov 18, 2009 3:26 am

howto for version 134
Open: catalog/model/catalog/product.php

Replace code block for methods getTotalProductsByKeyword, getProductsByKeyword:

Code: Select all


if (!$description) {
				$sql .= " AND pd.name LIKE '%" . $this->db->escape($keyword) . "%'";
			} else {
				$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%')";
			}
with code:

Code: Select all

if (!$description) {
				$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";
			} else {
				$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";
			}
There you go. You should now be able to search by product model as well as product name straight from the keyword search.

Daniel:
Can you please add this to the core so we can use it in replace of SKU as it was decided not to add SKU functionality.

Newbie

Posts

Joined
Wed Nov 11, 2009 12:55 pm

Post by electron » Sat Feb 20, 2010 11:40 pm

Nice one!

I managed to get it work with SKUs as well by adding p.sku, don't know what it means but decided to try and it worked like a charm...

Code: Select all

if (!$description) {
            $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%' OR p.sku LIKE '%" . $this->db->escape($keyword) . "%')";
         } else {
            $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%' OR p.sku LIKE '%" . $this->db->escape($keyword) . "%')";
         }
Thanks!

Newbie

Posts

Joined
Wed Feb 17, 2010 10:01 pm

Post by tilesupply » Thu Mar 25, 2010 2:07 am

Can anyone help me get this to work on 1.44.
I had it working on 1.40.

Many Thanks
jfima wrote:howto for version 134
Open: catalog/model/catalog/product.php

Replace code block for methods getTotalProductsByKeyword, getProductsByKeyword:

Code: Select all


if (!$description) {
				$sql .= " AND pd.name LIKE '%" . $this->db->escape($keyword) . "%'";
			} else {
				$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%')";
			}
with code:

Code: Select all

if (!$description) {
				$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";
			} else {
				$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";
			}
There you go. You should now be able to search by product model as well as product name straight from the keyword search.

Daniel:
Can you please add this to the core so we can use it in replace of SKU as it was decided not to add SKU functionality.

Active Member

Posts

Joined
Wed Aug 26, 2009 7:48 am


Post by tilesupply » Sun Apr 04, 2010 7:14 am

Can anyone help with this please for OC1.46

Active Member

Posts

Joined
Wed Aug 26, 2009 7:48 am


Post by yrshopping » Mon Apr 05, 2010 5:02 pm

I just install the model in search of v.1.3.4, however some model: can't search it, some can, if the number too old, so can't search it. so can you help me advise and how can I do it? thank you.

b.rgds
David Wei
yrshopping.com

New member

Posts

Joined
Wed Aug 12, 2009 12:42 pm

Post by djdaca » Tue Jun 08, 2010 9:00 am

its simple, in opencart 1.4.7 u cannnot replace any module or controller functions.

in tamplate catalog/view/theme/default/template/common/header.php
are javascript function:

Code: Select all

function moduleSearch() {
	url = 'index.php?route=product/search';
	var filter_keyword = $('#filter_keyword').attr('value')
	if (filter_keyword) {
		url += '&keyword=' + encodeURIComponent(filter_keyword);
	}
	var filter_category_id = $('#filter_category_id').attr('value');
	if (filter_category_id) {
		url += '&category_id=' + filter_category_id;
	}
	
	location = url;
}
U can modify this function only like this:

Code: Select all

function moduleSearch() {
	url = 'index.php?route=product/search';
	var filter_keyword = $('#filter_keyword').attr('value')
	if (filter_keyword) {
		url += '&keyword=' + encodeURIComponent(filter_keyword) + '&model=1';
	}
	var filter_category_id = $('#filter_category_id').attr('value');
	if (filter_category_id) {
		url += '&category_id=' + filter_category_id;
	}
	
	location = url;
}
if u search without javascript u can add to form:
<input type="hidden" name="model" value="1" />

Thats all.

Ten kdo mě zná - ten ví, kdo mě nezná ten mě pozná a bude dělat že mě nezná jako ti co mě znají.


User avatar
Newbie

Posts

Joined
Mon May 31, 2010 7:03 pm
Location - Prague/Czech Republic

Post by miradoro » Thu May 12, 2011 12:26 am

Hi

can you guys help me search model on default search for opencart 1.4.9.4 ?

New member

Posts

Joined
Tue May 03, 2011 9:43 pm

Post by hmignon » Mon Jun 27, 2011 11:21 pm

Dear is there an update for the latest version of opencart ?

Thx

Newbie

Posts

Joined
Mon Jun 27, 2011 11:20 pm

Post by uksitebuilder » Fri Jul 01, 2011 4:30 am

Check my sign for a 1.5.0 Improved Search

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by fbas » Wed Jul 06, 2011 2:59 am

hmignon wrote:Dear is there an update for the latest version of opencart ?

Thx

for 1.5.0.x (1.5.0.5 on my system)

file: ${opencart}/catalog/model/catalog/product.php
lines 67-73, add something to catch model (the "OR p.model LIKE" part, on the lines 69 and 71)

Code: Select all

		if (isset($data['filter_name']) && $data['filter_name']) {
			if (isset($data['filter_description']) && $data['filter_description']) {
				$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%' OR p.product_id IN (SELECT pt.product_id FROM " . DB_PREFIX . "product_tag pt WHERE pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.tag LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%') OR LCASE(pd.description) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%' OR LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%')";
			} else {
				$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%' OR p.product_id IN (SELECT pt.product_id FROM " . DB_PREFIX . "product_tag pt WHERE pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.tag LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%') OR LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%')";
			}
		}
there are similar queries constructed on lines 385 and 387 that perhaps should be changed too? function getTotalProducts()

Newbie

Posts

Joined
Fri Jul 01, 2011 2:58 am

Post by DJB31st » Sun Aug 28, 2011 6:52 pm

fbas's reply works great in the latest version v1.5.1.1

However in order to ensure that pagination and product counts work you do need to alter the SQL for the function getTotalProducts()

Cubecart to Opencart Migrations

KashFlow Accounting Integration with OpenCart


Newbie

Posts

Joined
Wed Jul 13, 2011 7:19 pm

Post by werepair » Fri Sep 02, 2011 4:20 pm

hi, i would also like the site to have a sku search added i am running 1.5.1, most people visiting my site search by sku number and not just by product name.

User avatar
Active Member

Posts

Joined
Sat May 28, 2011 2:54 pm
Location - United Kingdom
Who is online

Users browsing this forum: No registered users and 4 guests