Model/SKU unique check

Posts: 13
Joined: 04/11/2008

Hi all

I'm having fun setting up Ubercart Smiling

I'm testing out product entry for the store i'm creating and it seems that while SKU's should be unique there is no actual check to enforce this.

Ideally i'd like it so if you enter a duplicate sku than the form fails the validation check.

Is this possible or has anyone worked on this before?

Thanks

Ben

Posts: 1139
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

That's a great idea for a patch. I think it'd be easy to use hook_form_alter to intercept the validate part of the form submission process, but to be honest this is something I've actually experienced an issue with myself. I accidentally gave a new product the previous product's SKU (instead of increasing it by 1). This caused some headaches when we started selling the product - which included File Downloads. Going back and correcting the orders that had already been completed proved to be a cause for headaches.

Had the SKU not been duplicated in the first place it would've saved me some time Smiling

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 54
Joined: 08/08/2007

Very good idea. A client of mine uses the node id as part of the SKU like so: 3020-000461 where 461 is the nid. It would be nice if UC could pre-populate the SKU field for a new product according to some scheme entered in the shop configuration. But probably that's not possible using the nid because it's not defined before the new product has been saved...

Posts: 13
Joined: 04/11/2008

I've been looking at the uc_product.module and it seems the most obvious place to add the validation routine would be in the uc_product_validate function on line 614.

The CCK related Unique Field module might prove a useful reference too.

Posts: 4368
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

fwiw, I'm not sure a change to this should go into core in a release candidate. It can very easily be made into a contributed module using hook_nodeapi(), though.

Posts: 79
Joined: 08/09/2007
Bug Finder

You can try the auto_sku module, it might help.
http://www.ubercart.org/contrib/4307

--

Biodiesel * (ubercart + drupal) = Sundays Energy

Posts: 13
Joined: 04/11/2008

I took a look at the auto_sku module above and it gave me the inspiration to do the unique sku module

http://www.ubercart.org/contrib/4312

So thanks webmasterkai!

I'm not sure if the two modules will work together though, as it will depend which gets fired first on validation.

Posts: 63
Joined: 04/16/2008
Cool profile pic award.

Thanks for the contribution I am going to install and test it. Ultimately I think unique SKU checking should be a part of core.