Invoice is an obligatory commercial document used by you and millions of other online stores.
How to stand out in such a competitive environment?
How to make the document clear, unique without high costs?
Today we will talk about how to make it without any dev skills. We will consider how to make invoices automatically, attach a PDF invoice to email, and create a custom PDF version.
How to generate automatically sent invoices in Magento 2 programmatically
сAll Magento 2 merchants seek to customize invoice PDF to reduce the time spent on the process and be bright against competitors. However, to make it automatically, you need to develop a custom module.
If you don’t want to waste money on custom extension development or have no time to develop extensions by yourself, then you can try our Mass Order Actions. This module allows you to create invoices in bulk on the order grid. You don’t need anymore to open every order one by one to make an invoice. Save your time for more important deals!
Say, you are sure in your development skills, and you want to create a custom module. So, take a look at the following tips that we have prepared for you.
Step 1. Go to app/code/<Vendor>/<Module>/etc, create module.xml, and insert the following code:
Step 2. Add registration.php to app/code/<Vendor>/<Module> and register the mod by entering the code:
Step 3. Then go to <Vendor>/<Module>/etc and create events.xml. Please use this code:
Step 4. For this step, you need to create an observer class. Go to <Vendor>/<Module>/Observer and add file CheckoutAllSubmitAfterObserver.php, then enter the code:
Step 5. The last what you need to do is create a file Data.php in <Vendor>/<Module>/Helper and paste this code:
Step 6. The last what we will create now is the file that allows to turn on and off this module in admin panel. Create <Vendor>/<Module>/etc/adminhtml/system.xml and use the following code:
And that’s all.
Run following commands after installing this module:
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
php bin/magento setup:upgrade
Now invoices will be created automatically.
How to attach a PDF invoice to an email in Magento 2
Adding a PDF invoice to a confirmation email is another common challenge. And we have two solutions for you.
If you have good technical skills, you can try to create a custom module for this option. Below you will find instructions that will help you with this.
Or you can create a custom invoice with Magento 2 PDF Customizer. This plugin allows you to design a new template right in the admin panel by using an HTML/CSS tool and attach it to your invoice emails. You can set this in a few clicks. Let’s consider a fast example. Go to Stores>Configuration>Amasty Extensions>PDF Customizer>Invoice, choose a template from the list and select Yes in the Add PDF Attachment to Emails to Clients Automatically drop-down:
And that’s all, so simple.
If you still feel like coding is what you need, follow the instructions below.
Step 1. Create and register a new module like it was shown at the beginning of the article. The module.xml, registration.php files should be in every new module.
Step 2. Next, you need to override InvoiceOrder in Magento/Sales/Model and add this comment:
Step 3. Now you need to create events.xml in <Vendor>/<Module>/etc with code:
Step 4. Add observer sales_order_shipment_save_after in <Vendor>/<Module>/Observer then enter the code:
Customize your PDF invoice
Add your logo to PDF invoice using vanilla admin panel settings
You can customize PDF invoice only with your logo and address in default Magento. To do it go to Stores>Configuration:
Choose Sales in the Sales tab:
Open Invoice and Packing Slip Design and browse the image:
Then click the Save Config button.
Advanced customization options with Amasty PDF invoice module
If you want to get more customization options, try our PDF Customizer for Magento 2. It has an HTML/CSS editor where you can change the text of your PDF file, add variables, change fonts, colors, add a logo, etc. To do this, go to Marketing>Amasty PDF Templates. Click the Add New Template button:
Choose the needed pattern from the drop-down and load it. There is not only an Invoice template, but also Credit Memo, Order, and Shipment:
Then you will see where this template is already used. You need to give a title to the template, can change content, and styles:
What’s even more convenient, now you can preview the changes before saving the form by clicking on Preview Template:
When you are ready, save the changes to use this template in your emails.
This way you can add an unlimited number of invoice templates. Here is just one of PDF invoice examples:
Thus, buyers will have the ability to download and print PDF invoices from their account:
What’re the benefits? This module provides you with an option to create unique invoices (and not only) without any coding knowledge.
Add limitless number of invoice templates!
That’s all for today!
Feel free to ask your questions in the comment section below, we will be glad to help you out.