magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

[Issue] Cannot update Order status in 2.4.7

Open Nuranto opened this issue 1 year ago • 34 comments

Preconditions and environment

  • Magento version 2.4.7

Steps to reproduce

  1. Try to update status from admin order page view

Expected result

Status updated

Actual result

Status not updated

Additional information

I don't understand this change introduced in 2.4.7 : https://github.com/magento/magento2/issues/36562

private function getOrderStatus(string $orderStatus, string $historyStatus): string
    {
        return ($orderStatus === Order::STATE_PROCESSING || $orderStatus === Order::STATUS_FRAUD) ? $historyStatus
            : $orderStatus;
    }

Why would we be able to change status only if current status is processing or fraud ? (Also, Order::STATE_PROCESSING instead of Order::STATUS_PROCESSING )

If I understand correctly the issue #36562, the fix should be something like this instead :

private function getOrderStatus(OrderInterface $order, string $historyStatus): string
    {
        $statuses = $this->orderConfig->getStateStatuses($order->getState());
        
        if (!in_array($status, array_keys($statuses))) {
            return $order->getStatus();
        }
        return $historyStatus;
    }

Or am I missing something ?

Release note

No response

Triage and priority

  • [X] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Nuranto avatar Apr 25 '24 13:04 Nuranto

Hi @Nuranto. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :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, join the Community Contributions Triage session to discuss the appropriate ticket.

m2-assistant[bot] avatar Apr 25 '24 13:04 m2-assistant[bot]

Hi @engcom-Bravo. 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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Apr 25 '24 13:04 m2-assistant[bot]

Hi @engcom-Dash. 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:

    1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    1. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    1. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
      - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

m2-assistant[bot] avatar Apr 25 '24 13:04 m2-assistant[bot]

@magento give me 2.4-develop instance

engcom-Dash avatar Apr 25 '24 13:04 engcom-Dash

Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.

Hi @engcom-Dash, here is your Magento Instance: https://fe74e6b08484c0858eb929e57e74a885.instances-prod.magento-community.engineering Admin access: https://fe74e6b08484c0858eb929e57e74a885.instances-prod.magento-community.engineering/admin_f188 Login: 64dd48de Password: 68a200a92f49

@magento give me 2.4-develop instance

engcom-Dash avatar Apr 29 '24 05:04 engcom-Dash

Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.

Hi @engcom-Dash, here is your Magento Instance: https://fe74e6b08484c0858eb929e57e74a885.instances-prod.magento-community.engineering Admin access: https://fe74e6b08484c0858eb929e57e74a885.instances-prod.magento-community.engineering/admin_058a Login: 60dbf855 Password: 7a60f5716929

Hi @Nuranto

Thanks for reporting and collaboration.

Can you please provide detailed steps to reproduce with screenshots which would help us reproduce the issue accurately

Thanks!

engcom-Dash avatar Apr 29 '24 06:04 engcom-Dash

(https://fe74e6b08484c0858eb929e57e74a885.instances-prod.magento-community.engineering/admin_058a/sales/order/view/order_id/3/)

https://github.com/magento/magento2/assets/1633463/5237d99c-86ec-4281-a216-2c7d84ed5854

Nuranto avatar Apr 29 '24 08:04 Nuranto

Hi @Nuranto

Verified the issue in 2.4.7 and 2.4 dev instances.

But I am seeing only processing and suspend fraud options in order status after generating invoice.

Please refer to the screenshots. Let us know if we are missing anything.

Screenshot 2024-04-29 at 2 41 49 PM

engcom-Dash avatar Apr 29 '24 09:04 engcom-Dash

I added a custom status on your temporary env.

As you can see in the code :

private function getOrderStatus(string $orderStatus, string $historyStatus): string
    {
        return ($orderStatus === Order::STATE_PROCESSING || $orderStatus === Order::STATUS_FRAUD) ? $historyStatus
            : $orderStatus;
    }

We can update status, but only if current status is processing or fraud.

Nuranto avatar Apr 29 '24 09:04 Nuranto

Hi @Nuranto

Thanks for reporting and collaboration.

Verified the issue on magento 2.4 dev and 2.4.7 instances and the issue is reproducible. Hence, we are confirming the issue.

We are able to update the status only if the current status is in a processing or fraud state. If the status is anything other than processing or fraud state we are not able to update the status.

Please refer the attached screen recording.

https://github.com/magento/magento2/assets/60198592/6b72cbc4-fdc1-4b7c-b09c-48d80e667aba

engcom-Dash avatar Apr 29 '24 14:04 engcom-Dash

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-11877 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Apr 29 '24 14:04 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-Dash. Thank you for verifying the issue.
Issue Available: @engcom-Dash, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Apr 29 '24 14:04 m2-assistant[bot]

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11877

github-jira-sync-bot avatar Apr 29 '24 14:04 github-jira-sync-bot

Related to the order status update, this commit https://github.com/magento/magento2/commit/632f253106e0a2d68cbf0b5a58b12eeeb0a014bf also involves integration with Bling Erp. This integration updates the order via comment.

redati avatar Jun 10 '24 19:06 redati

We have the same error in our Magento instances. Is there already a patch?

dennismetz avatar Jun 12 '24 06:06 dennismetz

I used a workaround and sharing it so it can be helpful to anyone:

Create app/code/DevStone/Bugfix/Controller/Adminhtml/Order/AddComment.php

<?php

namespace DevStone\Bugfix\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/*/');
    }
}

Create app/code/DevStone/Bugfix/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="DevStone\Bugfix\Controller\Adminhtml\Order\AddComment" />
</config>

Of course update the paths and namespace to match an existing module you may have or create a new one with the usual module.xml and registration.php

This will revert the behavior to pre 2.4.7

superdav42 avatar Jun 20 '24 19:06 superdav42

Issue can be reproduced with 2.4.7-p1

If anyone is trying to find the respective lines in their local Magento instance, it's at the end of magento/vendor/magento/module-sales/Controller/Adminhtml/Order/AddComment.php

YiffyToys avatar Jun 24 '24 13:06 YiffyToys

Something like this should work too

cat patches/github-issue-38659_cannot-update-orderstatus-magento-2-4-7.diff

diff --git a/vendor/magento/module-sales/Controller/Adminhtml/Order/AddComment.php b/vendor/magento/module-sales/Controller/Adminhtml/Order/AddComment.php
index ea8af5828c..34608db2bd 100644
--- a/vendor/magento/module-sales/Controller/Adminhtml/Order/AddComment.php     2024-06-29 09:53:19.997829986 +0200
+++ b/vendor/magento/module-sales/Controller/Adminhtml/Order/AddComment.php     2024-06-29 10:15:35.983809521 +0200
@@ -91,7 +91,12 @@
      */
     private function getOrderStatus(string $orderStatus, string $historyStatus): string
     {
-        return ($orderStatus === Order::STATE_PROCESSING || $orderStatus === Order::STATUS_FRAUD) ? $historyStatus
-            : $orderStatus;
+           // BUGFIX for https://github.com/magento/magento2/issues/38659
+           return $historyStatus;
+
+
+//        return ($orderStatus === Order::STATE_PROCESSING || $orderStatus === Order::STATUS_FRAUD) ? $historyStatus
+//            : $orderStatus;
+
     }
 }

cat magento/composer.json

...
 "extra": {
        "magento-force": "override",
        "enable-patching": true,
        "composer-exit-on-patch-failure": true,
        "patches": {
...
            "magento/module-sales": {
                "fix Magento 2.4.7 can not set update order status": "patches/github-issue-38659_cannot-update-orderstatus-magento-2-4-7.diff"
            }
        }
    }

YiffyToys avatar Jun 29 '24 08:06 YiffyToys

Nothing seems to have happend with the pull request #38659 in all of May and all of June. While absolutely basic functionality is broken for all users out there.

Checked out the pull request and basically 1 static code analyser complained that the @param coment wasn't updated to reflect the new method signature and some unit test where $order->config is null failed. Probably because the unit test didn't set it up with proper values. All the other automatic test failures look like the codebase the PR was applied to was already broken.

The initial author hasn't responded in 2 month, no other developer picked it up and to do it yourself Adobe wants you to jump through even more (legal) hoops then you already have to in order to clone the repository, check it out, do your branch and create a new PR. No time for that.

YiffyToys avatar Jul 01 '24 18:07 YiffyToys

Having same issue with 2.4.7 - Need solution soon have to send email for every process to update customers.

NeoM-dev avatar Jul 04 '24 16:07 NeoM-dev

Having same issue. Major functionality broken. Issue been open for nearly 2 months. Fixes like this are taking far too long to review/release. I am not sure why we always need 100's of fixes in each release; it shouldn't be a huge deal to release a 2.4.7.1, 2.4.7.2, etc. with a couple dozen critical fixes.

joshbourke avatar Jul 11 '24 15:07 joshbourke

@magento I am working on this

BeggiNN avatar Jul 12 '24 06:07 BeggiNN

is there any patch or hotfix? this is quite important as many integrations (incl. payment) are failing that are using the comment api for webhooks etc

simonmaass avatar Jul 16 '24 11:07 simonmaass

The order state should be checked rather than the status to begin with; no clue how this got greenlit.

You can make custom order statuses for a singular order state. With the changes that have been made it's impossible to change order status after it's been set.

You should be able to switch freely between order statuses for the same order state.

This needs to be rectified ASAP.

edit: In fact; since only the statuses for the current state are displayed, it should be impossible to enter an incorrect status...

Quazz avatar Jul 30 '24 14:07 Quazz

Almost four months since the bug was reported... is there any hope that a patch will be released soon?

dennismetz avatar Aug 21 '24 14:08 dennismetz

We are also waiting for a patch for this issue.

Henryrchurchill avatar Aug 21 '24 14:08 Henryrchurchill