0

Magento の販売注文グリッド (管理 > 販売 > 注文) に新しい列を追加しようとしています。ここにある指示に従ってみました: http://www.atwix.com/magento/customize-orders-grid/

上書きできるように、コア ファイルをローカル フォルダーにコピーしました。

送信元: /public_html/wholesale/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

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

興味深いのは、EITHER ファイルにどんな変更を加えても、管理者側では何も変わらないことです。Mage::log() を動作させることさえできません。

その問題を乗り越えたら、行っている変更が正しいものであることを確認する必要があります。私は顧客の会社名を取得しようとしているだけです。今回追加したのは以下の2点です。

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を使用しています

4

1 に答える 1

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'),
));
于 2014-06-26T10:18:11.323 に答える