2012-07-21 37 views
0

我有magento 1.6.2。Magento - 在銷售/訂單屏幕中顯示縮略圖

現在我想在銷售/訂單屏幕中顯示縮略圖。 經過一番谷歌我找到了一些解決辦法...

我已經添加了下一個代碼到應用/ design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml

<?php $product = Mage::getModel('catalog/product') 
->setStoreId($_item->getOrder()->getStoreId()) 
->load($_item->getProductId()); 
?> 
<p align="center"><img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(135); ?>" width="135" height="135" alt="" /></p> 

這適用於簡單的產品。 對於由可配置產品生成的簡單產品,我得到佔位符「無圖像」

備案: 當我製作可配置產品時,我的擴展程序不會爲簡單產品提供圖像。只有基礎(父級)可配置產品。

現在我需要從可配置產品中調用圖像,而不是簡單的產品。 誰能幫幫我?

回答

1

全部取決於是否顯示從(簡單)產品或主(可配置)產品的圖像。

對於第一種情況下下面的代碼應工作:

<td> 
    <?php $_product = Mage::getModel('catalog/product')->load($_item->getId()); ?> 
    <img src="<?php echo Mage::helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="" /> 
</td> 

對於第二種情況使用下面的代碼:

<td> 
    <?php 

    if($_item->getProductType() == 'configurable') { 
     $_product = $_item->getProduct(); 
    }else{ 
     $_product = Mage::getModel('catalog/product')->load($_item->getId()); 
    } 

    ?> 
    <img src="<?php echo Mage::helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="" /> 
</td> 

在這兩種情況下認罪請確保您有上傳併入選圖像一個small image爲您的產品。見下面的截圖:

enter image description here

+0

嗨蒂姆,第二種情況是我想要的。我已將此添加到文件中。但我得到了「無圖像」佔位符而不是產品的圖像。我試圖將small_image更改爲圖像或縮略圖。但我比我得到這些圖像的佔位符。你知道什麼是錯的嗎? – Ronny 2012-07-21 16:56:06

+0

這意味着您沒有爲您的可配置產品選擇默認的小圖像。 – 2012-07-21 17:51:30

+0

只有配置產品它自己有圖像(拇指,小圖和大圖)。與可配置產品相​​關的簡單產品沒有圖像。所以它必須選擇可配置產品的圖像 – Ronny 2012-07-21 18:09:53