2

I have a problem with the PDF invoice and i'm trying to override the AbstractPdf.php file, I have done the following:

1)Created the following directories and files:

a. 'app\code\Ochos\fixPDF\registration.php':

    <?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Ochos_fixPDF',
__DIR__
);

b. 'app\code\Ochos\fixPDF\etc\di.xml':

<?xml version="1.0" ?>
<config>
   <preference for="vendor\magento\module-sales\Model\Order\Pdf\AbstractPdf"        type="Ochos\fixPDF\Model\Order\Pdf\AbstractPdf" />
</config>

c. 'app\code\Ochos\fixPDF\etc\module.xml':

<?xml version="1.0"?>
<config>
    <module name="Ochos_fixPDF" setup_version="2.0.0"/>
</config>

d. 'app\code\Ochos\fixPDF\Model\Order\Pdf\Abstract.php': the file that I have made changes in.

2)enabled the extension in config.php

3) Executed the following:

php -f bin/magento module:enable --clear-static-content Ochos_fixPDF
php -f bin/magento setup:upgrade

it seems that the extension is enabled, but no changes are made in the invoice PDF.

What am I doing wrong? Thanks!

DavidG
  • 113,891
  • 12
  • 217
  • 223
hezided
  • 65
  • 1
  • 9

1 Answers1

0

The problem is the function you want override is a protected function. I have other post and explain how we can change the function.

You have to preference to invoice.php and create the function into this file.

See this post: https://magento.stackexchange.com/questions/153308/override-abstractpdf-class-in-magento2

Community
  • 1
  • 1