I am building a drupal 7 commerce site, I have installed inline entity form module and adding products from inside the products displays.
Since I will have thousands of product displays and products, I thought of finding a way to automatically separate pictures into sub-folders at time of adding the product displays and products.
So I have installed this module
Filefield Paths
I managed the image field in the product display and set the path setting to:
pictures/products-displays/[node:field-taxonomy-terms:1:root]
(as per below screenshot)
So it uploads the image, to a folder named as per the product parent category, under products displays folder. Which is exactly what I want. a nicely organized pictures structures.
The problem is not with product display images. It is with product images. I want to have the same things for products where I need images of products to be saved under
pictures/products/(parent category of the product display this product belongs to)
I understand that:
- The product categories vocab is a reference field for Product Display and not product
- A product can belong to more than one product display, so there there is no reference on the product data to the product display it belongs to, only the other way around.
So I thought my only workaround to get the category of the product display to which the product belongs to is to use the page url
. (I edit my products from the same page of product display edits..remember I am using inline entity)
So [current-page:url:args:value:1]
will give me the product display node id, when I am on the page of product display and its products editing.
What I need is to get the parent category of that product display node id and use it for the path. in other words I need to have a token that will get me the parent category of the product display id on the page
I know the below does not work... but just to give an idea about the logic
[[current-page:url:args:value:1]:field-taxonomy-terms:1:root]