Magento custom Upsell image not showing

906 Views Asked by At

I have a problem where I can't get my custom attribute called upsell to get shown as my upsell image.

Attribute information
Attribute code: upsell
Scope: Store View
Catalog Input type for store owner: Media Image
Apply To: All product Types

I have created the thumbnail in the skin/frontend/.../images/catalog/product/placeholder/

Here's the code to show the image

<img src="<?php echo $this->helper('catalog/image')->init($_item, 'upsell')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(150); ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" />

If I change the ($_item, 'upsell') to ($_item, 'thumbnail') it's showing the right thumbnail.

Did I miss something in the process of creating the attribute?

2

There are 2 best solutions below

6
On BEST ANSWER

ayTo call an image you can use: $this->helper('catalog/image')->init($_product, 'product_details_image')->resize()

and the full script is:

<?php
$_detailsImg = $this->helper('catalog/image')->init($_product,'product_details_image')->resize(); 

if ($_detailsImg != 'no_selection'):
    $_detailsImg ='<img src="'.$this->helper('catalog/image')->init($_product, 'product_details_image')->resize().'" alt="'.$this->htmlEscape($this->getImageLabel()).' "/>';
    echo $_helper->productAttribute($_product, $_detailsImg , 'product_details_image');
endif;

?>

Please change product_details_image to your attribute image code.

In case you don’t have image assigned to the product you will get this error : Image file was not found. in (var/ reports) so to fix this create an image with same name as the attribute code (product_details_image.jpg) to act as placeholder and add it to: skin/frontend/base/default/images/catalog/product/placeholder/ Also you can add it to your skin folder. that is it.

EDIT:

I would rewrite the upsell.phtml again, get all ids add it to an array call product collections, filter by ids and you are ready to call any attribute including the media image - and I can confirm this works for me

EDIT:

This is may sound stupid but I can't find any other way, I had to load the collection for each product I hope some one can find other way.

I did try to call one collection and filter it using products IDs ( up sell products IDs ) but it didn't work.

<?php if(count($this->getItemCollection()->getItems())): 
    $items = $this->getItemCollection()->getItems();
    ?>
<div class="box-up-sell">
    <ul class="products-grid up-sell-grid">
        <?php foreach ($items as $item):  ?>
            <li class="item">
                <?php $product = Mage::getModel('catalog/product')->load($item->getId()); ?>
                <span><?php echo $product->getName(); ?></span>
                <img src="<?php echo Mage::helper('catalog/image')->init($product, 'measurements_guide_image')->resize(200, 200); ?>" alt="">
            </li>
        <?php endforeach ?>
    </ul>
</div>
<?php endif ?>
1
On

You need to add this media attribute to product flat setting:

    <frontend>
    <product>
        <collection>
            <attributes>
                  <upsell/>
            </attributes>
        </collection>
    </product>
</frontend>

At this code at my module config.xml and then you need to reindex from index management.