如何在magento admin中显示带有销售订单网格的项目名称?
答案 0 :(得分:2)
$collection->getSelect()->joinLeft('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('total_qty_ordered'));
$collection->getSelect()->join(array(
'item'=>$collection->getTable('sales/order_item')),
'item.order_id=`main_table`.entity_id AND item.product_type="simple"',
array(
'skus' => new Zend_Db_Expr('group_concat(item.sku SEPARATOR ", ")'),
'name' => new Zend_Db_Expr('group_concat(item.name SEPARATOR ", ")')
));
$this->addColumn('skus', array(
'header' => Mage::helper('sales')->__('SKU'),
'index' => 'skus',
'type' => 'text',
));
$this->addColumn('name', array(
'header' => Mage::helper('sales')->__('NAME'),
'index' => 'name',
'type' => 'text'
));
$this->addColumn('total_qty_ordered', array(
'header' => Mage::helper('sales')->__('Qty'),
'index' => 'total_qty_ordered',
'filter_index' => 'sales_flat_order.total_qty_ordered',
));
答案 1 :(得分:-1)
您可以执行以下操作,这是为了在网格列中显示数量:
$this->addColumn('qty_ordered',
array(
'header'=> $this->__('Quantity'),
'align' =>'right',
'type' => 'number',
'index' => 'qty_ordered'
'renderer' = new Custom_AddQty_Block_Adminhtml_Renderer_Qty()
)
);
class Custom_AddQty_Block_Adminhtml_Renderer_Qty extends
Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
{
public function render(Varien_Object $row)
{
return $this->_getValue($row);
}
public function _getValue(Varien_Object $row)
{
$val = $row->getData($this->getColumn()->getIndex());
return intval($val);
}
}