销售订单中的自定义列如何在magento中与市场多厂商扩展

时间:2015-05-01 06:54:47

标签: php mysql magento

我正在尝试在sales_order网格中添加列。我的专栏将是产品的卖家名称。我有一个多厂商市场扩展。 我发现卖家ID是客户ID,但我可以在卖家ID的帮助下找到全名。

我试图解决它,这是我使用的代码。

 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();
    }

现在我添加以下列。

    $this->addColumn('mageproownerid', array(
        'header' => Mage::helper('sales')->__('Seller ID'),
        'index' => 'mageproownerid',
    ));

Grid.php是:

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));
}

}

我想使用“marketplace_saleslist”字段“mageproownerid”上的join将上表与“customer_account”表联系起来。

我们如何找到客户的全名。

请让我知道解决方案。

谢谢和问候。

1 个答案:

答案 0 :(得分:0)

您可以在grid.php文件中创建辅助函数和更改列

$this->addColumn('mageproownerid', array(
    'header' => Mage::helper('sales')->__('Seller ID'),
    'index' => 'mageproownerid',
    'type'  =>  'options',  
    'options'   =>  Mage::helper('yourmodule')->getCustomerName(),
));