After upgrade to Commerce 1.6
Image fields linked to content in product list view now starts to link to product page in admin section, not to product display node.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mnklein’s picture

Priority: Normal » Critical

Experiencing the same issue. The catalog is only navigable by clicking product titles.

mnklein’s picture

Priority: Critical » Normal
rszrama’s picture

Ahh, crap. I noticed the same issue on my Kickstart 2.x demo site and hadn't traced it back to see if it was an issue in Commerce or something else. Will get a quick fix in for this asap, just noticed the same problem locally.

svouthi’s picture

Thanks, I'm glad to see you're on it. Just discovered it on my site too after updating the module yesterday.

Stellar Rush’s picture

Priority: Normal » Critical

I have the same problem. Updated Drupal Commerce and now product Teaser images link to admin Product page instead of Content. Tried setting to "Nothing", saved and checked. It did link to nothing. Then switched to "Content" and administrator got Product editing page on overlay. User without authorization could not select the image for the link.

theRuslan’s picture

mnklein’s picture

Thank you! I was able to roll back to the previous version's function to obtain this functionality back for now:
Previous version:

function commerce_product_reference_commerce_product_uri($product) {
// If the product has a display context, use its URI.
if (!empty($product->display_context)) {
return entity_uri($product->display_context['entity_type'], $product->display_context['entity']);
}
}

rszrama’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
Priority: Critical » Major
Status: Active » Needs review
FileSize
924 bytes

Ahh, yeah, that commit was fixing a bug introduced in a previous patch, and naturally the solution was only tested on a Kickstart 1.x site without images. In any event, I'd also isolated that code and had a patch but then went on vacation. Here it is for testing.

theRuslan’s picture

Thank you, Ryan! Applied patch in #8 to Commerce 1.6 and it works well.

davidwhthomas’s picture

Thanks Ryan, this alternative patch resolved the issue I was having in #1975432 as well.

I'm not sure where the entity_id value in $product->display_context['entity_id'] comes from in this new patch, but I guess it's not needed to determine the entity_uri because entity_type and entity are available.

Cheers,

David

svouthi’s picture

Appears to have fixed it for me too, though I haven't tested extensively. Thanks!

torgosPizza’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #8 worked for me too.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

@davidwthomas Yeah, the entity_id isn't required when we're actually trying to determine the entity URI for a product's "parent" entity instead of the product itself. However, it is unnecessarily inconsistent to not also include it here in this context where we do include the entity_type and entity, so I've added it back in. We already had a place earlier in commerce_product_reference_entity_view() where we extracted the IDs, so this patch just adds it to the array along with my fix to change when we return a NULL value in commerce_product_reference_commerce_product_uri().

Commit: http://drupalcode.org/project/commerce.git/commitdiff/13db923

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

onduhray’s picture

Status: Closed (fixed) » Active

I am still having this issue. Applied the patch, clear caches several times (drush and admin interface), even rebuilt a view to test this and URI of image still links to admin interface not product display. Checked the module code and patch was applied.

Maybe I patched the wrong file? Missed something else? I had to apply a patch to a different module recently, so I think I got the process/commands right. This is the location of the file that was patch (relative to drupal root):
/profiles/commerce_kickstart/modules/contrib/commerce/modules/product_reference/commerce_product_reference.module

I could not locate any other product_reference module on my setup.

Using Commerce Kickstart 7.x-2.8

Views Setup:
Relationships -> Content: Referenced product
Fields -> (Referenced Product) Commerce Product: Image [image linked to 'content']

rszrama’s picture

Status: Active » Closed (fixed)

Commerce Kickstart should have been updated, but the issue has been definitively fixed inside Commerce itself. My guess is your View uses Commerce Product as the base table instead of Node, in which case the rendered image field wouldn't know what node it was "supposed" to belong to. That the case?

onduhray’s picture

Alright, after much hunting, and nearly breaking my entire site, I figured out the issue.

It is extremely unclear how to display products using Views. After much googling, I had settled on creating a View displaying either CONTENT or COMMERCE PRODUCTS displaying FIELDS. I would then add a RELATIONSHIP to CONTENT: REFERENCED PRODUCT. This worked and it was easy to add fields and get the output exactly how I wanted it. The problem, and the reason I reopened this ticket, is that the COMMERCE PRODUCT: IMAGE field would link to the admin display, not the product display.

The problem was what I chose to display when creating the View. First, I updated Commerce Kickstart, which broke all my existing Views with a SQL error. Then I installed a fresh Commerce Kickstart to test product display views. There were numerous issues with the install, one which broke the front page. No idea. But through testing the fresh install, I stumbled across the idea to study the COLLECTION view that comes with Commerce Kickstart. I noticed that it was displaying PRODUCT DISPLAY content, and a field of CONTENT: RENDERED ENTITY with the PRODUCT LIST view mode.

Long story short, I discovered that by using Display Suite, I could create custom view modes, which would be customized with the exact fields I wanted to display. This had to be done on both the CONTENT TYPE (product displays) and VARIATION TYPES. While MANAGING DISPLAY for the type you are editing, select the tab at the bottom labeled CUSTOM DISPLAY SETTINGS to enable the custom view mode made in Display Suite. Then you can select the view mode for the content types and change the fields available. Its a bit tricky to figure out where to change what values (in CONTENT TYPES versus VARIATION TYPES) but I'm sure most people can figure it out.

After you create your VIEW MODE, create a new View that displays PRODUCT DISPLAY items, not CONTENT or COMMERCE PRODUCTS. Then make sure you are using RENDERED ENTITY either for the whole node or in a field (where it will be listed CONTENT: RENDERED ENTITY). Under the RENDERED ENTITY settings, select the VIEW MODE you created, and viola! It outputs the fields you want AND links to the content not the admin page. What it outputs will require some CSS styling, as there are more default drupal styles applied to the rendered entity than just plain fields. But that can be tweaked in the Views settings themselves or by using Mothership Base theme.

Anyways, sorry for the long post and all the caps. Seemed like the best way to point out the important bits. Hope this helps someone else stuck on this.

rszrama’s picture

Thanks for sharing your research, I'm sure it'll be helpful. : )

xiaoluan0318’s picture

Thanks a bunch for this, It help me out!

suntower’s picture

Issue summary: View changes

Having the same problem as #15: Any View created with Commerce Product links to Admin page if you're admin or to nothing if you're not.

And just to be clear, it's not just links to images, but -any- Commerce Product Reference field that one tries to wrap with a link back to original content.

Using Commerce Kickstart 7.x-2.8. It's pretty outrageous that this bug should persist... and I'm at a loss as to why it should be closed as 'fixed' if it's still happening in Kickstart.

I'm no Commerce expert. Can someone point me to a place in the code where that link is built so I can (hopefully temporarily) correct this? Not using Display Suite.

TIA.

suntower’s picture

Status: Closed (fixed) » Needs work

Still happening in Kickstart 2

rszrama’s picture

Category: Bug report » Support request
Status: Needs work » Closed (fixed)

The problem is just that the issue queue is a crappy place to support modules. : )

The best answers are probably scattered through a variety of issues that are difficult to search / relate together. The gist of it is slightly less outrageous than you might expect... in Drupal, "linking to content" for an image means it finds the entity URI of whatever entity the field is attached to and links to that. For products, that's the administrative URI, because technically speaking we don't enforce a canonical front end URI for product displays.

The way around this in Drupal Commerce is to render the field in the context of the referencing entity you want it to link to, because we work through the product reference field relationship to alter the link value to the referencing entity. In real terms, this typically means making the base table of the View the product display node, assigning the field to some display mode, and rendering the node using that view mode. I've done this on a variety of sites, though depending on the scenario you might need a use case specific view mode.

The alternative is you can create the relationship yourself and instead of using the image field's (in this case) faulty "link to content", wrap it in your own direct link to the URL you want it to go to. I've done this to great effect for both taxonomy term based product catalogs and product displays.

suntower’s picture

First off... I don't wanna argue... and I do appreciate the help.

Second: Can you clarify what you mean by "In real terms, this typically means making the base table of the View the product display node, assigning the field to some display mode, and rendering the node using that view mode." Does this mean making the Base Table 'Content' and then 'Of Type 'Bags_Cases'?

Is that the 'Product Display'?

Finally: I think it's reasonable that new users will expect a field with an option to 'link to content' will: link to the -content-, not the 'edit' of the content. This is, and I'm being charitable, non-intuitive.

Quoting from the Kickstart project title page:

"Who should use Commerce Kickstart? Anyone who wants to skip weeks of configuration to build a commerce site on the Drupal Commerce framework."

All the widgets should work in a way that lets people cobble together sites without doing seriously deep dives like you're suggesting.

AFA posting at multiple fora: Sorry. But have you tried getting help with Kickstart at the CommerceGuys forum lately?

rszrama’s picture

Nope, I didn't even see your post in there - I got an e-mail about it from Stack Exchange. : P

I think your assumption is reasonable - yes, new users would expect "link to content" to mean "link to node", but unfortunately we don't control the user interface for the image field module. That's one of the drawbacks of the modular nature of Drupal, but fortunately we're solving this in Commerce 2.x by going back to support the direct display of product entities themselves. We didn't have the tools we needed to make that happen in Drupal 7, but the entity API in Drupal 8 is robust enough to support that.

And yeah, you read me right. Instead of making a View of product entities, you'd make a View of nodes and filter it to product display node types (i.e. bags, hats, cases, etc.). If your issue is in a View that is more naturally a list of some other entity type (the shopping cart contents being line items, for example), then I'd use my alternate strategy of using Views relationships to find the node that references the product referenced by the line item (i.e. node -> product <- line item) and rewrite the output of the image field manually to wrap it in a link to node/[node-id].

xstanley’s picture

I was facing this problem also in the latest Kickstart 2 version, so after hours of investigating I was able to prepare these detailed steps how to solve it:

  1. In Views under 'Advanced' and the 'Relationship' heading choose 'Add', and find and select 'Content: Referenced Product' (if adjusting a cart form view, then select 'Commerce Line item: Product'). Check the 'Require this relationship' checkbox.
  2. Now, under 'Fields' heading add a field 'Content: Path' (in case of the cart form view, add 'Commerce Line item: Display path'). 'Exclude from display' this field and arrange it to be the first field (it is important to have this field above the image field in order to be able to use its [path] token (see point 3)). If you have a multilingual page, check 'Use absolute link' under 'Rewrite results' (matters for the 'Content: Path field' only).
  3. Finally, add the 'Product: Images' field. Link it to Nothing. Under 'Rewrite results' choose 'Output this field as a link' and use the token [path]. If you are facing the problem also with other fields, apply this solution also to them.

Source: Me and https://drupalcommerce.org/discussions/556/product-image-views-link-prod...

rszrama’s picture

Thanks for sharing! : )

mamunozr’s picture

Very useful after searching and experience when one is new to Drupal is a very interesting community, thank you.

webdevdoc’s picture

Hi,

I am trying to figure this out as well and none of the information here matches up to what I am seeing in my view. I have a view setup using commerce product.

I have an image and as admin I can click the image but it opens the product edit screen, as an anonymous user I cannot click on the image. In views, under relationships I click add but only get 4 options, none of which are useful.

torgosPizza’s picture

@webdevdoc: When you Add a new Relationship in your View, does it give you the option of "Referencing Entity"? It should be something along those lines, "A bridge to the content referencing this entity." If you select that, it essentially creates a reverse relationship to any entities/nodes that reference the related products in an entity reference (or product reference) field.

Your field names and content types will vary.

Then, edit your Field in the view, and choose the referencing entity type in the "Relationship" selector.

Note that if you have multiple nodes referencing the product, you may need to enable Aggregation to prevent duplicate nodes from appearing, though this may have further unintended consequences in the way your View is rendered.

MariskaTh’s picture

Thanks for your idea. The relationship that was similar was 'Commerce Product: Referencing Node'. When I added that relationship in my view and related it to the images of my teasers, the images of the teasers disappeared. So it didn't work yet.

Best regards,
Mariska.

MariskaTh’s picture

What I just wrote wasn't correct. With fields it doesn't work, but in the following way it does work:

- Create a view and choose to show 'content'
- Then choose to show a grid of teasers

With css you can change the teaser exactly as you want.

Best regards,
Mariska.