我在Magento的Order Grid中使用“Renderer”创建了一个自定义模块。 我创建了一个名为app / code / local / Od / Ordergridproduct / Block / Adminhtml / Renderer / ProductDetail.php的文件 这是我的代码:
<?php
class Od_Ordergridproduct_Block_Adminhtml_Renderer_ProductDetail extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$order=Mage::getModel('sales/order')->load($row['entity_id']);
$str="";
$i=1;
foreach($order->getAllItems() as $_order){
$str.="<b>".$_order->getProduct()->getName()."</b>";
$str.= "<br><b>Product Code:</b><br>".$_order->getSku();
if($i!=count($order->getAllItems()))
$str.=", ";
$i++;
}
$_product = Mage::getModel('catalog/product')->load($row['entity_id']);
$color_att = $_product->getAttributeText('color'));
$size_att = $_product->getAttributeText('size'));
$package_att = $_product->getAttributeText('package'));
$str.= "<br><b>Product Color:</b><br>".$color_att;
$str.= "<br><b>Product Package:</b><br>".$color_package;
unset($order);
return $str;
}
}
我有产品名称,但我需要在网格的同一列中显示产品属性(颜色,品牌,尺寸,包装)。我尝试在我的代码上添加以下行
$_product = Mage::getModel('catalog/product')->load($row['entity_id']);
$color_att = $_product->getAttributeText('color'));
$size_att = $_product->getAttributeText('size'));
$package_att = $_product->getAttributeText('package'));
$str.= "<br><b>Product Color:</b><br>".$color_att;
$str.= "<br><b>Product Package:</b><br>".$color_package;
但无法弄明白任何事情。有人可以帮帮我吗?希望得到积极的回应。
答案 0 :(得分:0)
$ _ product = Mage :: getModel('catalog / product') - &gt; load($ row ['entity_id']);
这是错误的代码b / z这里$ row ['entity_id']是订单ID而不是产品ID
public function render(Varien_Object $row)
{
$order=Mage::getModel('sales/order')->load($row['entity_id']);
$str="";
$i=1;
foreach($order->getAllItems() as $_order){
$str.="<b>".$_order->getProduct()->getName()."</b>";
$str.= "<br><b>Product Code:</b><br>".$_order->getSku();
$_product = Mage::getModel('catalog/product')->load($_order->getProductId());
$color_att = $_product->getAttributeText('color'));
$size_att = $_product->getAttributeText('size'));
$package_att = $_product->getAttributeText('package'));
$str.= "<br><b>Product Color:</b><br>".$color_att;
$str.= "<br><b>Product Package:</b><br>".$color_package;
if($i!=count($order->getAllItems()))
$str.=", ";
$i++;
}
unset($order);
return $str;
}
答案 1 :(得分:0)
我得到了答案。现在我可以在销售订单网格中显示产品属性的颜色,大小,包。这是代码:
public function render(Varien_Object $row)
{
$order = Mage::getModel('sales/order')->load($row['entity_id']);
$_items = $order->getItemsCollection();
$str="";
$i=1;
foreach($_items as $item){
if ($item->getParentItem()) continue;
$str.="<b>".$item->getName()."</b><br>";
$str.= "<br><b>Product Code:</b><br>".$item->getSku()."<br>";
}
foreach($order->getAllItems() as $_order){
$_product = Mage::getModel('catalog/product')->load($_order->getProductId());
$size_att = $_product->getAttributeText('size');
$package_att = $_product->getAttributeText('package');
if(!empty($size_att))
$str.= "<br><b>Package Contains:</b><br>".$package_att."<br>";
if(!empty($package_att))
$str.= "<br><b>Size:</b><br>".$size_att."<br>";
}
$items = $order->getAllItems();
$block = Mage::app()->getLayout()->createBlock('sales/order_item_renderer_default');
foreach ($items as $item) {
$block->setItem($item);
$_options = $block->getItemOptions();
foreach ($_options as $option) {
$label = $option['label'];
$textValue = $option['print_value'];
if(!empty($textValue))
$str.= "<br><b>Color:</b><br>".$textValue."<br>";
}
}
unset($order);
return $str;
}