I am using Drupal Commerce and would like my product url to have the following format:
/main_category/sub_category/product_name.

For this, I am using Pathauto module and have set the alias in the following format:
[commerce_product:field_categories:0]/[commerce_product:field_categories:1]/[commerce_product:title]

What I observed is that, the categories are replaced correctly but the product title does not appear in the url.
But on random shuffling of tokens, such as placing the title token in the beginning, the url appears correctly.

On debugging, I found that field_tokens() in token.tokens.inc file calculates the $delta value for a multi-valued field, like the categories field, and it does so in a for loop for all the tokens of a particular token type present in the pattern.
But the $delta value does not get reset on each iteration of the loop, thereby causing token replacement to not occur correctly.

In my case, after fetching values for [commerce_product:field_categories:0] and [commerce_product:field_categories:1], the value of $delta becomes 1. When the final token value is computed, i.e. for [commerce_product:title], as $delta=1, it is trying to get title[1] from the product entity, which does not exist, as title is only a single valued field. So, since value for replacement of [commerce_product:title] is not available, it does not appear so in the url for the product that I am trying to generate.

Comments

Vivek Panicker created an issue. See original summary.

vivek panicker’s picture

Version: 8.x-1.x-dev » 8.x-1.5
vivek panicker’s picture

Here I am initializing $delta = NULL for each iteration of the loop. That solves the problem for me.

vivek panicker’s picture

Status: Needs work » Needs review
vivek panicker’s picture

Assigned: vivek panicker » Unassigned
gigabates’s picture

I've just discovered the same issue and arrived at the same fix. I can confirm that your patch works.

anton4uk’s picture

Version: 8.x-1.5 » 8.x-1.17
StatusFileSize
new518 bytes

Reroll for 1.17