1

I have a custom template that is sent when my order is updated. The order status is sent in the default language (Portuguese) and not in the order language, can you help me figure this out ?

PS: Every other phrase in the email is correctly translated to the order language... This also happens in the default email template...

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

<table>
    <tr class="email-intro">
        <td>
            <p class="greeting">{{trans "%name," name=$order_data.customer_name}}</p>
            <p>
                {{trans
                    "Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."

                    increment_id=$order.increment_id
                    order_status=$order_data.frontend_status_label
                |raw}}
            </p>
            <p>{{trans 'You can check the status of your order by <a href="%account_url">logging into your account</a>.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}</p>
            <p>
                {{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}}{{depend store_phone}} {{trans 'or call us at <a href="tel:%store_phone">%store_phone</a>' store_phone=$store_phone |raw}}{{/depend}}.
                {{depend store_hours}}
                    {{trans 'Our hours are <span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
                {{/depend}}
            </p>
        </td>
    </tr>
    <tr class="email-information">
        <td>
            {{depend comment}}
            <table class="message-info">
                <tr>
                    <td>
                        {{var comment|escape|nl2br}}
                    </td>
                </tr>
            </table>
            {{/depend}}
        </td>
    </tr>
</table>

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

1 Answer 1

0

Ok, so this is just dumb but it works. For some reason the $order->getFrontendStatusLabel() is always returning the value in my default language rather then the language of the store in which the order was made.

<preference for="Magento\Sales\Model\Order\Email\Sender\OrderCommentSender" type="{Vendor}\{ModuleName}\Preferences\Emails\OrderCommentSender"/>

In the preference definition:

<?php
namespace Vendor\Module\Preferences\Emails;

use Magento\Sales\Model\Order;
use Magento\Framework\DataObject;

/**
 * Class OrderCommentSender
 */
class OrderCommentSender extends \Magento\Sales\Model\Order\Email\Sender\OrderCommentSender
{
    /**
     * Send email to customer
     *
     * @param Order $order
     * @param bool $notify
     * @param string $comment
     * @return bool
     */
    public function send(Order $order, $notify = true, $comment = '')
    {
        $this->identityContainer->setStore($order->getStore());
        $frontendStatusLabel = $order->getFrontendStatusLabel();

        $texttoTranslate = '%1';
        $texttoTranslate = str_replace ('%1', $frontendStatusLabel, $texttoTranslate);
        $transport = [
            'order' => $order,
            'comment' => $comment,
            'billing' => $order->getBillingAddress(),
            'store' => $order->getStore(),
            'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
            'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
            'order_data' => [
                'customer_name' => $order->getCustomerName(),
                'frontend_status_label' => __( $texttoTranslate)
            ]
        ];
        $transportObject = new DataObject($transport);

        /**
         * Event argument `transport` is @deprecated. Use `transportObject` instead.
         */
        $this->eventManager->dispatch(
            'email_order_comment_set_template_vars_before',
            ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject]
        );

        $this->templateContainer->setTemplateVars($transportObject->getData());

        return $this->checkAndSend($order, $notify);
    }
}

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.