Hello -

I need to make it so the SKU for a product gets added into the drupal search index, so that a user can search by Item Number (SKU) in the search box. I believe that just the correct hooks need to go into the product module to accomplish this, but I'm not sure.

I am looking for bids on time and cost for this small task.

contact me throught my form.
Thanks!

Comments

iandickson’s picture

If you have the Search option configured (using cron or poormanscron) right then I would have thought that the indexer would pick it up on each run. In which case all you need is the internationalisation stuff to allow you to define your own text for mods and you can change Search to "Search - text or SKU" to help users.

If I'm right and you want to reward me, drop me a line :-)

Ian Dickson - community specialist.
www.emint.org - Association of Online Community Professionals
www.iandickson.com/taxonomy/drupal/ - Taxonomy Server Project - generic, organic, standards compliant, directed graph based, ass kicking taxonomy

iandickson’s picture

just tried it,inc min word count of 1.

gravit’s picture

Hi ian - Thanks for the feedback - Unfortunately it doesnt seem ecommerce does this out of the box. Looking into the search_index hooks in the API is a little beyond me so I was hoping someone might have a simpler solution.

japerry’s picture

The simplest idea I found was to just make a SKU item in the CCK. It is duplicating work, but a simple copy/paste from one text field only takes about 5 seconds more to do. It'd be good to get a solution to fix this, however, its probably quicker to make a text field. You could even implement a cron script to copy the sku into the text field box.

gravit’s picture

Thanks Jakob -

but unfortunately, as you already know... I am not using CCK for my products, just the default product node. :-)

Good to find you on the forums.

kingandy’s picture

Apparently this functionality is standard as of Ecomm 4+, but I thought it would be worth noting our workaround for people who, like ourselves, are fearful of change and progression.

Create an ec_searchsku folder in your modules directory (usually sites/all/modules).
Within this folder create two files:

ec_searchsku.info

dependencies  = store search
description   = "Add SKU to the search index."
package       = "E-Commerce Uncategorized"
name          = "Search SKU"

and
ec_searchsku.module

function ec_searchsku_nodeapi(&$node, $op, $a3, $a4) {
  if ($op == 'update index' && $node->sku) {
    return 'Product code: '.$node->sku;
  }
}

Then to actually trigger the index update, you'll have to go to admin/settings/search and hit the 're-index content' button - then wait until Cron has fired enough times to index the site (or visit admin/logs/status and Run Cron Manually until the search page displays 100%.

It really is that simple :)

(Unless somebody says otherwise...)

--Andy

++Andy

tmandava’s picture

Andy, thanks for this workaround. It's a simple and great solution till we are ready to upgrade.

hassansr’s picture

will this search function (similar) work for ubercart?

hassansr’s picture

simplest solution that I found was to add the sku to the product name and use the search feature in views bulk operations to find the product where the name includes the sku number

for instance: Tire size 12, with sku 123 becomes 112 - Tire size 12

this works well just as long as the person doing the searching is not a customer or if as admin you dont activate a bulk operation

kingandy’s picture

Honestly I would have expected Ubercart to incorporate SKU indexing into their code, they're usually quite thorough. Oh well.

The code should technically work - BUT - be aware that Ubercart stores its SKU on a 'model' property instead of 'sku'. So that part of the code will have to change, at least. Also note that it's a Drupal 5.x module, there are a few changes that will need to be made if you want it to work with Drupal 6.x or higher (at the very least the .info file will need a 'core = 6.x' declaration).

I'm about to try to implement a variant of this, so will try and let you know how it comes out.

EDIT: Yes, switching '$node->sku' to '$node->model' (and 'store' to 'uc_store' in the .info file) worked fine. I also added a .install file with a hook_install that calls search_wipe(), but that's because I'm a perfectionist...

++Andy

drupalfever’s picture

Create an uc_search_model folder in your modules directory (usually sites/all/modules).
Within this folder create two files:

uc_search_model.info

; $Id$
name = Ubercart Search Model Number
description = This module will include the Ubercart Model Number to the Drupal search indexing.
core = 6.x
package = Other
dependencies[] = search

and
uc_search_model.module

function uc_search_model_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if (($op == 'update index')
  && ($node->build_mode == NODE_BUILD_SEARCH_INDEX)
  && ($node->model)) {
    return 'Product model: ' . $node->model;
  }
}

After creating the above files, go to "admin/build/modules" and enable your new module. The name of your new module is "Ubercart Search Model Number".

Now, the next time that cron runs on your server, your product nodes are going to be re-indexed with their respective SKU (Model) numbers.