2

How to override below file in module ?

Magento2/vendor/magento/module-payment/view/frontend/templates/info/default.phtml
11
  • The file from which is called is vendor/magento/module-payment/Block/Info.php – devhs Mar 9 at 13:20
  • Any thoughts on this ? – devhs Mar 10 at 4:42
  • 1
    If you want to add style then it is not a proper way. You can add style from admin. You just need to load email template in admin. You need to write style there for particular template. – ZealousWeb Mar 10 at 7:11
  • 1
    Here you can add style - prnt.sc/10hspo5, you just need to select newly added template for order email from stores > configuration > sales > sales emails – ZealousWeb Mar 10 at 7:13
  • 1
    Does this answer your question? Magento 2: Override Magento_Payment::info/default.phtml – Diana Botean Mar 10 at 11:03
1

Try with below way.

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">
    <type name="Magento\Payment\Block\Info">
        <plugin name="module_paympent_view_override_template" type="Vendor\Module\Plugin\Payment\Block\Info" />
    </type>
</config>

Info.php

<?php
namespace Vendor\Module\Plugin\Payment\Block;
 
class Info
{
    public function beforeToHtml(\Magento\Payment\Block\Info $subject)
    {        
            $subject->setTemplate('Vendor_Module::info/default.phtml');        
    }
}

The above code is not tested. I have just shared the way to override.

7
  • Thanks for the answer, i will check this answer. – devhs Mar 9 at 13:35
  • This is not working. – devhs Mar 9 at 13:44
  • Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'Vendor_Sales::info/default.phtml' in module: 'Magento_OfflinePayments' block's name: 'info\checkmo_0' – devhs Mar 10 at 6:49
  • This error appeared – devhs Mar 10 at 6:49
  • 1
    Thanks for the answer – devhs Mar 22 at 4:56
0

No, it's so easy. You need to copy that file into your vendor theme in app/desing. So, the original path file is vendor/magento/module-payment/view/frontend/templates/info/default.phtml, you need to copy and paste it in app/design/MyVendor/MyTheme/Magento_Payment/templates/info/default.phtml.

After this flush magento cache.

0

1)Create di.xml file and add following code:

<?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="module_paympent_view_override_template" type="Vendor\Module\Payment\Block\Info" />
</config>

2)Create Block:

<?php
namespace Vendor\Module\Plugin\Payment\Block;
 
class Info
{
    public function beforeToHtml(\Magento\Payment\Block\Info $subject)
    {        
            $subject->setTemplate('Vendor_Module::info/default.phtml');        
    }
}

3)Create Template file default.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @var \Magento\Payment\Block\Info $block
 * @see \Magento\Payment\Block\Info
 */
$specificInfo = $block->getSpecificInformation();
$title = $block->escapeHtml($block->getMethod()->getTitle());
?>
<dl class="payment-method">
    <dt class="title"><?= /* @noEscape */ $title ?></dt>
<?php if ($specificInfo) : ?>
    <dd class="content">
        <table class="data table">
            <caption class="table-caption"><?= /* @noEscape */ $title ?></caption>
            <?php foreach ($specificInfo as $label => $value) : ?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml($label) ?></th>
                    <td>
                        <?= /* @noEscape */ nl2br($block->escapeHtml(implode("\n", $block->getValueAsArray($value, true)))) ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        </table>
    </dd>
<?php endif;?>
</dl>
<?= $block->getChildHtml() ?>
5
  • preference for="module_paympent_view_override_template" ? – devhs Mar 16 at 10:58
  • yes you have to add preference – technerd Mar 16 at 11:00
  • preference for // This should be class – devhs Mar 16 at 11:00
  • yes the core block class you are extending for this – technerd Mar 16 at 11:04
  • or you can also use plugin instead of preference – technerd Mar 16 at 11:05
0

try to preference block Magento\Payment\Block\Info.php

file 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\Payment\Block\Info"" type=""Vendor\Module\Block\Info"" />
</config>

on file Vendor\Module\Block\Info.php

<?php
namespace Vendor\Module\Block;

class Info extends \Magento\Payment\Block\Info
{
.....................
    protected $_template = 'Vendor_Module::info/default.phtml';
....................
}

Finally, create your template

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.