Please excuse me if I am asking a dumb question, but I am new to Magento and frankly, my first impression is that it is over-designed and poorly documented. Maybe this is part of their business model, or maybe I am missing something. I hope I am missing something!

In my country, every invoice has to mention the date when was created and a date by which the client has to make the payment. The fact that (from what I can tell) Magento doesn't automatically generate an invoice for each order placed, tells me that these dates should be attributes of the invoice, and not attributes of the order.

I have made a plugin using the following code:


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="ideologic\RoInvoice\Model\Order\Pdf\Invoice" />
    <type name="Magento\Sales\Model\Order\Invoice">
        <plugin sortOrder="1" name="setDueDate" type="ideologic\RoInvoice\Model\Order\Invoice" />


 * Copyright © SC ideologic SRL, All rights reserved.
namespace ideologic\RoInvoice\Model\Order;

class Invoice

    public function beforeSetCreatedAt(\Magento\Sales\Model\Order\Invoice $invoice, $createdAt){
        return $createdAt;


But for some reason the addData() function call has no effect. When I am calling getData() from app/code/ideologic/RoInvoice/Model/Order/Pdf/Invoice.php I am getting a null value (or empty string).

From what I have read, I have to load the 'Model' before calling setData(). How do I do that? Any help will be appreciated!

1 Answer 1


I know this doesn't directly answer your question but is a solution to one of your issues.

Certain payment methods wont invoice automatically. They need manual attention.

I put together this externsion to automatically invoices orders based on certain conditions.


So solves that part

  • Thanks for the suggestion. I still want to add that that second date as an attribute of the invoice, and somehow, adding it to the order object seems wrong... Jun 11, 2019 at 22:10
  • Have you been able to add column to sales_order table or sales_invoice table yet? Doesn't really matter which. Just need to make sure you update the new date column in either table after invoice generation . Will be easier to work with updating order. Do you want to use event like checkout success or run something on schedule? Jun 12, 2019 at 0:15
  • I have managed to add the column in sales_invoice table. And I have a plugin beforeSetCreatedAt() in invoice in which I wish to set that attribute. But if i don't call $this->save(), the table column contains only NULL values, and if I do call $this->save(), it enters some kind of infinite loop, eating up all the memory. Jun 27, 2019 at 23:42
  • I could try to use an event instead of a plugin. But which one is triggered when the invoice is generated? I care more about the invoice than about the order, because the PayUntil date should be X days after the invoice was generated, not after the order was placed. I guess in some cases, could be a delay between the order placement and the invoice creation. I wouldn't want to auto-create the invoice, because the seller might have to check the product availability first. Jun 27, 2019 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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