Jump to content

How to have search include every category allocated for a product ?


Recommended Posts

Hi,

It seems that the search feature only considers the default category when matching against the search text. I would like to match all products that are within any category that matches the search text.

Is this possible with Prestashop 1.2.5 ?

If it is not possible is there anyone interested in providing this feature ?

Regards,
Mark

Link to comment
Share on other sites

  • 2 weeks later...

I've attempted to implement this, here is what I changed in 1.2.5:

In Search.php

added:

   public static function getCategories($db, $id_product, $id_lang)
   {
           $categories = '';
               $categoriesArray = $db->ExecuteS('
       SELECT `id_category`
       FROM `'._DB_PREFIX_.'category_product`
       WHERE `id_product` = '.intval($id_product));
       foreach ($categoriesArray as $category) {
               $c = new Category($category['id_category'], intval($id_lang));
           $categories .= Category::hideCategoryPosition($c->name) . ' ';
               }
       return $categories;
   }



In the public static function indexation

added to the setting of $weightArray :

'categories' => Configuration::get('PS_SEARCH_WEIGHT_CNAME')



after the line:

$product['features'] = self::getFeatures($db, $product['id_product'], $product['id_lang']);



added

$product['categories'] = self::getCategories($db, $product['id_product'], $product['id_lang']);



Rebuild the search index from the admin page.

Regards, Mark

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...