Discussions

Product image on cart form

Does anyone know how you can get a product's image to show on the shopping cart form? In product types there is a line item display and I've added all the fields I want there including the products image but this does not seem to affect the cart form page at all.

I've looked at the line item type editor and it does not seem to offer anything like you get with a Product Display (e.g. Product: Image on the display editor). Nor does the View "Shopping cart form" seem to offer a option to show a field of the attached product.

Am I missing something or will I have to see if I can do something in the template itself? I suppose if I can get the product's ID I can load in the image but I've not checked if any of the line item fields expose the products ID, plus its a bit hackish.

Thanks

Posted: Nov 15, 2011

Comments

Prince Manfred on November 15, 2011

You need to edit the "shopping cart form" view. If your image field is on the actual product then go to advanced and add the relationship "(Line Item) Commerce Line item: Product". Then go over to fields and add your image. Make sure you have some image styles defined because you'll probably want a smaller thumbnail there.

If you also want this to happen on the checkout page when confirming the order do the same thing to the "Shopping cart summary" view.

greenavus on February 20, 2012

I tried this but for some reason, it did not work but worked only for admin. Added the relationship "Line Item) Commerce Line item: Product " and under fields added "(Product) Field: Image (Image) ".

This worked for the admin but it removes the shopping cart block and shopping cart form for non logged in users. I have absolutely no idea why.

Please do you know of any reason why this could happen?

milkovsky on March 22, 2012

When I add relationship "(Line Item) Commerce Line item: Product" it removes cart block for all users instead of administrator.
It happened because non logged users don't have a permission to view the product entities.
You should give the "View any product of any type" permission to your user role ( /admin/people/permissions/list).

P.S. Be careful with this primission

nawi on May 3, 2012

Hi Prince Manfred.

In relationship I have "Commerce Line item: Referenced product" when add this, in fields I have only Node:Product. I can not add pictures in the fields.

Where is problem?

lastar84 on May 23, 2012

"Commerce Line item: Referenced product" appears to be the correct selection in "relationships". After selecting that in your view, you should find the fields you created on the store product type (not to be confused with fields that you created for your display content type).

But as others have mentioned, after doing this, the cart disappears for users who do not have the "View any product of any type" permission clicked on for anon users. Since that permission clearly states, "Warning: Give to trusted roles only; this permission has security implications," then this an unsuitable solution.

So we remain without a useful method of adding a product image to a cart.

joshmiller Josh Miller on May 24, 2012

lastar84,

Found this issue regarding the security notice: http://drupal.org/node/1303194

In short (and from the original programmer's mouth), "You might test what happens with disabled products, but it could be there isn't a security problem and we should just remove that warning."

And later on in the issue, from someone who did a bit of history digging "In summary, I'm not really sure this permission was meant to be flag security sensitive in the first place."

I will state that the real bug is the security flag and not that the shopping cart is broken. Please ignore the notice, and we'll try to get that removed in Commerce-1.4 (please submit a patch if you are aware of how to do that).

Josh

HyperGlide on July 4, 2013

We have had the permission "View any product of any type" enabled for anonymous users for some time.

We added the 2nd reference to pull images from the product displays (nodes).
There are a total of (5) references:

Commerce Order: Line items
(Line Item) Line Item To Product
(PID 2 NID) Content Type A
(PID 2 NID) Content Type B
(PID 2 NID) Content Type C

Before adding any of the new fields.

The cart does NOT display the line items in the cart for anonymous users.

Help please.

Updated.
After finding -- http://www.drupalcommerce.org/comment/2613#comment-2613
and disable query rewriting
Problem seems fixed.

lastar84 on May 25, 2012

I think you're right. It doesn't seem like a security issue. I'm going with along with that, and allowing that permission. Mine's a testing site anyway, so it's no risk while this issue gets wrangled out, or patched. And no, I don't think you want any patch created by me; it would probably crash the whole Commerce project.

dilari on November 29, 2012

so, (taken from the above link):

  1. Add a relationship 'Commerce Line item: Referenced product'
  2. Add a second relationship 'Commerce Product: Node referencing products from [field_name]' where [field_name] is the machine name of the field in your node that references the product itself
  3. If you have multiple product display content types, repeat step 2 for each
  4. You can then add fields from your product display nodes

jzeidler on January 6, 2013

I am handling the display of my products in the cart using the "products in cart" display within my variation type. This display the image is set to "product_thumbnail" and the cart view has the field "commerce line item: product" with the view mode set to the "products in cart". This seems to be all handle well with the kickstart installation and the existing variants (when they are added to cart), but new product variants I have created dont show the images when added to cart (or add to cart confirmation) even though they have the exact same display setup.

HeikeT on July 7, 2013

Just in case somebody needs to do this using Kickstart

1) If you use more than one product display, make sure to re-use the same image field on all product displays
2) Set up an image style e.g. product_image_cart
3) Go to shopping cart, use contextual link to "edit view"

and follow most of dilari's steps above

4) Add a relationship 'Commerce Line item: Referenced product'
5) Add a second relationship '(Product) Commerce Product: Node referencing products from field_product' (in Kickstart that works for all product displays)
6) Add field '(Node referencing products from field_product) Content: ', assign image style, reshuffle order

Done.

I hope this makes sense :).

bulewold on August 9, 2013

I got this working using product attribute. The problem is that one products that has multiple images, it'll all show up and I CANNOT find a way to limit that to just one and may even to smaller picture.

Anyone can tell me where i can control these settings?

Drupal 7, no kickstart

bulewold on September 5, 2013

Thanks but unfortunately this did not work.
If you dont' mind looking at this pic: http://www.fileconvoy.com/dfl.php?id=gd9448eaa55ca4ded9993652610b95ea1c2...
has the issue.

It has two big pictures. All I want there is just attribute (color and scent) and maybe one smaller picture. But even no picture is ok with me. Just not sure how to manage this.

Under view -> shopping cart form -> Fields -> Configure field: Commerce Line Item: Product Attributes
is where it's managed at as far as I can tell. But it doesn't have image display option which I need. It does have rewrite option and be able to limit to maximum character and when I set it to 1000, I only get one picture but no details.... This would work if I could display details first as I can be ok without display of pictures.

Any thoughts?

Paul Driver on August 14, 2013

I have a situation where the product image is handled by the product display node, rather than the variation. Consequently, I am not able to view a product image in either the cart confirmation view or the cart view.

When I try to modify the the cart views, I find that they do not appear to allow a relationship with the referenced content type, from where I could locate the image field.

Am I missing a trick here?

CptAnt on August 18, 2013

You should end up with something like this in your relationships

Commerce Order: Line items
(Line items referenced by commerce_line_items) Commerce Line item: Product
(Products referenced by commerce_product) Commerce Product: Referencing Node

Works for me !!

marvyndt on November 14, 2013

This works as far as getting field values from the referenced node, but it introduces a new problem for me: If any single commerce product is assigned to multiple product display nodes, then all those nodes are shown in the Shopping Cart form view.

For example, Product X is shown on Page 1 and on Page 2. If I add Product X to my cart and go to the /cart page, then it shows field values from both Page 1 and Page 2.

I thought I could fix it by attempting something similar found in a different issue related to views and duplicate product display nodes, but no dice or at least I'm using the wrong filters.

Any ideas?

spideep on May 26, 2014

I have a product, a content type to show it (product_ct). product_ct has the field Icon (image). What I need is to show that icon in the /cart page.... (shopping cart) , any ideas?