Unique SKU

Contrib type: 
Module
Status: 
Initial upload
Compatibility: 
Ubercart 1.x
Latest version: 
0.2

Allows you to enforce Product SKUs to be unique either among the current product type/class or among all products. Returns a form validation error in case of a duplicate SKU.

Simply go to the Content type or Product class settings form for each type you want to activate this for.

I took a lot of inspiration from webmasterkai's Automatic SKU module, but i'm not sure if the two will work together or not as it depends which fires first.

This is the first attempt at this and works well for me with light testing.

Comments and suggestions welcome!

Related threads: 
AttachmentSize
uc_unique_sku.tar.gz1.75 KB

Re: Unique SKU

Looks like i found a bug or an incompatability with my server settings.

warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home1/*/public_html/sites/testing.site.com/modules/uc_unique_sku/uc_unique_sku.module on line 79.

Drupal 5.7
Configuration file Protected
Cron maintenance tasks Last run 42 min 14 sec ago
You can run cron manually.
Database schema Up to date
File system Writable (public download method)
GD library bundled (2.0.34 compatible)
MySQL database 5.0.45
PHP 5.2.5
PHP register globals Disabled
Unicode library PHP Mbstring Extension
Web server Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Sensitivity-Filter/1.0.0

Re: Re: Unique SKU

Invalid mysql resource doesn't mean server settings, it probably means there's a variable or object not getting passed to the query function correctly.

updated

I've just uploaded a new version, which should hopefully fix that issue you were having.

Would you please try again to see if it works for you?

fixed

That did the trick. Thanks.

Hi Great module, did the

Hi

Great module, did the trick for me Smiling

I've added this piece of code for suiting to my needs, so when a new product is added, the sku field is "autocompleted" whit the greatest one recorded + 1, but you can alter it if you want to use one different.

In uc_unique_sku_form_alter hook, I've added this:

  if ($form_id == 'product_node_form' AND arg(1) == 'add') {
    $sql = "SELECT greatest(max(CAST(model AS SIGNED)),max(CAST(sku AS SIGNED))) +1
FROM uc_products u
JOIN uc_product_stock us ON (u.model = us.sku)";
    $next_sku = db_result(db_query($sql));
    $form['base']['model']['#default_value'] = $next_sku;
  }

Probably this code is not product classes aware