2014-04-02 129 views
0

我试图向Magento的销售订单网格添加一个新列(管理>销售>订单)。我想下面设在这里说明: http://www.atwix.com/magento/customize-orders-grid/Magento - 向销售订单网格添加新列不工作

我抄核心文件到本地文件夹,所以我可以重写它:

来源:/的public_html /批发/应用/代码/核心/法师/ Adminhtml /Block/Sales/Order/Grid.php

要:/public_html/wholesale/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

有什么奇怪的是,无论我对任何文件做了什么修改,管理端没有任何变化。我什至不能得到一个法师::日志()工作。

一旦我解决了这个问题,我需要确保我所做的更改是正确的。我只是想获取客户的公司名称。这里有两件,我说:

protected function _prepareCollection() 
{ 
    // This line is from the original 
    $collection = Mage::getResourceModel($this->_getCollectionClass()); 

    // This is the call where I try to bring in the extra field 
    // from another sales table 
    $collection->getSelect()->join(
     'sales_flat_order_address', 
     'sales_flat_order.entity_id = sales_flat_order_address.parent_id', 
     array('company') 
    ); 

    // These lines are also default 
    $this->setCollection($collection); 
    return parent::_prepareCollection(); 
} 

在_prepareColumns():

$this->addColumn('company', array(
    'header' => Mage::helper('sales')->__('Company'), 
    'index' => 'billing_company', 
)); 

仅供参考,我使用的Magento 1.7.0.2

谢谢您的时间!

回答

0

试试这个:

protected function _prepareCollection() 
{ 
    // This line is from the original 
    $collection = Mage::getResourceModel($this->_getCollectionClass()); 

    // Join billing 'company' field from sales_flat_order_address table 
    $collection->getSelect()->join(
     array('addressTable' => 'sales_flat_order_address'), 
     'main_table.entity_id = addressTable.parent_id AND addressTable.address_type = "billing"', 
     array('billing_company'=>'company') 
    ); 

    // These lines are also default 
    $this->setCollection($collection); 
    return parent::_prepareCollection(); 
} 

protected function filterBillingCompany($collection, $column) { 
    $val = (string)trim($column->getFilter()->getValue()); 
    if ($val != "") { 
     $collection->getSelect()->where("addressTable.company LIKE '%{$val}%'"); 
    } 
    return $this; 
} 

在_prepareColumns():

$this->addColumn('company', array(
    'header' => Mage::helper('sales')->__('Company'), 
    'index' => 'billing_company', 
    'filter_condition_callback' => array($this, 'filterBillingCompany'), 
)); 
相关问题