magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Incorrect order status label in sales update emails sent from the admin for non-default store views #29263

Closed aadmathijssen closed 3 years ago

aadmathijssen commented 4 years ago

After sending a sales update email from the admin for an order using a non-default store view, the resulting email contains the order status label for the default store view instead of the order status label for the store view in which the order is placed.

Preconditions (*)

  1. A Magento 2.4-develop installation with sample data.

Steps to reproduce (*)

  1. In the admin:

    • Go to “Stores > All Stores”, click on “Create Store View”, fill in the required values, set the status to “Enabled” and click on the "Save Store View” button.
    • Go to “Stores > Order Status”, click on the “Pending” status, enter the following data under “Store View Specific Labels”, and click on the “Save Status” button.
      • Default Store View: “Pending (default)”
      • New Store View: “Pending (secondary)” Screenshot from 2020-07-29 12-26-46
  2. In the frontend:

    • Select the new store view in the store view switcher.
    • Add a product to the cart.
    • Complete the checkout using the “Check / Money order” payment method.
  3. In the admin:

    • Go to “Sales > Orders”, and click on the newly created order.
    • On this order view page, enter a comment, click on the “Notify Customer by Email” checkbox and click on the "Submit Comment” button.

Expected result (*)

  1. An order update email is sent containing “Pending (secondary)” as the order status.

Actual result (*)

  1. An order update email is sent containing “Pending (default)” as the order status.

Screenshot of the resulting email:

sales_order_update_email_with_incorrect_order_status_label


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 4 years ago

Hi @aadmathijssen. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

aadmathijssen commented 4 years ago

@magento give me 2.4-develop instance

magento-engcom-team commented 4 years ago

Hi @aadmathijssen. Thank you for your request. I'm working on Magento 2.4-develop instance for you

magento-engcom-team commented 4 years ago

Hi @aadmathijssen, here is your Magento instance. Admin access: https://i-29263-2-4-develop.instances.magento-community.engineering/admin_77c7 Login: 1856ed77 Password: c43a74371a5a Instance will be terminated in up to 3 hours.

m2-assistant[bot] commented 4 years ago

Hi @engcom-Alfa. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

magento-engcom-team commented 4 years ago

:white_check_mark: Confirmed by @engcom-Alfa Thank you for verifying the issue. Based on the provided information internal tickets MC-36262 were created

Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

salelsol commented 4 years ago
WilliejanB commented 3 years ago

Is there a temporary fix available for this issue? I need it urgently. If so, where can I find this? I'm not a programmer, so please keep it simple...... Thanks a lot!

Axel29 commented 3 years ago

Up, is there a fix for that?

Axel29 commented 3 years ago

I have tested a fix that I can suggest that would impact only one class but I'm not sure that it wouldn't have side effects on other parts of the website.

The idea would be to emulate the order's store using \Magento\Store\Model\App\Emulation::startEnvironmentEmulation and \Magento\Store\Model\App\Emulation::stopEnvironmentEmulation inside \Magento\Sales\Model\Order::getFrontendStatusLabel like that:

    /**
     * Retrieve frontend label of order status
     *
     * @return string
     * @since 102.0.1
     */
    public function getFrontendStatusLabel()
    {
        $this->appEmulation->startEnvironmentEmulation($this->getStoreId(), Area::AREA_FRONTEND);

        $frontendLabel = $this->getConfig()->getStatusFrontendLabel($this->getStatus());

        $this->appEmulation->stopEnvironmentEmulation();

        return $frontendLabel;
    }

It seems to work locally but I haven't tested anything else than adding a comment to the order in the admin.

Axel29 commented 3 years ago

Here is a quickfix until the patch is made in the official release that you can apply in a custom module (think about replacing the "Vendor\Module" parts):

  1. File etc/adminhtml/di.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Model\Order">
        <plugin sortOrder="1" name="bmSalesOrder" type="Vendor\Module\Plugin\Model\OrderPlugin" />
    </type>
</config>
  1. File Plugin/Model/OrderPlugin.php
<?php
namespace Vendor\Module\Plugin\Model;

use Magento\Framework\App\Area;
use Magento\Sales\Model\Order;
use Magento\Store\Model\App\Emulation as AppEmulation;

class OrderPlugin
{
    /**
     * @var \Magento\Store\Model\App\Emulation
     */
    private $appEmulation;

    /**
     * OrderPlugin constructor.
     *
     * @param \Magento\Store\Model\App\Emulation $appEmulation
     */
    public function __construct(AppEmulation $appEmulation)
    {
        $this->appEmulation = $appEmulation;
    }

    /**
     * Fix transactional emails retrieving order status without the translation.
     * See https://github.com/magento/magento2/issues/29263
     *
     * @param \Magento\Sales\Model\Order $subject
     * @param string                     $result
     *
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     *
     * @return string
     * @since 102.0.1
     */
    public function afterGetFrontendStatusLabel(Order $subject, $result)
    {
        $this->appEmulation->startEnvironmentEmulation($subject->getStoreId(), Area::AREA_FRONTEND);

        $frontendLabel = $subject->getConfig()->getStatusFrontendLabel($subject->getStatus());

        $this->appEmulation->stopEnvironmentEmulation();

        return $frontendLabel;
    }
}

i'll try to make a pull request as soon as possible but even if it is accepted, it wouldn't be available until at least one of these versions I guess 2.4.2, 2.4.1-p1, 2.3.6-p1, so this is a quickfix until then.

WilliejanB commented 3 years ago

Here is a quickfix until the patch is made in the official release that you can apply in a custom module (think about replacing the "Vendor\Module" parts):

i'll try to make a pull request as soon as possible but even if it is accepted, it wouldn't be available until at least one of these versions I guess 2.4.2, 2.4.1-p1, 2.3.6-p1, so this is a quickfix until then.

Thank you for your "quick-fix" @Axel29 I will ask our developer to add it, because I could not find the exact location (folder) where to put the replacements.

Axel29 commented 3 years ago

Here is a quickfix until the patch is made in the official release that you can apply in a custom module (think about replacing the "Vendor\Module" parts): i'll try to make a pull request as soon as possible but even if it is accepted, it wouldn't be available until at least one of these versions I guess 2.4.2, 2.4.1-p1, 2.3.6-p1, so this is a quickfix until then.

Thank you for your "quick-fix" @Axel29 I will ask our developer to add it, because I could not find the exact location (folder) where to put the replacements.

No problem, you can add it in app/code/[Vendor]/[Module]/ where [Vendor]/[Module] is one of your modules.

magento-engcom-team commented 3 years ago

Hi @aadmathijssen, @edenduong.

Thank you for your report and collaboration!

The related internal Jira ticket MC-36262 was closed as Fixed.

The fix will be available with the upcoming 2.4.3 release.

WilliejanB commented 2 years ago

Hi @magento-engcom-team @aadmathijssen @edenduong,

We currently use Magento ver. 2.4.3, which still has the problem. Please confirm if it is solved in Magento ver. 2.4.4 release?

Best regards, Williejan

sukeshini-kot commented 2 years ago

Where can I find the commit for this fix?