Skip to main content
2 of 3
added 165 characters in body
Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156

Seem that you tried to follow the Magento 1 way. In Magento 2, there are no local, community code pool.

We need to use Dependency injection to override the class.

app/code/Vendor/Module/etc/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 type="Magento\Sales\Model\Order\Pdf\Invoice"
                for="Vendor\Module\Model\Order\Pdf\Invoice"/>
</config>

app/code/Vendor/Module/Model/Order/Pdf/Invoice.php

<?php

namespace Vendor\Module\Model\Order\Pdf;

class Invoice extends \Magento\Sales\Model\Order\Pdf\Invoice
{
  //Your custom code lines
}

Recommended way: We can use Plugin to modify the behaviour of methods in Magento 2: http://devdocs.magento.com/guides/v2.1/extension-dev-guide/plugins.html

Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156