简体   繁体   中英

Add New Product Image Type (Attribute) in Magento

I am trying to add a new image type in the product admin panel. I created a new attribute (hero_banner) set it's type to media image (similar to how the thumbnail image and small_image have been set up). I then added it to the Default attribute set under images. It appears fine in the admin panel and allows you to assign images as the hero but then when I try and echo the image path into the phtml the templates stop rendering. The code I am using to echo the image is below:

<?php echo $this->helper('catalog/image')->init($_product, 'hero_banner'); ?>

This is being done within a product foreach iteration so I have the $_product variable and I am able to echo other images fine (such as thumbnail, small_image etc). What am I doing wrong?

I think you have to select this attribute too in your collection like this before the collection is actually loaded:

$productCollection->addAttributeToSelect('hero_banner');

It works fine on my code, but I dont know if you already have rewrited the block where your collection is defined (it won't work in your template since the collection is already loaded there) Maybe you can configure your hero_attribute to add this addAttributeToSelect directly in Magento back office, I'll have a look

Edit: Ok, I think I've got it, you won't have to worry about collection & rewrites :) If you use this attribute on product listing, you have to set the property "visible on product listing" to true to your image attribute (in the admin panel attribute management)

Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM