Post by 0li4tw » Fri Oct 25, 2013 10:17 pm

Hello all,
v1.5.3.1

I am trying to find a way to include products options in the search results on my store. Here is my problem:

http://www.rosemaryandco.com/mh-oils-series-1

As you can see this product has many options assigned to it, and many customers are typing the colour to find it rather than the name of the product. I know an obvious solution is to create each colour as an individual product but this seems long winded. I have also found that adding product tags named as each colour makes the product appear in searching but this seems a dirty way of doing it.

Does anybody know of a way to solve this? I don't mind doing the research by looking into the core if someone can point me in the right direction.

Many thanks,
Oli

New member

Posts

Joined
Wed Jun 06, 2012 8:21 pm

Post by agristar » Thu Mar 27, 2014 5:04 pm

I am looking fo the same feature.

How have you done it?

Newbie

Posts

Joined
Mon Oct 29, 2012 6:10 pm

Post by melbagnato » Fri Mar 28, 2014 5:36 pm

Hi agristar,

you can do this, but the solution is version independent as search changed a bit over the OpenCart versions.

For version 1.5.3.1, you would need to modify the "getProducts()" function in "\catalog\model\catalog\product\".

For example, if originally the search string was:

Code: Select all

"SELECT 
	p.product_id, 
	(SELECT AVG(rating) AS total 
		FROM oc_review r1 
		WHERE r1.product_id = p.product_id 
		AND r1.status = '1' 
		GROUP BY r1.product_id) AS rating 
	FROM oc_product p 
		LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id) 
		LEFT JOIN oc_product_to_store p2s ON (p.product_id = p2s.product_id) 
		LEFT JOIN oc_product_tag pt ON (p.product_id = pt.product_id) 
	WHERE 
		pd.language_id = '1' 
		AND p.status = '1' 
		AND p.date_available <= NOW() 
		AND p2s.store_id = '0' 
		AND ( LCASE(pd.name) LIKE '%red%' 
			OR  LCASE(pt.tag) LIKE '%red%' 
			AND pt.language_id = '1') 
		GROUP BY p.product_id 
		ORDER BY p.sort_order ASC, LCASE(pd.name) ASC 
		LIMIT 0,15"
You would need it to look like this:

Code: Select all

SELECT 
	p.product_id, 
	(SELECT AVG(rating) AS total 
		FROM oc_review r1 
		WHERE r1.product_id = p.product_id 
		AND r1.status = '1' 
		GROUP BY r1.product_id) AS rating 
	FROM oc_product p 
		LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id) 
		LEFT JOIN oc_product_to_store p2s ON (p.product_id = p2s.product_id) 
		LEFT JOIN oc_product_tag pt ON (p.product_id = pt.product_id) 
		LEFT JOIN oc_product_option po ON (p.product_id = po.product_id) 
	WHERE 
        pd.language_id = '1' 
	AND p.status = '1' 
	AND p.date_available <= NOW() 
	AND p2s.store_id = '0' 
	AND ( LCASE(pd.name) LIKE '%red%' 
		OR  LCASE(pt.tag) LIKE '%red%' 
		OR  LCASE(po.option_value) LIKE '%red%'
		AND pt.language_id = '1') 
	GROUP BY p.product_id 
	ORDER BY p.sort_order ASC, LCASE(pd.name) ASC 
	LIMIT 0,15
This will show you all products that have an option value of "red".

If you need this done for you, let me know.

- Mel

http://online.enterpriseconsulting.com.au

Site with OpenCart extensions & code downloads, many new extensions coming soon!
Follow us on twitter for more updates

Image


User avatar
Active Member

Posts

Joined
Wed Jan 13, 2010 1:39 pm
Location - Melbourne

Post by Johnathan » Fri Mar 28, 2014 11:01 pm

Smart Search can do this, if you don't want to modify core files yourself. Otherwise, I would recommend using product tags like you suggested, rather than changing the MySQL queries, unless you really know what you're doing.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am

Who is online

Users browsing this forum: No registered users and 1 guest