Page 1 of 1

[1.4.0] Products appear multiple times when searching

Posted: Mon Feb 01, 2010 1:38 pm
by Johnathan
In 1.4.0, If you search "All Categories" for a product that has multiple category designations, it brings up the products multiple times. For an example, see this search for "Macbook Air" on the demo version:

http://demo.opencart.com/index.php?rout ... egory_id=0

I think it has something to do with the getTotalProductsByKeyword function in /catalog/model/catalog/product.php, but I'm not sure. Can someone with more know-how provide a fix? It certainly makes the search less useful when products appear three or four times in a row.

Re: [1.4.0] Products appear multiple times when searching

Posted: Mon Feb 01, 2010 2:27 pm
by Qphoria
Confirmed.

One Solution (tho maybe not the best):

1. EDIT: catalog/model/catalog/product.php

2. IN THE getProductsByKeyword() FUNCTION, FIND:

Code: Select all

return $query->rows;
3. REPLACE WITH:

Code: Select all

return array_unique($query->rows);
Doesn't fix the count, but only returns one.

Re: [1.4.0] Products appear multiple times when searching

Posted: Mon Feb 01, 2010 4:34 pm
by allenshea
Thanks Q, But what if this KEY WORD has some similar items.

If I replace with your change, I can only search for 1 result. What about the similar items?

Anyone who can find the solution. Thanks!

Allen

Re: [1.4.0] Products appear multiple times when searching

Posted: Tue Feb 02, 2010 4:05 am
by Johnathan
I found a fix, if you don't mind not allowing searching by category. (I had already disabled that, so it works well for me.) Delete the instances of the following piece of code in both getProductsByKeyword() and getTotalProductsByKeyword():

Code: Select all

 LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)
There's three instances of that line in the file (one more in getProductsByCategoryId() ) so be sure not to do just a find-and-replace if you want that function working correctly.

Re: [1.4.0] Products appear multiple times when searching

Posted: Tue Feb 02, 2010 4:25 am
by Qphoria
allenshea wrote:Thanks Q, But what if this KEY WORD has some similar items.

If I replace with your change, I can only search for 1 result. What about the similar items?

Anyone who can find the solution. Thanks!

Allen
it should only removes unique items of the exact same id.
So you can have "Apple Monitor" and "Apple Ipod" and if you have monitor in 3 categories and ipod in 2 categories, it should still only return 1 monitor and 1 ipod

-EDIT-
Ah, i see it does not. Ok then... don't use that code. It should probably e done at the db level anyway

Re: [1.4.0] Products appear multiple times when searching

Posted: Wed Feb 03, 2010 9:26 pm
by SSJ