开发者

Magento Invoice Excel Export - How do I change fields?

开发者 https://www.devze.com 2023-02-21 17:31 出处:网络
I want to export some invoices to Microsoft Excel / XML. The standard Format doesn\'t work very well because i need some extra columns.

I want to export some invoices to Microsoft Excel / XML. The standard Format doesn't work very well because i need some extra columns.

My question is: Where开发者_Python百科 is the file generated? Where do i set these special columns?

Thanks in advance


The export to Excel is performed when the InvoiceController calls getExcelFile() on the Mage_Adminhtml_Block_Sales_Invoice_Grid. The invoice Grid extends from the Mage_Adminhtml_Block_Widget_Grid which in turn calls _exportExcelItem on each row of the grid.

The _exportExcelItem method uses the grid's _columns private variable to export the spreadsheet columns.

All of which goes to say... that the _prepareColumns() method in Mage_Adminhtml_Block_Sales_Invoice_Grid sets the columns that are displayed in the grid, and exactly the same columns in the Excel export.

If you want to add extra columns, you could rewrite Mage_Adminhtml_Block_Sales_Invoice_Grid and redefine the _exportExcelItem() method with something like this:

$this->addColumn('your_extra_field_name', array(
        'header'    => Mage::helper('sales')->__('Field Title'),
        'index'     => 'your_extra_field_name',
        'type'      => 'relevant_data_type',
    ));
... rinse and repeat ... then finish with
parent::_exportIterateCollection($callback, array $args);

There are numerous posts on StackOverflow and the Intertubes on writing a custom module to extend a Block, grok those and then apply the specifics above.

This is the key piece of XML you need in your config.xml:

 <blocks>
        <adminhtml>
            <rewrite>
                 <sales_invoice_grid>Namespace_Modulename_Block_Rewrite_AdminhtmlSalesInvoiceGrid</sales_invoice_grid>
.... 

HTH,
JD


You could write a custom report that extends Mage_Adminhtml_Block_Sales_Invoice_Grid (and the container, Mage_Adminhtml_Block_Sales_Invoice).

The only difference it needs to do is call parent::_prepareColumns() then add your own columns. You can also use it's addColumnsOrder() to move them around.

You will also need to make a controller that works like Mage_Adminhtml_Report_SalesController::invoicedAction().


i wrote a complete new connection and class to the DB because i didn't get the right files. Thank you for all your help but this solution was much simpler it saved me about 5 days of work!

0

精彩评论

暂无评论...
验证码 换一张
取 消