I´m using Commerce on my Online-Shop, but I having some difficulties with the standard search provided by Drupal.

It´s just impossible to search by the SKU for products (for visitors) with the standard Search, given by Drupal.
I guess, the SKU-field is just not getting indexed. Does there exist a module or a patch, that could help me, to let the SKU-Field of commerce being indexed?

Thanks for any help,


AxelStoll’s picture

I´ve found this thread: https://drupal.org/node/1929780 incl. this screenshot: http://cl.ly/image/1h0L3m000l1K

I guess, this could be the solution. But... frankly - I´m very new to commerce. Where can I find this option?

nicoz’s picture

Core search leaves a lot to be desired. I would recommend using the search API, search API database, fuzzy search and search pages modules for a more enhanced search experience. You can pull and index any fields on any entity and even weight each field for relevance. It takes a bit more to get up and running but is worth it in the long run.

FMB’s picture

You could implement hook_node_update_index() in a module this way:

 * Implements hook_node_update_index().
 * Reference product SKUs.
function mymodule_node_update_index($node) {
  $product_display_types = commerce_product_reference_node_types();
  if (isset($product_display_types[$node->type])) {
    $wrapper = entity_metadata_wrapper('node', $node);
    $skus = '';
    foreach ($wrapper->field_produit->getIterator() as $product_wrapper){
      $skus .= ' ' . $product_wrapper->sku->value();
    return $skus;

Just replace mymodule and field_produit by the actual names of your module and your product reference field; requires Entity API, which is already a dependency of Drupal Commerce anyway. You will have to rebuild your search index.

kruser’s picture

@FMB This snippet is awesome. Thanks for sharing.

Bob @ Drupal Aid (https://www.drupalaid.com)

thaistore’s picture

can somebody build a module please, I am too stupid to use this snipet code

Drupal webdesign - regular sites and ubercart ecommerce sites
Drupal webdesign

nicoz’s picture

Can somebody build a module please, I am too stupid to use this snipet code

There is a module. Search API. I mention it above.