Problem

After the attribute is changed, and the image is swapped, the image is no longer linked to content, as specified in the Product Type display.

How to reproduce

Create the product and display

  • Create a product type
  • Add an image field
  • Manage the Display for Node: Teaser
  • Set the image field format to Image, linked to content
  • Create a new select text field such as Size, with more than one option
  • Make this field exposed and selectable by the user on the add to cart form
  • Create a product display

Create sample products

  • Add a new product with each attribute, and add them to the same display node
  • Add an image for each product

Build the view

  • Create a new view to show content of type Product Display
  • Show content / teaser

Display the view ( such as a page )

When viewing the display, the image will be linked to the node. However, after the attribute is changed, and the image is switched, the image is no longer "clickable". The anchor tag that should surround the image is gone.

I've tried by best to track this down in the commerce_cart_add_to_cart_form_attributes_refresh function, but I can't find it. It looks as though it just renders the field with field_view_field with node_teaser as the display, but I couldn't figure it out.

Comments

mr.baileys’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new714 bytes

We are having the same issue, though Views is not required to reproduce this. Just create a couple of products with images, display the image on node teaser and configure an attribute to show up on the add to cart form. When loading the product teaser, the image links to the correct product display. When changing an attribute via the AJAX widget, the new image loads correctly, but the link points to /admin/commerce/product/nnn.

When the Add to Cart form is rendered normally (non-AJAX), it uses commerce_cart_add_to_cart_form(), which triggers commerce_cart_field_attach_view_alter() to add some additional data to the elements of the form, including display context.

When part of the add to cart form is updated via AJAX, the display context does not get set, and the entity_uri('commerce_product', $product) fallback is used to determine the url, resulting in /admin/commerce/product/nnn instead of node/nnn (Also see commerce_product_reference_commerce_product_uri()).

Patch attached fixed the issue for us.

rszrama’s picture

Issue tags: +1.1 blocker

Tagging.

rfay’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect to me, and resolves the issue as described in #1.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Honestly, it's these one-liners that take all the work... anyone can write a chunk of code, but finding that one place where someone else has forgotten something can take a lot more time. Thanks for the excellent summary and the patch, mr.baileys.

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