0

We need to override following files in custom module.

/data/magento2/vendor/magento/module-sales/Model/Order/Pdf/AbstractPdf.php
/data/magento2/vendor/magento/module-sales/Model/Order/Pdf/Invoice.php
/data/magento2/vendor/magento/module-sales/Model/Order/Pdf/Items/AbstractItems.php
/data/magento2/vendor/magento/module-sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php

We've tried many different ways but that didn't work. So Please help me the proper ways to override vendor files in App/Code. Magento 2.2

0

Please Try Below Method in Your Module di.xml File

<?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="vendor/magento/module-sales/Model/Order/Pdf/AbstractPdf" type="Your_ExtensionName/Your_ModuleName/Model/Order/Pdf/AbstractPdf" />
<preference for="vendor/magento/module-sales/Model/Order/Pdf/Invoice" type="Your_ExtensionName/Your_ModuleName/Model/Order/Pdf/Invoice" />
<preference for="vendor/magento/module-sales/Model/Order/Pdf/Items/AbstractItems" type="Your_ExtensionName/Your_MOduleName/Model/Order/Pdf/Items/AbstractItems" />
<preference for="vendor/magento/module-sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice" type="Your_ExtensionName/Your_MOduleName/Model/Order/Pdf/Items/Invoice/DefaultInvoice" />
</config>
0

Please Try Following methods in 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\Model\Order\Pdf\Invoice" type="ExtensionName\Modulename\Model\Order\Pdf\Invoice"/>
    <preference for="Magento\Sales\Model\Order\Pdf\AbstractPdf" type="ExtensionName\Modulename\Model\Order\Pdf\AbstractPdf"/>
</config>

Hope it will work for you.

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.