In order grid, two records with same Order ID are shown when the product is configurable product that has child product so-called simple product. I only want child product (simple product). I don't want parent product (configurable product). But the child simple product record only shows zero in Total column while the parent configurable product record shows total amount in Total column . What I want to get is the child simple product with the Total amount extracted from parent configurable product.
<?php
class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('sales_order_grid');
$this->setUseAjax(true);
$this->setDefaultSort('created_at');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
}
/**
* Retrieve collection class
*
* @return string
*/
protected function _getCollectionClass()
{
return 'sales/order_collection';
}
protected function _prepareCollection()
{
/*$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ", ")'),
'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ", ")'),
'qtys' => new Zend_Db_Expr('group_concat(`sales/order_item`.qty_ordered SEPARATOR ", ")'),
//'proptions' => new Zend_Db_Expr('group_concat(`sales/order_item`.product_options SEPARATOR "<br><hr>")'),
)
); */
$collection = Mage::getModel('sales/order_item')->getCollection()
->addFieldToSelect(array('order_id','sku','name','qty_ordered','product_id','product_options','row_total'))
//->setOrder('main_table.order_id', 'desc');
->setOrder('main_table.created_at', 'desc');
// $collection->getSelect()->group('main_table.order_id');
$collection->getSelect()->joinLeft(
array('sfog' => 'sales_flat_order_grid'),
'main_table.order_id = sfog.entity_id',
array('sfog.shipping_name','sfog.billing_name','sfog.increment_id')
);
$collection->getSelect()->joinLeft(
array('sfo'=>'sales_flat_order'),
'sfo.entity_id=main_table.order_id',
array('sfo.customer_email','sfo.weight',
'sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status',
'sfo.base_grand_total','sfo.grand_total')
);
//Join Invoice Grid
$collection->getSelect()
->joinLeft(
array('sfi' => 'sales_flat_invoice_grid'),
'sfi.order_id= main_table.order_id',
array(
'sfi.increment_id as invoice_increment_id'
)
);
/*//Product Options
$collection->getSelect()->joinLeft(
array('sfo'=>'sales_flat_order'),
'sfo.entity_id=main_table.order_id',
array('sfo.customer_email','sfo.weight',
'sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status',
'sfo.base_grand_total','sfo.grand_total')
);
//Product Options */
$this->setCollection($collection);
return parent::_prepareCollection();
}
public function callback_skus($value, $row, $column, $isExport) {
$_items = Mage::getModel('sales/order')->loadByIncrementId($value)->getAllItems();
$skus_arr = array();
foreach ($_items as $item) {
array_push($skus_arr, $item->getSku());
}
$skus_arr = array_unique($skus_arr);
return implode("<br/>",$skus_arr);
}
public function callback_qtys($value, $row, $column, $isExport) {
$_items = Mage::getModel('sales/order')->loadByIncrementId($value)->getAllItems();
$skus_arr = array();
foreach ($_items as $item) {
array_push($qtys_arr, $item->getQtyOrdered());
}
$skus_arr = array_unique($qtys_arr);
return implode("<br/>",$qtys_arr);
}
protected function _prepareColumns()
{
$this->addColumn('invoice_id', array(
'header' => Mage::helper('sales')->__('Invoice #'),
'index' => 'invoice_increment_id',
'type' => 'text',
'filter_index'=>'sfi.increment_id',
));
$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type' => 'text',
'index' => 'increment_id',
'filter_index' => 'sfog.increment_id',
));
/* $this->addColumn('tt', array(
'header'=> Mage::helper('sales')->__('Options'),
'width' => '80px',
'type' => 'text',
'index' => 'proptions',
//'filter_index' => 'sfog.increment_id',
));*/
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'created_at',
'filter_index' => 'sfo.created_at',
'type' => 'datetime',
'width' => '50px',
));
$this->addColumn('billing_name', array(
'header' => Mage::helper('sales')->__('Bill to Name'),
'index' => 'billing_name',
'filter_index' => 'sfog.billing_name',
));
$this->addColumn('names', array(
'header' => Mage::helper('sales')->__('Product Name'),
'index' => 'name',
'filter_index' => 'name',
));
/*
$this->addColumn('Options', array(
'header' => Mage::helper('sales')->__('Product Option'),
'index' => 'product_options',
'filter_index' => 'product_options',
));*/
$this->addColumn('Product Option', array(
'header' => Mage::helper('sales')->__('Product Option'),
'width' => '150',
'index' => 'product_options',
'filter_index' => 'product_options',
'renderer' => new Mage_Adminhtml_Block_Renderer_Data() // added this line
));
$this->addColumn('qtys', array(
'header'=> Mage::helper('sales')->__('Quantity'),
'align' => 'center',
'type=' => 'text',
'index' => 'qty_ordered',
'filter_index' => 'qty_ordered',
//'frame_callback' => array($this, 'callback_qtys')
//'renderer' => new Mage_Adminhtml_Block_Renderer_Date()
));
/* $this->addColumn('increment_id', array(
'header' => Mage::helper('sales')->__('SKU'),
'index' => 'increment_id',
'align' => 'center',
'filter_index' => 'sfo.increment_id',
'frame_callback' => array($this, 'callback_skus')
));*/
$this->addColumn('increment_id', array(
'header' => Mage::helper('sales')->__('SKU'),
'index' => 'sku',
'align' => 'center',
'filter_index' => 'sku',
// 'frame_callback' => array($this, 'callback_skus')
));
$this->addColumn('customer_email', array(
'header' => Mage::helper('sales')->__('Customer Email'),
'index' => 'customer_email',
'type' => 'text',
'filter_index' => 'sfo.customer_email',
));
$this->addColumn('Total', array(
'header' => Mage::helper('sales')->__('Total'),
'index' => 'row_total',
'filter_index' => 'row_total',
'type' => 'currency',
'currency' => 'order_currency_code',
));
/*$this->addColumn('grand_total', array(
'header' => Mage::helper('sales')->__('Total'),
'index' => 'grand_total',
'filter_index' => 'sfo.grand_total',
'type' => 'currency',
'currency' => 'order_currency_code',
));*/
$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'filter_index' => 'sfo.status',
'type' => 'options',
'width' => '70px',
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
));
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
$this->addColumn('action',
array(
'header' => Mage::helper('sales')->__('Action'),
'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('View'),
'url' => array('base'=>'*/sales_order/view'),
'field' => 'order_id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
}
$this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS'));
$this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
$this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
return parent::_prepareColumns();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('order_ids');
$this->getMassactionBlock()->setUseSelectAll(false);
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
$this->getMassactionBlock()->addItem('cancel_order', array(
'label'=> Mage::helper('sales')->__('Cancel'),
'url' => $this->getUrl('*/sales_order/massCancel'),
));
}
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
$this->getMassactionBlock()->addItem('hold_order', array(
'label'=> Mage::helper('sales')->__('Hold'),
'url' => $this->getUrl('*/sales_order/massHold'),
));
}
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
$this->getMassactionBlock()->addItem('unhold_order', array(
'label'=> Mage::helper('sales')->__('Unhold'),
'url' => $this->getUrl('*/sales_order/massUnhold'),
));
}
$this->getMassactionBlock()->addItem('pdfinvoices_order', array(
'label'=> Mage::helper('sales')->__('Print Invoices'),
'url' => $this->getUrl('*/sales_order/pdfinvoices'),
));
$this->getMassactionBlock()->addItem('pdfshipments_order', array(
'label'=> Mage::helper('sales')->__('Print Packingslips'),
'url' => $this->getUrl('*/sales_order/pdfshipments'),
));
$this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
'label'=> Mage::helper('sales')->__('Print Credit Memos'),
'url' => $this->getUrl('*/sales_order/pdfcreditmemos'),
));
$this->getMassactionBlock()->addItem('pdfdocs_order', array(
'label'=> Mage::helper('sales')->__('Print All'),
'url' => $this->getUrl('*/sales_order/pdfdocs'),
));
$this->getMassactionBlock()->addItem('print_shipping_label', array(
'label'=> Mage::helper('sales')->__('Print Shipping Labels'),
'url' => $this->getUrl('*/sales_order_shipment/massPrintShippingLabel'),
));
return $this;
}
public function getRowUrl($row)
{
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
// return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
return $this->getUrl('*/sales_order/view', array('order_id' => $row->getOrderId()));
}
return false;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
Best Answer
Naing,add parent id filter
To