Question

Able to get values of store phone number but not able to get custom config values(even it is working fine in root file when get custom config value) How to get value for this - {{config path="custom_finance/general/finance_text"}} ?

custom.html

<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<!--@subject {{trans "Your %store_name order confirmation" store_name=$store.frontend_name}} @-->
<!--@vars {

"var order_data.customer_name":"Customer Name"
} @-->

{{template config_path="design/email/header_template"}}

<table>
<tr class="email-intro">
        <td>
            <p class="greeting">{{trans "%customer_name," customer_name=$order_data.customer_name}}</p>
            <p>Finance1</p>
            <p><strong>{{trans "Store Contact Number"}}</strong></p> 
            <p>{{config path="general/store_information/phone"}}</p> //it is working fine
            <p><strong>{{trans "Store Fianance Number"}}</strong></p>
            <p>{{config path="custom_finance/general/finance_text"}}</p> //not working

</td></tr>
</table>

{{template config_path="design/email/footer_template"}}

system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="Xyz" translate="label" sortOrder="10">
            <label>XYZ</label>
        </tab>
        <section id="custom_finance" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <class>separator-top</class>
            <label>Finance</label>
            <tab>Xyz</tab>
            <resource>Xyz_Custom::xyz_config</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>General Configuration</label>
                <field id="finance_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Display Text</label>
                    <comment>This text will show on email finance</comment>
                </field>
            </group>
        </section>
    </system>
</config>
Was it helpful?

Solution

To be able to add system config variables to email templates it is not enough that they are defined in system.xml and added to core_config_data.

You must also make them appear in the list of variables that appear when you click

Insert Variable…

In the email templates:

enter image description here

To do this you have to define a config path in your di.xml like this:

<?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\Variable\Model\Source\Variables">
        <arguments>
            <argument name="configPaths" xsi:type="array">
                <item name="custom_finance/general" xsi:type="array">
                    <item name="custom_finance/general/finance_text" xsi:type="string">1</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

It will then appear in the variable list and you can use it in your email templates:

enter image description here

enter image description here

Good luck!

OTHER TIPS

Please check core_config_data table has store value or not

SELECT * FROM `core_config_data` WHERE `path` LIKE "custom_finance%";

I Hope This Helps You.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top