I am trying to add column in my sales_order grid. My column will be seller name of the product. I have a multivendor marketplace extension. I find the seller id which is the customer id but I can find the full name with the help of seller id.
I trying to solve it and here is the code that i used.
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('marketplace_saleslist', 'main_table.entity_id = marketplace_saleslist.mageorderid',array('mageproownerid'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
And now I add the following column.
$this->addColumn('mageproownerid', array(
'header' => Mage::helper('sales')->__('Seller ID'),
'index' => 'mageproownerid',
));
The Grid.php is :
public function __construct()
{
parent::__construct();
$this->setId('sales_order_grid');
$this->setUseAjax(true);
$this->setDefaultSort('created_at');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
}
protected function _getCollectionClass()
{
return 'sales/order_grid_collection';
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('marketplace_saleslist', 'main_table.entity_id = marketplace_saleslist.mageorderid',array('mageproownerid'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type' => 'text',
'index' => 'increment_id',
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', array(
'header' => Mage::helper('sales')->__('Purchased From (Store)'),
'index' => 'store_id',
'type' => 'store',
'store_view'=> true,
'display_deleted' => true,
));
}
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'created_at',
'type' => 'date',
'format'=> 'M/d/y',
'width' => '100px',
));
$this->addColumn('mageproownerid', array(
'header' => Mage::helper('sales')->__('Seller ID'),
'index' => 'mageproownerid',
));
$this->addColumn('shipping_name', array(
'header' => Mage::helper('sales')->__('Ship to Name'),
'index' => 'shipping_name',
));
$this->addColumn('base_grand_total', array(
'header' => Mage::helper('sales')->__('G.T. (Base)'),
'index' => 'base_grand_total',
'type' => 'currency',
'currency' => 'base_currency_code',
));
$this->addColumn('grand_total', array(
'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
'index' => 'grand_total',
'type' => 'currency',
'currency' => 'order_currency_code',
));
$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => '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'=>'adminhtml/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);
$this->getMassactionBlock()->addItem('approve_order', array(
'label'=> Mage::helper('sales')->__('Approve Order'),
'url' => $this->getUrl('*/*/massstatus'),
));
return $this;
}
public function getRowUrl($row)
{
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
return $this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getId()));
}
return false;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
I want to relate the above table with "customer_account" table using join on "marketplace_saleslist" field "mageproownerid".
How can we find the customer fullname.
Please let me know the solutions.
Thanks and regards.
You can create helper function and change column in grid.php file
$this->addColumn('mageproownerid', array(
'header' => Mage::helper('sales')->__('Seller ID'),
'index' => 'mageproownerid',
'type' => 'options',
'options' => Mage::helper('yourmodule')->getCustomerName(),
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.