Cannot Update Order Status in Magento 2.4.7? We’ve got an answer for that.

Magento 2.4.7, the latest version of widely used eCommerce platform magento, has introduced a frustrating issue for many store administrators: the inability to update the order status by saving an order comment within the admin dashboard.

This problem, highlighted by users on GitHub, has disrupted the workflow for numerous Magento store owners and developers. In this article, we will delve into the details of this issue, explore the proposed solution, and introduce our own addon that effectively resolves this problem.

Cannot Update Order Status in Magento 2.4.7 – Understanding the Issue

The main problem reported in Magento 2.4.7 is that the order status cannot be changed when adding an order comment in the admin panel. Typically, administrators use this feature to update customers about their order status changes, such as processing, completed, or shipped. However, with the update to Magento 2.4.7, this functionality seems broken.

Cannot Update Order Status in Magento 2.4.7


The Community’s Response

The Magento community, known for its proactive approach to solving such issues, quickly started investigating the problem. One notable contribution came from GitHub user superdav42 https://github.com/magento/magento2/issues/38659#issuecomment-2181443426, who provided a detailed fix suggestion. The fix involved a modification to the Magento codebase to revert the logic introduced in magento 2.4.7 so that the order status gets updated correctly when an order comment is saved.


To provide a comprehensive, deployable solution for this issue, we have developed a small addon based on the community-provided fix. Our addon ensures that the order status gets updated when saving an order comment in the Magento admin dashboard. This addon is simple to install and integrates seamlessly with your Magento setup. The code is outlined below, a zip file containing the full addon is also available at the end of this article.

Registration.php:

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Dtfdigital_Fixordercomments',
__DIR__
);

etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Dtfdigital_Fixordercomments" setup_version="1.0.0">
</module>
</config>

etc/di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Controller\Adminhtml\Order\AddComment" type="Dtfdigital\Fixordercomments\Controller\Adminhtml\Order\AddComment" />
</config>

Controller/Adminhtml/Order/AddComment.php:

<?php

namespace Dtfdigital\Fixordercomments\Controller\Adminhtml\Order;

use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender;

/**
 * Class AddComment
 *
 * Controller responsible for addition of the order comment to the order
 */
class AddComment extends \Magento\Sales\Controller\Adminhtml\Order implements HttpPostActionInterface
{
    /**
     * Authorization level of a basic admin session
     *
     * @see _isAllowed()
     */
    public const ADMIN_RESOURCE = 'Magento_Sales::comment';

    /**
     * ACL resource needed to send comment email notification
     */
    public const ADMIN_SALES_EMAIL_RESOURCE = 'Magento_Sales::emails';

    /**
     * Add order comment action
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $order = $this->_initOrder();
        if ($order) {
            try {
                $data = $this->getRequest()->getPost('history');
                if (empty($data['comment']) && $data['status'] == $order->getDataByKey('status')) {
                    $error = 'Please provide a comment text or ' .
                             'update the order status to be able to submit a comment for this order.';
                    throw new \Magento\Framework\Exception\LocalizedException(__($error));
                }

                $order->setStatus($data['status']);
                $notify = $data['is_customer_notified'] ?? false;
                $visible = $data['is_visible_on_front'] ?? false;

                if ($notify && !$this->_authorization->isAllowed(self::ADMIN_SALES_EMAIL_RESOURCE)) {
                    $notify = false;
                }

                $comment = trim(strip_tags($data['comment']));
                $history = $order->addStatusHistoryComment($comment, $data['status']);
                $history->setIsVisibleOnFront($visible);
                $history->setIsCustomerNotified($notify);
                $history->save();

                $order->save();
                /** @var OrderCommentSender $orderCommentSender */
                $orderCommentSender = $this->_objectManager
                    ->create(\Magento\Sales\Model\Order\Email\Sender\OrderCommentSender::class);

                $orderCommentSender->send($order, $notify, $comment);

                return $this->resultPageFactory->create();
            } catch (\Magento\Framework\Exception\LocalizedException $e) {
                $response = ['error' => true, 'message' => $e->getMessage()];
            } catch (\Exception $e) {
                $response = ['error' => true, 'message' => __('We cannot add order history.')];
            }
            if (is_array($response)) {
                $resultJson = $this->resultJsonFactory->create();
                $resultJson->setData($response);
                return $resultJson;
            }
        }
        return $this->resultRedirectFactory->create()->setPath('sales/*/');
    }
}

How to Install The Addon

To resolve the “cannot update order status in Magento 2.4.7” issue, follow these steps:

Download the Addon: At the end of this article, you will find a link to download the addon zip file.
Upload the Addon: Unzip the file and upload the contents to your Magento installation directory.
Enable the Addon: Run the following commands in your Magento root directory:

bin/magento module:enable Dtfdigital_Fixordercomments
bin/magento setup:upgrade
bin/magento cache:clean

The “cannot update order status in Magento 2.4.7” issue has caused significant inconvenience for Magento administrators. However, with the collective effort of the community this problem can be effectively resolved while we await an official fix release, ensuring that the order status is updated correctly when an order comment is saved.

We encourage all Magento 2.4.7 users facing this issue to download and install our addon to restore the seamless functionality of order status updates. If you have any questions or need further assistance, please feel free to reach out to us.

Company News
DTF Digital

Our Team Grows

The DTF team has grown! We’d like to take this opportunity to welcome Oscar who joins the team as Junior eCommerce Developer, on placement from the University of Huddersfield.
Read More »
DTF Digital