1

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 = \Magento\Store\Model\ScopeInterface::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 \Magento\Framework\DataObject();
    $postObject->setData($orderdata);

    $transport = $this->_transportBuilder
            ->setTemplateIdentifier('7') // Send the ID of Email template which is created in Admin panel
            ->setTemplateOptions(
                    [
                        'area' => \Magento\Framework\App\Area::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="Magento\Sales\Block\Order\Email\Items" name="items" template="HK_OrderEmail::email/manufacturer_items.phtml" cacheable="false">
            <block class="Magento\Framework\View\Element\RendererList" name="manufacturer.email.order.renderers" as="renderer.list"/>
            <!--<block class="Magento\Sales\Block\Order\Totals" name="order_totals" template="Magento_Sales::order/totals.phtml">
                <arguments>
                    <argument name="label_properties" xsi:type="string">colspan="2"</argument>
                </arguments>
                <block class="Magento\Tax\Block\Sales\Order\Tax" 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="Magento\Framework\View\Element\Template" 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="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" 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

  • Please check store views if you enabled the template path hint for particular store view? – Sukumar Gorai Jun 19 '18 at 7:17
  • There is only one store... – Hardik Jun 19 '18 at 7:18
  • Flush the cache and try again. – Sukumar Gorai Jun 19 '18 at 7:19
  • Already clean everything. – Hardik Jun 19 '18 at 7:20
0

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_Namespace\Cron;


     use Magento\Framework\App\Config\ScopeConfigInterface;
     use Magento\Framework\App\Area;
     use Magento\Framework\App\State as AppState;
     use Magento\Framework\ObjectManagerInterface;
     use Magento\Framework\ObjectManager\ConfigLoaderInterface;

     /**
      * Class SendMail
      * @packageYour_Namespace\Cron
      */
     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
          }
     }
0

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(\Magento\Store\Model\StoreManagerInterface $storeManager,
                            \Magento\Framework\ObjectManagerInterface $objectManager,
                            \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader,
                            \Magento\Framework\App\AreaList $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('Magento\Framework\TranslateInterface');
        $localeInterface->setLocale('de_DE');
        $localeInterface->loadData(); 

        $areaObject = $this->areaList->getArea(\Magento\Framework\App\Area::AREA_ADMINHTML);
        $areaObject->load(\Magento\Framework\App\Area::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.

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.