Skip to main content
2 of 4
edited title
Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156

Override method that Print Pdf Invoice in Magento 2

In Magento 2.1 I want to do a custom action when the admin click on button "Print" in Invoice page. In particular I want to show a pdf saved in a specific folder.

I thought that I have to override the controller PrintAction but it doesn't work.

di.xml:

<?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\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction"
                type="VendorName\ModuleName\Controller\Sales\Adminhtml\Invoice\AbstractInvoice\PrintAction"/>
</config>

controller override:

<?php
namespace VendorName\ModuleName\Controller\Sales\Adminhtml\Invoice\AbstractInvoice;

abstract class PrintAction extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction
{
    public function execute($coreRoute = null)
    {
        // My action
    }
}

But when I click on Print button, it does the core action and not my action. Is right? Or what method do I have to override?

Vixent
  • 349
  • 1
  • 4
  • 16