0

I'm trying to change the store_email variable which can be used in all email templates to general/store_information/email (a new system field I created).

This variable loads trans_email/ident_support/email system config value by default from the function addEmailVariables in Magento\Email\Model\AbstractTemplate.

I tried creating an after plugin for this function like this:

<?php

namespace Cmcs\Email\Plugin;

use Magento\Store\Model\ScopeInterface;

class AbstractTemplate
{
    /**
     * Change store email variable
     */
    public function afterAddEmailVariables(
        \Magento\Email\Model\AbstractTemplate $subject,
        $result,
        $variables,
        $storeId
    )
    {
        $store = $subject->getStore($storeId);
        $result['store_email'] = $subject->getValue(
            'general/store_information/email',
            ScopeInterface::SCOPE_STORE,
            $store
        );
        return $result;
    }

}

and this is in my di.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="\Magento\Email\Model\AbstractTemplate">
        <plugin name="Cmcs_Email::addEmailVariables" type="Cmcs\Email\Plugin\AbstractTemplate" sortOrder="1" />
    </type>
</config>

But the store_email variable doesn't get changed...

Any ideas what I'm missing?

1 Answer 1

1

Using variables in the template like this not work?

{{config path="trans_email/ident_general/name"}}

For example

{{config path="general/store_information/email"}}
5
  • I already tried {{config path="general/store_information/email"}} but doesn't work on it's own. While trans_email/ident_general/name should work, since it's default M2, but doesn't help in this situation.
    – Lez
    Feb 19, 2020 at 23:11
  • 1
    What if you edit this in vendor as an experiment github.com/magento/magento2/blob/… as in check this github.com/magento/magento2/pull/24425 Feb 20, 2020 at 13:47
  • Adding general/store_information/email to di.xml in Magento_Variable module allows me to add {{config path="general/store_information/email"}} to any email template. Do you know of a way to put config values inside of translatable texts, e.g. {{trans 'Email us at: CUSTOM_VARIABLE'}}? Similar to how Magento does it with {{trans 'If you have questions about your order, you can email us at <a href="mailto:%store_email">%store_email</a>' store_email=$store_email|raw}}
    – Lez
    Feb 20, 2020 at 17:02
  • I think this is what you need docs.magento.com/m2/ce/user_guide/marketing/… Feb 20, 2020 at 20:25
  • Yep I know about that already, but I wanted to make a module so that I could use Magento's default behaviour to get the desired result and use it when necessary on new shops.
    – Lez
    Feb 21, 2020 at 7:31

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.