[英]How to get access to custom Image Attribute in list.phtml in Magento
I am creating a website in magento. 我正在magento中创建一个网站。
So i have added a new media image attribute to my products. 因此,我在产品中添加了新的媒体图片属性。 I want to use a specific image for my homepage but a few products will not have this image. 我想为主页使用特定的图像,但是有些产品将没有该图像。
So i have created a new list.phtml file called list-homepage.phtml. 因此,我创建了一个名为list-homepage.phtml的新list.phtml文件。
so i am doing this at the moment within product collection for loop in list.phtml. 所以我现在在list.phtml中的循环产品集合中执行此操作。
$product=Mage::getModel('catalog/product')->load($_product->getId());
i am loading the product again from above, and i test to see if this product has the new image attribute 我从上方再次加载产品,然后测试以查看该产品是否具有新的图片属性
<?php if ($product->getMaleFemaleImage()){ ?>
<img src="<?php echo $this->helper('catalog/image')->init($product, 'male_female_image')->setQuality(100)->resize($imgSize); ?>" width="<?php echo $imgSize ?>" height="<?php echo $imgSize ?>" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'male_female_image'), null, true) ?> " />
<?php }else{ ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->setQuality(100)->resize($imgSize); ?>" width="<?php echo $imgSize ?>" height="<?php echo $imgSize ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php }?>
This works BUT As you can see from above i have to load the product again and i do not want to do this. 从上面您可以看到,但是我必须再次加载产品,而我不想这样做。 Is there any way to get access to the male_female_image attribute i have created. 有什么办法可以访问我创建的male_female_image属性。
Take a look @ Magento - add media gallery attribute to product flat table 看看@ Magento-向产品平面表添加媒体库属性
Open app/design/frontend/default/yourtheme/layout/catalog.xml 打开app / design / frontend / default / yourtheme / layout / catalog.xml
In <catalog_category_layered translate="label">
and <catalog_category_default translate="label">
find the line below 在<catalog_category_layered translate="label">
和<catalog_category_default translate="label">
找到以下行
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
and (add <action method="addAttribute">
....) 和(添加<action method="addAttribute">
...。)
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
add --> <action method="addAttribute"><name>MaleFemaleImage</name></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
Read more @ 阅读更多 @
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.