2

同様の質問をしましたが、十分な詳細を提供できず、回答も得られなかったので、もう一度やり直します。

主なタスクは、magento admin sales->invoices の下でエクスポートされる CSV ファイルにフィールドを追加することです。編集するメインファイルを見つけました:

app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php

これには addColumn のようなオプションがあります:

    $this->addColumn('increment_id', array(
        'header'    => Mage::helper('sales')->__('Invoice #'),
        'index'     => 'increment_id',
        'type'      => 'text',
    ));

新しい列を追加しようとすると、インデックスを適切なデータベース フィールドに変更します。たとえば、「税額」としましょう。唯一の問題は、この新しい値が私の Magento コレクションにないことです。そのため、テーブルの空の列に値が入力されるだけです。

私は Magento を初めて使用するので、Magento コレクションがどのように機能するか、または grid.php のスコープでアクセスする方法を完全には理解していません。コレクションに追加する方法を教えてください。

私は本当に立ち往生しており、助けていただければ幸いです。

4

1 に答える 1

4

基本的に、リソースモデルを編集して、含めるフィールドを含める必要があります。コードでリソースを編集できます。使用しているバージョンはわかりませんが、Grid.phpファイルでは、_prepareCollectionが次のようなコードを検索します。

$collection = Mage::getResourceModel('sales/order_invoice_collection')
->addAttributeToSelect('order_id')
->addAttributeToSelect('increment_id')
->addAttributeToSelect('created_at')
->addAttributeToSelect('state')
->addAttributeToSelect('grand_total') ...and so on!

行を追加します

->addAttributeToSelect('tax_amount')

そのリストにあなたが使用できるはずです

$this->addColumn('tax_amount', array(
    'header'    => Mage::helper('sales')->__('Tax'),
    'index'     => 'tax_amount',
    'type'      => 'number',
));

これは、私が開発マシンから離れていて、Mageを手に入れることができないのと同じくらいテストされていませんが、これは機能するか、少なくとも正しい方向を示しているはずです。

編集:

_prepareCollection全体を置き換えてみることができませんでした

protected function _prepareCollection()
{

$collection = Mage::getResourceModel('sales/order_invoice_collection')
->addAttributeToSelect('order_id')
->addAttributeToSelect('increment_id')
->addAttributeToSelect('created_at')
->addAttributeToSelect('state')
->addAttributeToSelect('grand_total')
->addAttributeToSelect('tax_amount')
->addAttributeToSelect('order_currency_code')
->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
->joinAttribute('order_increment_id', 'order/increment_id', 'order_id', null, 'left')
->joinAttribute('order_created_at', 'order/created_at', 'order_id', null, 'left');

$this->setCollection($collection);
return parent::_prepareCollection();
}

繰り返しますが、これはテストされていません。メモリからは、これはmagentoの1.3範囲の_prepareCollectionであるため、少し古いですが、動作するはずです。

于 2011-07-13T20:04:15.880 に答える