3

I am currently trying to automate some stuff, including the product sku as new products are created. For this I am using the AutoSKU module together with Token.

The idea is that every product display has a Base SKU, which I want to define once per product display.

So when you add a new variation to that product display, I want AutoSKU to also fetch whatever string has been put into said Base SKU field, named field_device_sku .


Stuff like [commerce-product:field-device-sku] unfortunately does not work, for the field belongs to the product variation's parent product display.

Is there any way pulling this off without unnecessarily redefining the 'base SKU' inside every product variation?


TL;DR: For pictures famously say more than 117 words, here an admin panel screeny which might make it clearer what I am talking about and struggling with: Fetch Product Display Field

Fetching the desired SKU of the coverage and texture is no issue thanks to taxonomy, but the base sku string I just cant figure how to get. I am starting to doubt it's even possible if it's not defined directly in the product variation.

Any help or hints would be highly appreciated!

  • I was about to ask about the same question : how to get a token from a product type field in Autosku Parameters ? I'm wondering if adding a hidden field in product variation that would take the base value with a code snippet ? – Kojo Dec 27 '13 at 14:30
  • as far as I understand the architecture of drupal and commerce, i'm afraid this is the smartest thing you can do about it. I believe the only relationship between a display node and a variation is that from a display node can refer to a variation, but not vice versa. – Bird-Kid Dec 27 '13 at 20:39
  • (apparently i cant edit posts after more than 5 minutes of submittion) – the way I went around this is, as you suggested, to set up another taxonomy term reference in every single variation. I like your idea though of hiding that field and including a code snippet that automatically inserts the data for you when you set up the same field in the display node, that will indeed get around this issue. – the only other issue you will probably run into is that the AutoSKU's token field by default allows max. 128 characters, but fortunately, editing a file, there is an easy way around this too. – Bird-Kid Dec 27 '13 at 20:46
  • @Kojo I doubt you're still looking for a solution to this, but just in case you are, I just found out about a token that does exactly this and posted about it below. (: – Bird-Kid Mar 4 '14 at 15:44
  • Thanks to share your solution, I'll try it within the next days and will report back. – Kojo Mar 4 '14 at 17:53
0

although I solved this issue a while back just by applying the same Device term reference field on every variation form, maybe someone else happens to stumble upon this sometime:

just as I was messing with some rules yesterday, I found out about a token that deal with exactly this! I just gave it a shot and it does exactly what I was looking for: refer to fields on the node that was used to create the variation.

the token that does this:

[commerce-product:field-product-node:0:


so, for example, the token in my case would look like this:

[commerce-product:field-product-node:0:field-device-name:field-device-sku]

(note that the screenshot in my original post is outdated, as I now determine the device name and SKU via a taxonomy term reference field-device-name)


keep in mind!:
although this may keep you from having to include the same field on the product variation, I reckon this is less reliable. you may run into trouble, if you happen to create (or edit!) a product variation from a different node that does not have the reference field (or has other input). note that even when editing an already existing product, the SKU will be re-generated on submit. so make sure you only edit the product from within the original node (or any node that has the same field with the same value), if you dont want the value of the token-generated field to change.

however, I could be wrong and it may be just as reliable, if the field-product-node:0 always references to the same node on which the variation was originally created, regardless of where you edit it later on. – someone will have to test this (and preferably report back) if he/she is interested in the exact behavior of this node reference token. if anyone knows the answer, I would be interested in hearing how this behaves exactly. but since I'm sticking with the extra field in the variation, I do not rely on this method now.


hope this helps someone else in the future. (:

  • was looking for same thing and came through this comment and its a nice catch by you about the variation SKU modification whenever it is edited. To solve this, option is provided in varitaion configuration like "Always regenerate SKU". We can disable this option if we don't want SKU to get updated whenever variation product is edited. – kiranking Oct 2 '14 at 7:17
  • hi, I've came across the same need to use node specific data in my SKU pattern. Strangely, [commerce-product:field-product-node:0:nid] does not work, any ideas? – Alex Nov 21 '14 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.