2013-12-12 148 views
0

我需要重新调整XML Feed的图像大小。我正在循环浏览产品,但试图获取重新调整大小的图像的URL时,我遇到了问题。如何从产品集合中获取产品图片网址?

foreach ($collection as $_product) { 

$MainImage = Mage::helper('catalog/image')->init($_product, 'small_image')->constrainOnly(false)->keepAspectRatio(true)->keepFrame(true) 
->keepTransparency(true)->resize(300, 150); 

$arr['Image'] = $_product->getSmallImageUrl(); 
$arr['MainImage'] = $MainImage; 
$arr['Name'] = $_product->getName(); 

} 

如果我回显$ MainImage它会返回一个URL,但由于某种原因,它不喜欢在一个字符串中。

基本上,如果我然后回显数组它不显示图像的URL,它只是空白。

任何人都可以指向正确的方向吗?

回答

0

如果你看看@ /app/design/frontend/default/base/template/catalog/product/view/media.phtml

$_helper = Mage::helper('catalog/output'); 

.... 
foreach ($collection as $_product) { 
    $MainImage = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(410,420); 
    $MainImage = $_helper->productAttribute($_product, $MainImage, 'small_image'); 

或转换返回字符串作为

$MainImage = (string)Mage::helper('catalog/image')->init($_product, 'small_image')->constrainOnly(false)->keepAspectRatio(true)->keepFrame(true)->keepTransparency(true)->resize(300, 150); 
0

你尝试

$改编[ 'MainImage'] =(字符串)法师::助手( '目录/图片') - >初始化($ _产品 'small_image');?

相关问题