公司要求在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能够同时调用了
把代码改成如下:
$collection->getSelect()->joinLeft('sales_flat_invoice', 'main_table.entity_id = sales_flat_invoice.entity_id',array('shipping_amount','tax_amount'));
成功解决。花了三天才弄好。。
截个图