2

我问了一个类似的问题,但我没有提供足够的细节,也没有得到答案,所以我会再试一次。

主要任务是将字段添加到在 magento admin sales->invoices 下导出的 CSV 文件中。我找到了要编辑的主文件:

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

这具有添加列的选项,如下所示:

    $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',
));

这就像我离开我的开发机器并且手头没有法师一样未经测试,但这应该可以工作,或者至少可以为您指明正确的方向。

编辑:

如果您无法尝试更换整个 _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 回答