When creating a product variation, I would like to auto generate the SKU using a field in the referencing product display node.
The Node Token subtree is not shown in the available replacement patterns. I added the subtree to them by adding 'node' to the tree with this line:
$autosku['pattern']['#token_type'] = array('commerce-product','node');
However, when I reference a token such as, node:field-sku-component, the replacement doesn't occur and my skus look something like T100-nodefield-sku-component-001.
I'm not sure what I'm missing here. Maybe the referencing node is not available when the replacement occurs?
Comments
Comment #1
rbayliss CreditAttribution: rbayliss commentedYeah, the referencing node isn't available to the product. It makes sense when you think about it - the same product can be used in multiple product displays, so the product display node has the reference to the product, not the other way around.
Comment #2
jaylotta CreditAttribution: jaylotta commentedThe thing that is confusing me about your reply is that Commerce core uses the title field of the display node to create the title of the product when automatic title generation is enabled. So, it seems to me, at some point during the creation of the product the referencing product display node is available.
I see what you are saying about multiple displays for products but when creating product variations in the display node editor, perhaps you can get this information. The inline entity form module code which does this is as follows:
Any comment will be greatly appreciated.
Comment #3
jaylotta CreditAttribution: jaylotta commentedComment #4
sic CreditAttribution: sic commentedHow would you do this then? I'd like to have the referencing node to the SKU aswell. Strangely, there is a token for that but it doesnt work, this fella has the same problem but using :0: doesnt work either
Comment #5
jaylotta CreditAttribution: jaylotta commentedI would use this because my SKUs are generated based upon a value in the product display node, the SKU_Prefix.
All product variations have SKU components that I would like to get from the referenced taxonomy and the variation itself.
So, all product variations for a specific node would have a SKU like so,
SKU_Prefix - Variation Component - Taxonomy 1 SKU Component - Taxonomy 2 SKU Component.
For example, a product variation which is for the display node, Basket, with a Finish of Brushed Nickel, and an Installation type of Stone would have the SKU
T100-001-BN-S
Hopefully this clarifies my specific use case.
Comment #6
maxplus CreditAttribution: maxplus commentedHi,
did you find a solution for using a token of a field of the display node inside the sku?
Like already said, using [commerce-product:field-product-node:0:... does not work.
Thanks
Comment #7
UksusoFF CreditAttribution: UksusoFF commentedIf you creates products on nodes edit page via https://www.drupal.org/project/inline_entity_form
You can use this token for get referenced node nid: [current-page:url:args:value:1]
Yes, this is very crooked but I can't find another way.
Also you need uncheck "Always regenerate SKU" option on product type page.
Comment #8
UksusoFF CreditAttribution: UksusoFF commentedComment #9
nvahalik CreditAttribution: nvahalik at Centarro commentedIt's worth noting that in many cases, products are generated without being referenced by a SKU until later on in the content/data creation process. As the author module stated, it's also possible for product entities to be related to many product displays (so which would it be?)