3

I am associating my products with categories in Magento, and I'd like to modify the basic search so that products from category names that match the search query are included in the results.

Is there a buried option that allows that? Category is not an attribute as such, and I can't find an option in each category to include in search.

  • Is problem solved ? – inrsaurabh Jun 9 '18 at 16:11
0

You should change native magento CatalogSearch Indexer. Need add category name to data_index column.

As I know, this feature implemented in few search extensions, like https://mirasvit.com/magento-extensions/magento-sphinx-search.html

0

There is no out of the box way of doing this, but you can trick magento into doing this.
You can create a hidden attribute called category_names that is seachable but not displayed in the frontend.
Then create an observer for the catalog_product_save_before where you take all the category names from the associated categories and place them in this field.
Something like this (untested):

public function setCategoryNames($observer)
{
    $product = $observer->getProduct();
    $categoryIds = $product->getCategoryIds();
    $storeId = $product->getStoreId();
    $categories = Mage::getModel('catalog/category')->getCollection()
                ->setStoreId($storeId)
                ->addAttributeToFilter('entity_id', $categoryIds)
                ->addAttributeToSelect('name');
    $names = array();
    foreach ($categories as $category) {
        $names[] = $category->getName();
    }
    $product->setCategoryNames(implode(' ', $names));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.