<p>I've run into a dead end when trying to create custom URL's for a product type in Commerce 2. I want to create the URL from a custom field -- a Commerce Product field to be exact. This product does not have variants.</p>

<p>I've referenced <a href="https://craftcms.stackexchange.com/questions/22497/get-the-category-into-the-url-of-the-product-page">this question here</a>, but the example did not work for me.</p>

<p>Here is what I've tried with no success: <code>{relatedImage.first().id}</code>, <code>{relatedImage[0].id}</code>, <code>{object.relatedImage.first().id}</code>.</p>

<p>When the Craft task manager tries to rerun these products, it just errors out (Failed). And I'm not sure where to find task manager error logs to see if I can get any information from them.</p>

CC BY-SA 4.0
2018-08-06T18:31:51.350Z
The underlying error for the failed job will be in your project's `craft/storage/logs` or `storage/logs` folder depending on how you have it setup.
Brad Bell
CC BY-SA 4.0
2018-08-07T13:59:03.073Z
"Could not generate a unique URI based on the URI format". The URI format is: `{relatedImage.first().id}`. It's looking for the id of a selected commerce product. Is that not possible?
John Johnson
CC BY-SA 4.0
2018-08-07T23:53:03.920Z
Assuming `relatedImage` is the Commerce Product field, is it inside of Matrix or SuperTable or the like? Or is it at the root?
Brad Bell
CC BY-SA 4.0
2018-08-08T16:08:42.957Z
It's at the root.
John Johnson
CC BY-SA 4.0
2018-08-08T22:58:11.097Z
Just did a test of this locally on the latest Commerce 2 beta. Created a Commerce Products field, added it to the Product Type field layout using `{relatedImage.first().id}` as the URI Format, created a new Product, selected a related Product with an ID of 10, then the new Product's resulting URI is the expected `site.com/10`
Brad Bell
CC BY-SA 4.0
2018-08-13T17:20:43.677Z
Just to confirm: I have two product types: Images, Recipes. When adding a Recipe, that's where the relatedImage field is present. This field allows me to select an Image-type product. Upon doing so, I want to use that Image's ID as the slug in the URL of the recipe. `{relatedImage.first().id}` does not appear to be working on my end, despite the good results you have found, Brad.
John Johnson
<plugin-craftcommerce2>
Custom Commerce product type URL from custom field
# Custom Commerce product type URL from custom field

(Asked by: username_0 on 2018-08-06)

I've run into a dead end when trying to create custom URL's for a product type in Commerce 2. I want to create the URL from a custom field -- a Commerce Product field to be exact. This product does not have variants.

I've referenced [this question here](https://craftcms.stackexchange.com/questions/22497/get-the-category-into-the-url-of-the-product-page), but the example did not work for me.

Here is what I've tried with no success: `{relatedImage.first().id}`, `{relatedImage[0].id}`, `{object.relatedImage.first().id}`.

When the Craft task manager tries to rerun these products, it just errors out (Failed). And I'm not sure where to find task manager error logs to see if I can get any information from them.

**Tags:** plugin-craftcommerce2

> **Comments:**
> **username_1**: The underlying error for the failed job will be in your project's `craft/storage/logs` or `storage/logs` folder depending on how you have it setup.  
> **username_0**: "Could not generate a unique URI based on the URI format". The URI format is: `{relatedImage.first().id}`. It's looking for the id of a selected commerce product. Is that not possible?  
> **username_1**: Assuming `relatedImage` is the Commerce Product field, is it inside of Matrix or SuperTable or the like? Or is it at the root?  
> **username_0**: It's at the root.  
> **username_1**: Just did a test of this locally on the latest Commerce 2 beta. Created a Commerce Products field, added it to the Product Type field layout using `{relatedImage.first().id}` as the URI Format, created a new Product, selected a related Product with an ID of 10, then the new Product's resulting URI is the expected `site.com/10`  
> **username_0**: Just to confirm: I have two product types: Images, Recipes. When adding a Recipe, that's where the relatedImage field is present. This field allows me to select an Image-type product. Upon doing so, I want to use that Image's ID as the slug in the URL of the recipe. `{relatedImage.first().id}` does not appear to be working on my end, despite the good results you have found, Brad.  

---

## 0 answers

