I have a custom field on my Product Type for brand names of the products. Im using this custom field brand name as part of my AutoSKU pattern like [commerce-product:field-brand]-[commerce-product:product-id]. Which works pretty fine.

However, some of the brand names I have are pretty long and makes the SKU way too much longer then I would like it.

Is there anyway to limit the number of characters to be used in this token? Like maybe taking the first 3 or 4 characters of the brand name field as part of the pattern?

Thanks...

Comments

paranormals’s picture

Came across AutoSKU today. Thanks for the nice simple module. I was looking for the same feature as hgurol. A way to truncate fields to keep my SKU's shorter.

rbayliss’s picture

We're dependent on token support here. There's no way I know of to shorten a token value, although you can always create your own version of the token if you've got some coding chops (http://rbayliss.net/story/tokens-drupal-7).

hgurol’s picture

Well, creating my own token is not something I can do myself.
If you can think of an easier workaround, doesn't matter how dirty it is, I would really appreciate that.

Thanks...

@paranormals
Maybe you have already came up with a workaround?

paranormals’s picture

@hgurol - I did not come up with a work around yet. Sorry.

ahillio’s picture

With fields of type "List (text)" we can specify key|label. I have list of colors dg|Dark Green and other lists built like that. Autosku's are being built with the label (Dark Green), but it'd be great if they could be build with the key (dg). Is this possible?

It sounds like this would depend on token being able to access the key?

ahillio’s picture

This can be done!
@hgurol ...4 months later, if you're still working on this... you can abbreviate your brand names this way:

  • set your brand field's type as list (text) ...not sure if other field types will work
  • edit that field and under the allowed values list do something like "abn|Abbreviated Brand Name" - this is key|lable
  • go to your product type and "manage display", under "custom display settings" check "tokens"
  • go to the tokens display and change the brand field format from "default" to "key"
  • finally to set the pattern for your autosku's use the token with underscores instead of hyphens like [commerce-product:field_brand]

Wonder if title of this post should be "abbreviated sku" or the likes and instead of "custom pattern". Would it be improper for me to change it? Not certain about the etiquette here...