1

I am trying to override this file :-

Vendor/Module/Block/Order/Email/Items

i call this file in my di.xml Here is xml 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\Block\Order\Email\Items\DefaultItems" type="Vendor\Module\Block\Order\Email\Items\DefaultItems" />
   </config>

On following path i have create DefaultItems.php

Vendor/Module/Block/Order/Email/Items

Here is code of DefaultItems.php

<?php

namespace Vendor\Module\Block\Order\Email\Items;

use \Magento\Sales\Model\Order\Creditmemo\Item as CreditmemoItem;
use \Magento\Sales\Model\Order\Invoice\Item as InvoiceItem;
use \Magento\Sales\Model\Order\Item as OrderItem;

/**
 * Sales Order Email items default renderer
 *
 * @author     Magento Core Team <[email protected]>
 */
class DefaultItems extends \Magento\Sales\Block\Order\Email\Items\DefaultItems
{
    public function getAdditionalOptionData()
    {

        return "hello";
    }

}

In this file

app/design/frontend/Vendor/Theme/Magento_Sales/templates/email/items/invoice/default.phtml

I have write following code

echo $block->getAdditionalOptionData(); die;

Now, when i send invoice email from admin, my code is not working. It should display hello.

When i put di.xml file code in comment and add function getAdditionalOptionData in magento vendor file, hello display.

I am using magento 2.1.6

Can anyone please let me know where i make mistake?

7
  • 1
    Firstly check whether your module is enabled or not and remove generated and flush cache Commented Apr 3, 2019 at 11:59
  • Remove from slash (\) at use \Magento\Sales\Model\Order\Creditmemo\Item as CreditmemoItem; use \Magento\Sales\Model\Order\Invoice\Item as InvoiceItem; use \Magento\Sales\Model\Order\Item as OrderItem;
    – Amit Bera
    Commented Apr 3, 2019 at 13:13
  • why you need to override the class
    – Amit Bera
    Commented Apr 3, 2019 at 13:16
  • @PrathapGunasekaran I already did that. But not working.
    – user55548
    Commented Apr 3, 2019 at 13:23
  • @AmitBera I want to add additional information in invoice email. When invoice mail sent first time, additional data comes properly. But when i send mail again, at that time additional data not comes. That's why i want to override.
    – user55548
    Commented Apr 3, 2019 at 13:25

1 Answer 1

1

After R&D I found solution. I hope this will help to someone.

I have add default.phtml file into my module instead of theme So now, new path is

app/code/Vendor/Module/view/frontend/templates/email/items/invoice/default.phtml

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.