Post by Johnathan » Mon Feb 01, 2010 1:38 pm

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.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Qphoria » Mon Feb 01, 2010 2:27 pm

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.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by allenshea » Mon Feb 01, 2010 4:34 pm

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

I know nothing about PHP and SQL, but I still try my best to understand it.


Active Member

Posts

Joined
Mon Dec 14, 2009 10:01 pm

Post by Johnathan » Tue Feb 02, 2010 4:05 am

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.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Qphoria » Tue Feb 02, 2010 4:25 am

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

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by SSJ » Wed Feb 03, 2010 9:26 pm


SSJ
Newbie

Posts

Joined
Wed Feb 03, 2010 1:05 am
Who is online

Users browsing this forum: No registered users and 69 guests