Magento invoice grid下新增column 如shipping amount, tax amount, subtotal,payment method

公司要求在magento后台的sales/invoice的列表中,新增几列数据, shipping amount, tax amount, subtotal,payment method。

subtotal 和payment method这两个都挺好弄。很快弄好了。 

在路径app/code/core/Mage/Adminhtml/Block/Sales/Invoice/grid.php下面添加两句代码。代码加在  protected function _prepareCollection()下面。

$collection->join('invoice', 'main_table.entity_id = invoice.entity_id', 'subtotal');
$collection->getSelect()->joinLeft('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id','method');


运费和税率的code分别是shipping amount和 tax_amount,这个确保了肯定正确。但是一直调用不出来。后来研究出调用语句

$collection->getSelect()->joinLeft('sales_flat_invoice', 'main_table.entity_id = sales_flat_invoice.entity_id','shipping_amount');

$collection->getSelect()->joinLeft('sales_flat_invoice', 'main_table.entity_id = sales_flat_invoice.entity_id','tax_amount');

这两句不能同时用,否则后台invoice报错,如果只放其中一句,那都是正确显示的。

把代码改为

$collection->getSelect()->joinLeft('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id','shipping_amount');

后台可以正常显示,也都有数据出来。tax的数据是正确的,但是shipping amount的是不正确的。乱了。

所以还是只能从invoice里面调用shipping method。 这就要求tax amount 和shipping amount能够同时调用了

查看了很多资料。了解到要用到 array

把代码改成如下:

$collection->getSelect()->joinLeft('sales_flat_invoice', 'main_table.entity_id = sales_flat_invoice.entity_id',array('shipping_amount','tax_amount'));

成功解决。花了三天才弄好。。

截个图


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值