Jump to content

How to made Search results appears category name?


istox

Recommended Posts

istox,

 

Search::find is responsible for Prestashop search. So if you want a category to be taken into search account, you need to use this parameter.

 

If you look at the following function and its parameters, you will notice that the category is not considered.

public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false, $useCookie = true)

 

However, you can expand this class, adding the category.

 

$result = $db->ExecuteS('

SELECT cp.`id_product`

FROM `'._DB_PREFIX_.'category_group` cg

INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category`

INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category`

INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`

WHERE c.`active` = 1 AND p.`active` = 1 AND indexed = 1

AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (

SELECT id_group FROM '._DB_PREFIX_.'customer_group

WHERE id_customer = '.(int)$id_customer.' AND cp.`id_category` = '.(int)$id_category.'

)'), false);

 

AND cp.`id_category` = '.(int)$id_category.' is responsible for category recognizing here.

 

 

 

Regards,

BelVG Team

[email protected]

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

@Irinia

 

I followed what you noted, but searches still yield no matches on the category name. To be clear, I am trying to simply have the search do something like this:

 

WHERE product_name LIKE %keyword% OR category_name LIKE %keyword%

 

I know the above is a simple reference, but it shows what I am trying to make the front end search for products accomplish.

 

I am new to PrestaShop and did not see in the query logic of the search class where I might make the above changes.

 

Any further suggestions?

 

Thanks.

 

Maxx

Link to comment
Share on other sites

  • 2 years later...

Thank you!

 

istox,

 

Search::find is responsible for Prestashop search. So if you want a category to be taken into search account, you need to use this parameter.

 

If you look at the following function and its parameters, you will notice that the category is not considered.

public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false, $useCookie = true)

 

However, you can expand this class, adding the category.

 

$result = $db->ExecuteS('

SELECT cp.`id_product`

FROM `'._DB_PREFIX_.'category_group` cg

INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category`

INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category`

INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`

WHERE c.`active` = 1 AND p.`active` = 1 AND indexed = 1

AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (

SELECT id_group FROM '._DB_PREFIX_.'customer_group

WHERE id_customer = '.(int)$id_customer.' AND cp.`id_category` = '.(int)$id_category.'

)'), false);

 

AND cp.`id_category` = '.(int)$id_category.' is responsible for category recognizing here.

 

 

 

Regards,

BelVG Team

[email protected]

 

I can't get it. Could you help me? I'm using PS 1.6.0.8

Link to comment
Share on other sites

Hi Alvarosc,

 

can you explain your issue a little bit more?

 

Regards

 

Hi Alex,

 

Thank you for your answer.

 

I have located the code she provided in my files. My problem is I don't know what to add or how to put those results (category name, url ...) to display on the web. I mean, I don't really know how I should start  :wacko:

 

Thanks :)

 

Regards

Link to comment
Share on other sites

First of all you need to understand whole request flow for search process. Irina meant search::find() method is the main part of this flow. You need to override this logic and add once more check. So in your case you need to check category of product directly in SQL-query. If you needs to check multiple categories for the same product, you can use static method (Product::getProductCategories($id_product))

 

Regards

Link to comment
Share on other sites

First of all you need to understand whole request flow for search process. Irina meant search::find() method is the main part of this flow. You need to override this logic and add once more check. So in your case you need to check category of product directly in SQL-query. If you needs to check multiple categories for the same product, you can use static method (Product::getProductCategories($id_product))

 

Regards

Hi

 

Thanks you for your response. I don't want to find products, I just want what maxxmann mentioned. I'm looking for something like this (in basic logic): WHERE product_name LIKE %keyword% OR category_name LIKE %keyword%, and then show the categories that matches with the seacrh.

 

I know I have to change the SQL-Query to add a new parameter. My problem is I don't know exactly what I have to change and I have to do it. I tried some changes in a shop I have in a local machine but I can't find it :S

 

Regards :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...