Sign in to follow this  

How to overwrite default invoice PDF which is sent to Amazon

Recommended Posts


I have a Magento2 with the M2E extension running to manage Amazon products and orders.

Currently the system automatically uploads the PDF invoice to Amazon. But it is the default one. I am using another module to create invoice PDF. This is working everywhere in Magento but not in M2E.

I already found the file, where the pdf render function is called in m2e but passing my own PDF file stream string instead fails without an error. (Model/Cron/Task/Amazon/Order/SendInvoice.php line241)

It only displays that the merchant did not upload a PDF in the amazon administration.

As this code is called from the cron it is hard to debug and find out what is wrong.

Also I always have to wait for the next order to check if this is working.

Has anybody done this before? 


Thanks in advance 

Share this post

Link to post
Share on other sites

Okay, I have an update - in case someone is interested and I manage to solve this, it is possible to see my steps for the progress:

I used a custom module with a plugin to override the magento model which initiates the pdf:

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Model\Order\Pdf\Invoice">
        <plugin name="overwrite_m2e_amazon_order_pdfinvoice" type="MyVendor\MyModule\Plugin\Model\Order\PdfInvoice" />

This is working great. I tested this by creating a class which is calling the invoice pdf in exact the same way, M2e is doing this in vendor/m2epro/magento2-extension/Model/Cron/Task/Amazon/Order/SendInvoice.php on line 245 - 253.
With my plugin, the desired PDF is created. Without the plugin, the old magento default PDF is created.

If I know upload this and check what M2e is doing in the situation of creating a new invoice, I see the following error message:


Invoice #xxxxxxx was not sent. Reason: Please provide metadata:totalamount,metadata:totalvatamount

And this is very confusing. 
I did not found any ocurrency of this metadata anywhere in the m2e code. Furthemore, I did not change anything other than replacing the method for rendering the pdf.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this