Magento 1.9 - 在订单历史页面中显示可配置的产品图片
Magento 1.9 - Displaying Configurable product image in Order History page
我在用户仪表板的 "My Order" 中显示订购产品的图像。
<?php
$orderId = $_order->getId();
$order = Mage::getModel('sales/order')->load($orderId);
$items = $order->getAllItems();
foreach ($items as $itemId => $_item)
{
if($_item->getProductType() == 'configurable')
{
$product = $_item->getProduct();
}else{
$product = Mage::getModel('catalog/product')->setStoreId($_item->getOrder()->getStoreId())->load($_item->getProductId());
}
?>
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); ?>" width="75" height="75" />
<?php }?>
一切正常。但它显示可配置产品的所有图像。我想显示选定的可配置简单产品图像。
任何帮助将不胜感激
使用下面的代码:
<?php $orderId = $_order->getId(); ?>
<?php $order = Mage::getModel('sales/order')->load($orderId); ?>
<?php foreach ($order->getAllItems() as $itemId => $_item): ?>
<?php if($_item->getProductType() == 'configurable') :?>
<?php $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku()); ?>
<?php else: ?>
<?php $product = Mage::getModel('catalog/product')->setStoreId($_item->getOrder()->getStoreId())->load($_item->getProductId()); ?>
<?php endif; ?>
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); ?>" width="75" height="75" />
<?php endforeach; ?>
希望对您有所帮助!
我用 getAllVisibleItems
而不是 getAllItems
,现在可以用了。
<?php
$orderId = $_order->getId();
$order = Mage::getModel('sales/order')->load($orderId);
$items = $order->getAllVisibleItems();
foreach ($items as $itemId => $_item){
if($_item->getProductType() == 'configurable'){
$product = $_item->getProduct();
}else{
$product = Mage::getModel('catalog/product')->setStoreId($_item->getOrder()->getStoreId())->load($_item->getProductId());
}?>
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); ?>" width="75" height="75" />
<?php }?>
我在用户仪表板的 "My Order" 中显示订购产品的图像。
<?php
$orderId = $_order->getId();
$order = Mage::getModel('sales/order')->load($orderId);
$items = $order->getAllItems();
foreach ($items as $itemId => $_item)
{
if($_item->getProductType() == 'configurable')
{
$product = $_item->getProduct();
}else{
$product = Mage::getModel('catalog/product')->setStoreId($_item->getOrder()->getStoreId())->load($_item->getProductId());
}
?>
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); ?>" width="75" height="75" />
<?php }?>
一切正常。但它显示可配置产品的所有图像。我想显示选定的可配置简单产品图像。
任何帮助将不胜感激
使用下面的代码:
<?php $orderId = $_order->getId(); ?>
<?php $order = Mage::getModel('sales/order')->load($orderId); ?>
<?php foreach ($order->getAllItems() as $itemId => $_item): ?>
<?php if($_item->getProductType() == 'configurable') :?>
<?php $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku()); ?>
<?php else: ?>
<?php $product = Mage::getModel('catalog/product')->setStoreId($_item->getOrder()->getStoreId())->load($_item->getProductId()); ?>
<?php endif; ?>
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); ?>" width="75" height="75" />
<?php endforeach; ?>
希望对您有所帮助!
我用 getAllVisibleItems
而不是 getAllItems
,现在可以用了。
<?php
$orderId = $_order->getId();
$order = Mage::getModel('sales/order')->load($orderId);
$items = $order->getAllVisibleItems();
foreach ($items as $itemId => $_item){
if($_item->getProductType() == 'configurable'){
$product = $_item->getProduct();
}else{
$product = Mage::getModel('catalog/product')->setStoreId($_item->getOrder()->getStoreId())->load($_item->getProductId());
}?>
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); ?>" width="75" height="75" />
<?php }?>