Search code examples
symfonycsvexportsonata-admin

Customise exported CSV content of Sonata Admin bundle


I'm new to sonata admin bundle. Now, I am try to export a csv file with something like: 'customer.phone', 'order.total'... but when I opened the csv file, in the field 'order.total' is only '99.99', I would like it to export as 'AUD $99.99', anyone know how I can achieve it? Thank a lot! The code is here:

public function getExportFields() {
    return array('id','customer.First_name','customer.Last_name',
        'customer.contact','total_amount'
        );
}

Solution

  • You need to define method getTotalAmountFormated in your Order class, and make it return string that you need. Then add totalAmountFormated (or total_amount_formated, I think both should work) in array returned from getExportFields

    public function getExportFields() {
        return array('id','customer.First_name','customer.Last_name',
            'customer.contact','totalAmountFormated'
            );
    }