Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Calling a new image attribute in list.phtml
 
hazardpro
Member
 
Avatar
Total Posts:  53
Joined:  2008-10-09
 

Hi all

I have added a new image attribute in the admin area called ‘matching_products’ and I want to call it from a modified list.phtml page Im working on.

The original code looks like this:

<div class="product-image">
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
            </
a>
        </
div>

And the changed code

<div class="product-image" style="margin-right:10px;">
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img src="<?php echo $this->helper('catalog/image')->init($_product, 'matching_products')->resize(270, 135); ?>" width="270" height="135" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
            </
a>
        </
div>

All I have done is changed the image source from ‘small_image’ to ‘matching_products’, which I would have thought was all I need to do for it to call the new image attribute?

What am I missing / where am I going wrong confused

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nobby
Jr. Member
 
Total Posts:  22
Joined:  2008-06-23
 

I think that to use a user defined attribute you need to declare it in your catalog.xml you need to add

<action method="addAttribute"><code>yourattribute</code></action>

into your

<catalog_category_default>

<
reference name="content">

section and in your

<catalog_category_layered>

<
reference name="content">

in the same file.

 
Magento Community Magento Community
Magento Community
Magento Community
 
hazardpro
Member
 
Avatar
Total Posts:  53
Joined:  2008-10-09
 

Hi Nobby

Thanks! That sorted it. grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
hazardpro
Member
 
Avatar
Total Posts:  53
Joined:  2008-10-09
 

Hmm strange it did work for a while, then all of a sudden pages/categories broke and I was getting 404’s everywhere, if I remove those two lines it all worked again :-(

Checked the error page and got this:

“Invalid attribute requested: matching_products”

Any ideas anyone? :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
hazardpro
Member
 
Avatar
Total Posts:  53
Joined:  2008-10-09
 

Sorted!

I forgot I changed the name and was calling the wrong name.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top