<p>This actually depends where the image is stored - if the asset (image) field is on the product, and is called <code>myImage</code>, then as per Brad's example you'd use: </p>

<p><code>lineitem.purchasable.product.myImage</code> </p>

<p>...BUT if it's in rather a field on the variant you would instead reference it as:</p>

<p><code>lineitem.purchasable.myImage</code></p>

<p>(This is because lineitem refers to a variant....in the case of a product without variants it references the implicitly created <code>defaultVariant</code>).</p>

CC BY-SA 3.0
2016-07-26T23:59:36.523Z
Somehow I knew either you or Luke would correct me. :)
Brad Bell
CC BY-SA 3.0
2016-07-26T05:36:10.367Z
2016-07-26T05:36:10.367Z
Jeremy Daalder
<p>You'd access the product images just like you would any other <a href="https://craftcms.com/docs/assets-fields#examples" rel="nofollow">Assets field</a> in Craft.</p>

<p>Assuming you've already got the cart, and your Assets field is called <code>productImages</code>, something like this should work:</p>

<pre><code>{% for item in cart.lineItems %}
    &lt;p&gt;SKU: {{ item.sku }}&lt;/p&gt;

    &lt;ul&gt;
    {% for image in item.purchasable.product.productImages %}
        &lt;li&gt;&lt;img src="{{ image.url }}"&gt;
    {% endfor %}
    &lt;/ul&gt;

{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-07-25T22:33:01.497Z
Yeah, I had tried that but I get the following error.

Craft\Commerce_LineItemModel and its behaviors do not have a method or closure named "productImage".

I had assumed it would be as simple as fetching a normal asset, but everything I have tried fails.
Terry Upton
CC BY-SA 3.0
2016-07-25T22:41:18.487Z
That's why I said "and your Assets field is called `productImages`". :)  What's the name of the Assets field you're storing the product images in?
Brad Bell
CC BY-SA 3.0
2016-07-25T22:43:54.293Z
productImage. I have changed the code to reflect my asset field name.
Terry Upton
CC BY-SA 3.0
2016-07-25T22:51:01.247Z
When I do a dump. {{ dump(item) }} I can't even see any reference to the productImage field. :-(
Terry Upton
CC BY-SA 3.0
2016-07-25T23:13:45.400Z
Updated my answer.  And actually tested it this time. :)
Brad Bell
CC BY-SA 3.0
2016-07-25T23:17:38.307Z
That's the one Brad! item.purchasable.product - Thanks. Got me there in the end. :-) Good stuff.
Terry Upton
CC BY-SA 3.0
2016-07-25T22:05:21.760Z
2016-07-25T23:13:32.413Z
2016-07-25T23:13:32.413Z
Brad Bell
<p>Really struggling with this (perhaps my brain is tired), but how would I get the image of a product for each entry in the cart screen in Craft Commerce? </p>

<plugin-craftcommerce><image><ecommerce>
Getting image for product in Cart Screen
# Getting image for product in Cart Screen

(Asked by: username_0 on 2016-07-25)

Really struggling with this (perhaps my brain is tired), but how would I get the image of a product for each entry in the cart screen in Craft Commerce?

**Tags:** plugin-craftcommerce, image, ecommerce


---

## 2 answers

### Answer by username_1 on 2016-07-26. Score: 4 | Accepted answer

This actually depends where the image is stored - if the asset (image) field is on the product, and is called `myImage`, then as per Brad's example you'd use:

`lineitem.purchasable.product.myImage`

...BUT if it's in rather a field on the variant you would instead reference it as:

`lineitem.purchasable.myImage`

(This is because lineitem refers to a variant....in the case of a product without variants it references the implicitly created `defaultVariant`).

> **Comments:**
> **username_2**: Somehow I knew either you or Luke would correct me. :)  

---

### Answer by username_2 on 2016-07-25. Score: 2

You'd access the product images just like you would any other Assets field in Craft.
Assuming you've already got the cart, and your Assets field is called productImages, something like this should work:
{% for item in cart.lineItems %}
    SKU: {{ item.sku }}

    
    {% for image in item.purchasable.product.productImages %}
        
    {% endfor %}
    

{% endfor %}

> **Comments:**
> **username_0**: Yeah, I had tried that but I get the following error.  Craft\Commerce_LineItemModel and its behaviors do not have a method or closure named "productImage".  I had assumed it would be as simple as fetching a normal asset, but everything I have tried fails.  
> **username_2**: That's why I said "and your Assets field is called `productImages`". :)  What's the name of the Assets field you're storing the product images in?  
> **username_0**: productImage. I have changed the code to reflect my asset field name.  
> **username_0**: When I do a dump. {{ dump(item) }} I can't even see any reference to the productImage field. :-(  
> **username_2**: Updated my answer.  And actually tested it this time. :)  
> **username_0**: That's the one Brad! item.purchasable.product - Thanks. Got me there in the end. :-) Good stuff.  

---

