Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
        );
}
like image 736
GaryZ Avatar asked Sep 16 '14 06:09

GaryZ


1 Answers

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'
        );
}
like image 164
tiriana Avatar answered Sep 28 '22 06:09

tiriana