Question

I am working on payment gateway. but i have problem i did google research but couldn't find any solution i hope i'll get solution here so i am posting here

following my system.xml code block

<title translate="label">
    <label>Title</label>
    <comment><![CDATA[<img src="/media/billmate/images/billmate_bank_s.png" />]]></comment>
    <frontend_type>text</frontend_type>
    <sort_order>3</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</title>

in this block problem is in comment tag right now here i put static link /media/billmate/images/billmate_bank_s.png please anybody suggess me how to make it dynamic

Was it helpful?

Solution

An element from system.xml can have a dynamic comment. The comment can be rendered through a model.
You need to declare the comment field like this:

<comment>
    <model>module/adminhtml_comment</model>
</comment>

Now you need to create the model with alias module/adminhtml_comment:

<?php
class Namespace_Module_Model_Adminhtml_Comment{
    public function getCommentText(){ //this method must exits. It returns the text for the comment
        return "Some text here";
    }
}

like following

<title translate="label">
    <label>Title</label>
    <comment>
        <model>module/adminhtml_comment</model>
    </comment>
    <frontend_type>text</frontend_type>
    <sort_order>3</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</title>

return value from the getCommentText method

OTHER TIPS

Add into system.xml file

<field id="row_payment_us_free" translate="label" type="select" sortOrder="5" showInDefault="1" showInStore="1" showInWebsite="1" canRestore="1">
    <label>Payment US Free</label>
    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
    <comment><model>VendoreName\ModuleName\Model\SystemConfigComment</model></comment>
</field>

app/code/VendoreName/ModuleName/Model

SystemConfigComment.php

<?php

namespace VendoreName\ModuleName\Model;

use Magento\Framework\UrlInterface;

class SystemConfigComment implements \Magento\Config\Model\Config\CommentInterface
{
    protected $urlInterface;

    public function __construct(
        UrlInterface $urlInterface
    ) {
        $this->urlInterface = $urlInterface;
    }

    public function getCommentText($elementValue)
    {
        $url = $this->urlInterface->getUrl('adminhtml/system_config/edit/section/payment');

        return 'Require to enable <a href="' .$url . '#row_payment_us_free" target="_blank">Zero Subtotal Checkout</a>payment method for Zero Subtotal order.';
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top