0

I'm using EaDesgin/magento2-pdf-generator2 to format the customer's invoice. This works nice. But in this template I use the magento 2 variable {{var invoice.created_at}}, what gives me the ugly format 'yyyy-mm-dd h:i:s'.

I want to reformat this date. Maybe I could add a custom variable (not with backend, there I cannot use PHP functions), or a filter to invoice.created_at. Where can I do that?

2

I solved the problem by adding a new function to Model/Order/Invoice.php:

public function getInvoiceDate(){
        $cdate = $this->getCreatedAt();
        $invoiceDate = date('d. M. Y', strtotime($cdate));
        return $invoiceDate;
    }

Then you can use {{var invoice.invoice_date}} to display the formatted date.

Tested with Magento 2.2.3 and EADesign Invoice PDF Generator 1.2.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.