How I can include Commerce SKUs in search result?
I am using “Search API and Search API Solr” modules.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
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.