Magento - 将订单代码添加到订单网格

时间:2011-12-06 14:17:31

标签: magento

如何让客户发送邮政编码显示在订单网格的列中?

谢谢!

2 个答案:

答案 0 :(得分:1)

创建自定义模块并覆盖<sales_order_grid>

在你的Grid.php中,你需要做两件事:

  1. 告诉Magento在哪里可以找到邮政编码

  2. 告诉Magento把它放在哪里

  3. 告诉Magento在何处查找信息的最佳方法是setCollection函数。从_prepareCollection中调用此函数,因此您不必弄乱该函数。

    public function setCollection($collection)
    {
        parent::setCollection($collection);
        $collection->getSelect()
            ->join(
                array('address' => $collection->getTable("sales/order_address")),
                'main_table.entity_id = address.parent_id AND address.address_type = "shipping"',
                array('postcode')
            );
    }
    

    在这里你做了一个连接并定义了可以使用别名'postcode'找到信息

    现在剩下的就是告诉Magento把它放在哪里。只需覆盖_prepareColumn函数:

    protected function _prepareColumns()
    {
        parent::_prepareColumns();
    
        $this->addColumn('postcode',
            array(
                'header'    => Mage::helper('sales')->__('Postcode'),
                'index'     => 'postcode'
            )
        );
    
        return $this;
    }
    

    index是指您在setCollection函数中设置的名称。 如果要将列放到特定位置,则应使用addColumnAfter()

    希望有所帮助

答案 1 :(得分:0)

在你的模型网格中,

_prepareColumns()函数中的

确保

    $this->setData('column_filters',array('shippingpostcode' => 'mymodule/sales_order_filter_shippingpostcode'));
    $this->addColumn('shippingpostcode', array(
        'header'=> Mage::helper('sales')->__('Shipping Postcode'),
        'width' => '80px',
        'type'  => 'text',
        'index' => 'shipping_postcode', //you would need this field in your order table
        'renderer' => 'mymodule/sales_order_renderer_shippingpostcode',
    ));

并创建一个类

Mymodule_Model_Sales_Order_Render_Shippingpostcode extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Abstract

并且在函数getHtml中,您可以返回要在Grid上呈现的任何值。

相关问题