Set image field link to product display node not product entity

I have created a View to display products in grid format through adding a Views relationship - product reference. Each product grid contains three fields: content title, product image and product price.

Both content title and product image should link to the actual product display node. Content title is simple. But if link product image field to the content, it's not the node, but product entity which only administrative users are able to see.

To overcome this, I have added a hidden nid field and ordered it before product image field, and rewrite the result of product image field by "output this field as a link" with link path "node/[nid]". This enables the image field to link to the product display node and takes care of URL alias as well.

Is there a better way to do it?

Posted: Apr 21, 2011


realguess on April 23, 2011

Thanks Randy, the screencast is great. I was also looking at the issue you have submitted: https://drupal.org/node/1131192. The "Add relationship" image contains 3 duplicate "Content: Referenced product". I am using Views (7.x-3.0-beta3), and I have not yet applied your patch. I see the following in my add relationship:

- Content: Referenced product
- Fields: Referenced product
- Fields: Referenced product (delta)

I was able to get it working with "Fields: Referenced product" (not delta), not "Content: Referenced product", as in the screencast 3:34. Shouldn't "referenced product" be a type of field not content (node)?

Second thing is in the screencast 6:08, there is "Link image to", if you selected content, does it link to product display node or product entity? I would like the image link to the node, therefore, I had to use rewrite.

rfay Randy Fay on April 23, 2011

That patch got committed yesterday and went into beta3, so please update to beta3 or the latest dev.

You can create links of nearly any kind, and you can rewrite, as you say.

latulipeblanche on May 4, 2011

I don't get this working: Link image to product display node. I use the latest dev versions of commerce and views.

I need to link an image to the Product Display node but it's linked to the product type.

maxchock on June 8, 2011

Is there any update on this issue? Because even using the latest dev version of Commerce and Views, the product image still link to Product Administration Page rather than Product Display page and non-administrator user will see no link on image.