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

.fail() and .always() not firing on this.getPlaceOrderDeferredObject() with HTTP 400 Errors #35878

Closed hopeseekr closed 2 years ago

hopeseekr commented 2 years ago

Preconditions and environment

It works fine in Magento v2.4.0 through v2.4.2-p2.

Steps to reproduce

  1. Create a Magento extension.
  2. Overload the placeOrderAction.
  3. Write the following code for placeOrder:

    placeOrder: function (data, event) {
        var self = this;
    
        if (event) {
            event.preventDefault();
        }
    
        $('.s4messages').html('');
    
        if (this.validate()) {
            this.isPlaceOrderActionAllowed(false);
    
            this.getPlaceOrderDeferredObject()
                .done(function () { alert('success'); });
                .fail(function () { alert('failure'); });
                .always(function () { alert('always'); });
           }
    }

Expected result

Expected: For the .done() to fire on success, for .fail() to fire if there is an HTTP 400 on the AJAX call, and .always() to fire everytime.

Actual result

Actual:

  1. .done() will always fire when there is no HTTP error status code (4xx, 5xx).
  2. .always() will fire when there is no HTTP error status code (4xx, 5xx).
  3. fail() nor .always() will never fire when there is an HTTP error status code (4xx, 5xx).

Instead, Magento's own JavaScript explodes with the following error:

knockout.js:3054 Uncaught TypeError: Cannot read properties of null (reading 'appendChild')
    at Object.prepend (knockout.js:3054:43)
    at Object.insertAfter (knockout.js:3062:48)
    at ko.utils.setDomNodeChildrenFromArrayMapping (knockout.js:6465:48)
    at Object.ignore (knockout.js:1563:45)
    at setDomNodeChildrenFromArrayMapping (knockout.js:6017:48)
    at ko.subscription._callback (knockout.js:6027:29)
    at Function.notifySubscribers (knockout.js:1401:50)
    at ko.subscription.notifyChanges [as _callback] (knockout.js:1909:60)
    at Function.notifySubscribers (knockout.js:1401:50)
    at Function.valueHasMutated (knockout.js:1645:46)
prepend @ knockout.js:3054

This prevents the order process from happening. The user has to hard-refresh the page to get to a working shopping cart, but then they are unable to place an order that has a sad path. No error messages are shown to the end-user, becuase the JS process encountered a terminal stop.

Additional information

Instead, Magento's own JavaScript explodes with the following error:

knockout.js:3054 Uncaught TypeError: Cannot read properties of null (reading 'appendChild')
    at Object.prepend (knockout.js:3054:43)
    at Object.insertAfter (knockout.js:3062:48)
    at ko.utils.setDomNodeChildrenFromArrayMapping (knockout.js:6465:48)
    at Object.ignore (knockout.js:1563:45)
    at setDomNodeChildrenFromArrayMapping (knockout.js:6017:48)
    at ko.subscription._callback (knockout.js:6027:29)
    at Function.notifySubscribers (knockout.js:1401:50)
    at ko.subscription.notifyChanges [as _callback] (knockout.js:1909:60)
    at Function.notifySubscribers (knockout.js:1401:50)
    at Function.valueHasMutated (knockout.js:1645:46)
prepend @ knockout.js:3054

Upon drilling in, it's because this.containerNode is null on line 3054 of knockout.js.

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 years ago

Hi @hopeseekr. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

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:

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

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


: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.

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

hopeseekr commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @hopeseekr. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @hopeseekr, here is your Magento Instance: https://4ea669a210fd6878acb4e8c3d2fae193.instances.magento-community.engineering Admin access: https://4ea669a210fd6878acb4e8c3d2fae193.instances.magento-community.engineering/admin_b308 Login: 2cb14c34 Password: 72b77fb1f336

hopeseekr commented 2 years ago

It seems that Braintree, for one instance, has had to reimplement this.getPlaceOrderDeferredObject() to get around this problem:

image

hopeseekr commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @hopeseekr. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @hopeseekr, here is your Magento Instance: https://4ea669a210fd6878acb4e8c3d2fae193.instances.magento-community.engineering Admin access: https://4ea669a210fd6878acb4e8c3d2fae193.instances.magento-community.engineering/admin_96e1 Login: fb174358 Password: feb767126c3b

hopeseekr commented 2 years ago

@magento give me 2.4-develop instance with extensions shift4/payment:1.1.20

magento-deployment-service[bot] commented 2 years ago

Hi @hopeseekr. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @hopeseekr, here is your Magento Instance: https://4ea669a210fd6878acb4e8c3d2fae193.instances.magento-community.engineering Admin access: https://4ea669a210fd6878acb4e8c3d2fae193.instances.magento-community.engineering/admin_4015 Login: e01c8c1e Password: a14f8556f4a7

m2-assistant[bot] commented 2 years ago

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

engcom-Hotel commented 2 years ago

Hello @hopeseekr,

Thanks for the report and collaboration!

We have tried to reproduce the issue in Magento 2.4-develop branch but the issue is not reproducible for us. We have made a custom module which has been attached with this comment below.

Let us know if we have missed anything.

Magz.zip

Thanks

engcom-Hotel commented 2 years ago

Dear @hopeseekr,

We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.

Regards