2013-12-12 190 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');?

相關問題