Skip to main content

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

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

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 for="Magento\Sales\Model\Order\Pdf\Invoice"
                type="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

added 165 characters in body
Source Link
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

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
}

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

Source Link
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
}