auto generate SKU (using token module)?

Posts: 15
Joined: 09/14/2007

On a recent project, i was able to auto generate many things via hooking into the token module. I noted that it is required for ubercart - is there a way it can be hooked into to auto-generate an SKU. This could be as simple as a string of letters followed by the node-id (the only issue would be that non-product nodes would not provide for sequential numbering - product id perhaps?)

I am not sure how relevant/widespread its application would be. For the project i am working through, it would be as it is for an artist's work.

I was also thinking in terms of having different SKUs for attributes. For example, what i am trying to achieve is to have an original artwork and prints. There would only be one original (i am working though inventory control as well - stuck on both for now) and a select number of prints, if any. In this case, the prints SKU could have a -p added, for example, at the end.

Given that this would be the same for each product (artwork) i think i should be able to create a class to apply automatically for the attributes as well - this is for another thread, however - as are my current fumbling's with inventory control Eye-wink

Posts: 282
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

This is something that I am interested in. It would save the effort of store admins from having to check which is the next available model number.

I built an auto-generate model number contribution for oscommerce that queries the database for the products_id and products_image or products_name fields then constructs and inserts a configurable model number like so:

XXX-YYY-001

Where:

XXX = User defined letters (usually an acronym of the store name (such as UBT for Ubercart)).
YYY = First three letters from the products_image or products_name fields (usually gives a good idea of the actual item).
001 = The products_id ensuring each model number is unique.

The problem with using this script with Ubercart is that SKU is required to add a product.

I have been thinking a little about this and (despite not knowing much about token module) I believe your idea of using token module could be the right one. There would need to be a settings page where the format would be defined - probably something like the way pathauto handles it's url formats.

Ideally the value="" of the SKU field would be prepopulated with the auto-generated model number allowing for overriding when necessary.

Sorry I haven't got more than this to offer. I can code for oscommerce but Drupal/Ubercart is still mostly a mystery to me (have bought the pro drupal development book and am working through it though so it shouldn't be long before I can contribute more)

Posts: 203
Joined: 09/06/2007

what about hiding the field with cck permissions and then afterwards change it be checking the db which products still have sku = lame-needstobechanged ...

Posts: 282
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

I've not thought about this. Have you tried anything similar in the past that worked in this way? Is CCK permissions a module?

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

Problem with using Token, is that the SKU should be prepopulated with a node id that still doesn't exist (as the product was not yet submitted).

I'm thinking maybe there should be a configuration in UC saying "Make SKU same as Node id"

Posts: 282
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

Yes, just as long as we can get past the submit product part we could do what we like with the database. I have been adding my products as SKU = "a" and then later will format the model numbers using a script. Would be nice to have an option that made node id populate the SKU field on the submission form.

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

I'm thinking maybe there should be a configuration in UC saying "Make SKU same as Node id"

I'm confused, why would you want the SKU to be the same as the node id? Since nids are usually numbered incrementally, if you create content other than a product, your SKUs will go out of order once you start switching back and forth.

I do like the idea of having the SKU field pre-populate, but I think it should be based off an earlier SKU value. Maybe there can be a token pattern assigned for such a function. I would also be able to use different SKU patterns for different vocabs or product types. Downloadable content gets "D-###" and Shippable product gets "Prod-##-alpha" or whatever the need is.

I'm making things more complicated, aren't I? Eye-wink I'm good at that.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

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

Well, in fact I'm not using the SKU at all. My product reference is the NID. Every new NID is a new product. Having to enter manually an SKU for me (thus I assume maybe others) is not necessary.

Posts: 19
Joined: 01/13/2008

I'm still interested in an auto generated sku. As for using the node id instead, how exactly did you accomplish this and what about the downsides - e.g., a product with many attributes can no longer have those attributes distinguished or inventoried separately by their own unique sku?

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

You can check out the auto_sku module and see if it helps. Feedback welcome.
http://www.ubercart.org/contrib/4307

--

Biodiesel * (ubercart + drupal) = Sundays Energy

Posts: 13
Joined: 03/14/2008

Thanks a lot webmasterkai.

For those who, as me, were looking for config panel its collapsed under admin/store/settings/products/edit.