AnswerBun.com

Magento 2 - Remove debug path hint from email template

Magento Asked by Hardik on December 9, 2020

I am sending order email from my custom module. Issue is in order email it showing debug path hint. Here is the code that i am using.

public function sendEmail($orderdata, $order)
{

   /*Send email*/
    $this->inlineTranslation->suspend();
    $storeScope = MagentoStoreModelScopeInterface::SCOPE_STORE;
    $sender = [
        //'name' => $this->_escaper->escapeHtml($customer->getFirstName()),
        //'email' => $this->_escaper->escapeHtml($customer->getEmail()),
        'name' => 'My store',
        'email' => $this->scopeConfig->getValue('trans_email/ident_general/email', $storeScope)
    ];
    $postObject = new MagentoFrameworkDataObject();
    $postObject->setData($orderdata);

    $transport = $this->_transportBuilder
            ->setTemplateIdentifier('7') // Send the ID of Email template which is created in Admin panel
            ->setTemplateOptions(
                    [
                        'area' => MagentoFrameworkAppArea::AREA_FRONTEND,
                        'store' => $this->storeManager->getStore()->getId()
                    ]
            )
            ->setTemplateVars(['order' => $order, 'manufacturerdata' => $orderdata,  'billingaddress' => $orderdata['billingaddress'], 'shippingaddress' => $orderdata['shippingaddress']])
            ->setFrom($sender)
            ->addTo($orderdata['brandEmail'])
            ->getTransport();
    $transport->sendMessage();

    $this->inlineTranslation->resume();
    /**********End Send email*/
}

manufacturer_email_order_items.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Order Items List" design_abstraction="custom">
    <update handle="manufactures_email_order_renderers"/>
    <!--<update handle="sales_email_item_price"/>-->
    <body>
        <block class="MagentoSalesBlockOrderEmailItems" name="items" template="HK_OrderEmail::email/manufacturer_items.phtml" cacheable="false">
            <block class="MagentoFrameworkViewElementRendererList" name="manufacturer.email.order.renderers" as="renderer.list"/>
            <!--<block class="MagentoSalesBlockOrderTotals" name="order_totals" template="Magento_Sales::order/totals.phtml">
                <arguments>
                    <argument name="label_properties" xsi:type="string">colspan="2"</argument>
                </arguments>
                <block class="MagentoTaxBlockSalesOrderTax" name="tax" template="Magento_Tax::order/tax.phtml">
                    <action method="setIsPlaneMode">
                        <argument name="value" xsi:type="string">1</argument>
                    </action>
                </block>
            </block>-->
        </block>
        <block class="MagentoFrameworkViewElementTemplate" name="additional.product.info" template="Magento_Theme::template.phtml"/>
    </body>
</page>

manufactures_email_order_renderers.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
    <body>
        <referenceBlock name="manufacturer.email.order.renderers">
            <block class="MagentoSalesBlockOrderEmailItemsOrderDefaultOrder" as="default" template="HK_OrderEmail::email/items/order/default.phtml"/>
        </referenceBlock>
    </body>
</page>

Order email template.

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

<table>
    <tr class="email-information">
        <td>
            <table class="order-details">
                <tr>
                    <td class="address-details">
                        <h3>{{trans "Billing Info"}}</h3>
                        <p>{{var billingaddress|raw}}</p>
                    </td>
                    {{depend order.getIsNotVirtual()}}
                    <td class="address-details">
                        <h3>{{trans "Shipping Info"}}</h3>
                        <p>{{var shippingaddress|raw}}</p>
                    </td>
                    {{/depend}}
                </tr>
            </table>
            {{layout handle="manufacturer_email_order_items" order=$order manufacturerdata=$manufacturerdata area="frontend"}}
        </td>
    </tr>
</table>

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

Here is the email that i am getting with path hint. Path hint is already disabled. I have double checked in DB and also removed cache as well.
enter image description here

3 Answers

I had similar issue when sending email through command in Maganeto 2. To solve this in your custom module di.xml file add this

  • app/code/NameSpace/Module/etc/di.xml

    <type name="MagentoDeveloperModelTemplateEnginePluginDebugHints">
        <arguments>
            <argument name="debugHintsPath" xsi:type="string">dev/debug/template_hints_storefront</argument>
        </arguments>
    </type>
    

Tested in magento 2.2.5.

Answered by kamlesh.bar on December 9, 2020

i had the same problem, but in a command. So Alex' solution does not work this way for me, but i could solve this the following way. I hope i could help someone with the code.

I was searching the half day for a solution and i posted the answer also in another thread. but the threads were in significally different search terms in google, so i hope someone will find at least one of the solutions described.

public function __construct(MagentoStoreModelStoreManagerInterface $storeManager,
                            MagentoFrameworkObjectManagerInterface $objectManager,
                            MagentoFrameworkObjectManagerConfigLoaderInterface $configLoader,
                            MagentoFrameworkAppAreaList $areaList) {

        $this->storeManager = $storeManager;
        $this->objectManager = $objectManager;
        $this->configLoader = $configLoader;
        $this->areaList = $areaList;

}

...

public function init() {
        ...

        $this->objectManager->configure($this->configLoader->load('frontend'));

        $localeInterface = $this->objectManager->create('MagentoFrameworkTranslateInterface');
        $localeInterface->setLocale('de_DE');
        $localeInterface->loadData(); 

        $areaObject = $this->areaList->getArea(MagentoFrameworkAppArea::AREA_ADMINHTML);
        $areaObject->load(MagentoFrameworkAppArea::PART_TRANSLATE);

        ...
}

My problem was that i had the email debug path inside the mails. This is caused by magento itself, because magento won´t set any store view or load languages or translations in a cron / command. So you need to set it by yourself.

We have 1 location of sending an email - when creating a shipment - and here it works like a charm. The email looks - like it should - the same like if i would create a shipment in the backend manually.

It is a shame for magento that there is no "preloading" of translations, store views or helper functions for commands, like setting the language / store view.

Answered by Chris Schrut on December 9, 2020

I found the problem. When you try to send email by cron, it take by default configs from adminhtml. By default in adminhtml debug email path is always enabled. I use the next functionality for set front area and prevent the problem.

<?php

     namespace Your_NamespaceCron;


     use MagentoFrameworkAppConfigScopeConfigInterface;
     use MagentoFrameworkAppArea;
     use MagentoFrameworkAppState as AppState;
     use MagentoFrameworkObjectManagerInterface;
     use MagentoFrameworkObjectManagerConfigLoaderInterface;

     /**
      * Class SendMail
      * @packageYour_NamespaceCron
      */
     class SendMail
     {
          public function execute($options, OutputInterface $output)
          {
             try  {
                $this->objectManager->configure($this->configLoader->load(Area::AREA_FRONTEND));
                $this->appState->emulateAreaCode(
                   Area::AREA_FRONTEND,
                   [$this, "executeCallBack"],
                   [$options, $output]
                 );
             } catch (Exception $e) {
                $output->writeln($e->getMessage());
             }
          }

          public function executeCallBack($options, OutputInterface $output)
          {
              // your main functionality
          }
     }

Answered by Alexander Talda on December 9, 2020

Add your own answers!

Related Questions

Get matrixrate config programatically

0  Asked on December 14, 2020 by pevik

     

Error 404 : The requested page do not exist

1  Asked on December 14, 2020 by claims

   

Magento 2 Checkout shipping afterRender

0  Asked on December 13, 2020 by mac_mod

         

How to make checkout page 2columns-left on magento 2

1  Asked on December 13, 2020 by alin-lupoiu

       

magento2 plugin and str_replace

2  Asked on December 11, 2020 by boll

 

Custom email layout handle for custom module

2  Asked on December 11, 2020 by karan-adhikari

     

Magento 2 – Remove debug path hint from email template

3  Asked on December 9, 2020 by hardik

   

Watermark magento 2

2  Asked on December 9, 2020 by pascal-van-kooten

 

How to place sizes in order

1  Asked on December 7, 2020 by stefaniiia

 

Magento 2.4 disable UI/Theme part

0  Asked on December 7, 2020 by bogdan-hepting

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP