<p>This should work:</p>

<pre><code>{% set image = block.chooseProduct.first().mainProductImage.first() %}
</code></pre>

<p>Explanation:
your field handle in your product is called <code>recommendProduct</code> (matrix) that contains a relation <code>chooseProduct</code>. Your <code>block.chooseProduct</code> is an object of type <code>ElementCriteriaModel</code> so in order to fetch the product you need to call the <code>first()</code> method (or something similar). So if you have multiple products in your <code>chooseProduct</code> field your code would look like this </p>

<pre><code>{% for block in product.recommendProduct %}
{% set i = i + 1 %}
   &lt;div&gt;
       {% for relatedProduct in block.chooseProduct %}
            {% set image = relatedProduct.mainProductImage.first() %}
            &lt;img src="{{ image.getUrl('productListing') }}"&gt;
            &lt;p&gt;{{ relatedProduct.title }}&lt;/p&gt;
       {% endfor %} 
   &lt;/div&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-11-05T19:23:13.023Z
2017-11-05T19:23:13.023Z
Robin Schambach
<p>I'm trying to bring in recommended products for adding to a bigger purchase. I set up a simple matrix but can't seem to figure out how to pull product information. This is what I have so far, it throws no errors, but it also gives nothing.</p>

<pre><code>{% for block in product.recommendProduct %}
    {% set i = i + 1 %}
       &lt;div&gt;
           {% set image = block.chooseProduct.mainProductImage.first() %}
            &lt;img src="{{ image.getUrl('productListing') }}"&gt;
            &lt;p&gt;{{ block.chooseProduct.title }}&lt;/p&gt;
       &lt;/div&gt;
{% endfor %}
</code></pre>

<plugin-craftcommerce><matrix><products>
How to show a product from a field entry
# How to show a product from a field entry

(Asked by: username_0 on 2017-11-05)

I'm trying to bring in recommended products for adding to a bigger purchase. I set up a simple matrix but can't seem to figure out how to pull product information. This is what I have so far, it throws no errors, but it also gives nothing.
{% for block in product.recommendProduct %}
    {% set i = i + 1 %}
       
           {% set image = block.chooseProduct.mainProductImage.first() %}
            
            {{ block.chooseProduct.title }}
       
{% endfor %}

**Tags:** plugin-craftcommerce, matrix, products


---

## 1 answers

### Answer by username_1 on 2017-11-05. Score: 2 | Accepted answer

This should work:
{% set image = block.chooseProduct.first().mainProductImage.first() %}

Explanation:
your field handle in your product is called recommendProduct (matrix) that contains a relation chooseProduct. Your block.chooseProduct is an object of type ElementCriteriaModel so in order to fetch the product you need to call the first() method (or something similar). So if you have multiple products in your chooseProduct field your code would look like this 
{% for block in product.recommendProduct %}
{% set i = i + 1 %}
   
       {% for relatedProduct in block.chooseProduct %}
            {% set image = relatedProduct.mainProductImage.first() %}
            
            {{ relatedProduct.title }}
       {% endfor %} 
   
{% endfor %}


---

