1

How I can include Commerce SKUs in search result?

I am using “Search API and Search API Solr” modules.

Any suggestions?

  • 1
    Include them as in show them in the results listing or include them as in, allow for them to be used as search criteria? – nvahalik Jan 25 '16 at 12:02
0

Add a field or attribute to your index

Most likely, you need to add the SKU field to your index. Since most search api implementations of Commerce index display nodes AND their connected products, you will need to use: https://www.drupal.org/project/commerce_search_api for connecting referenced product properties with your display nodes.

Then, you will need to add the SKU field to your product display index. A good step-by-step for this is here (search for "define index fields" on the page): http://www.webwash.net/drupal/tutorials/intro-search-api-part-1-how-create-search-pages

Add an indexed field or attribute to search results

Finally, if you want to managed the fields that appear in search results, you will need to modify the view and/or the display mode being used to render the results.

Commerce allows "field injection" for display nodes that allow you to inject default product properties on display. But note that if you search for "Red Shirt" and the display node that has this product is by default "Blue Shirt" then, when that node is rendered, it's likely going to render the "Blue" and not "Red" SKU.

Probably need to create a hook_form_alter() that can determine if the add to cart form is being generated inside search results and trying to make it understand which SKU should be a part of the result.

  • Thank you for your response. In my case I am using search API module. I am indexing all nodes and I am able to display result by using view as Indexed content. Then I made another Index commerce product. How I can display or include commerce product in display view. I am not having any relationship between nodes/content type and commerce products. But I need to display commerce product as well. Please help me out. – Alok Jain Feb 1 '16 at 9:48

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.