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.54k stars 9.32k forks source link

Registered shipping rates validators are not running #39039

Closed kooliahmd closed 1 month ago

kooliahmd commented 2 months ago

Summary

Following this documentation in order to register a custom shipping rate validator, I found out that shipping-rates-validator.js::validateAddressData would never execute the registered validator as long as the default validator returns true.

This is because shipping-rates-validator.js registers a default-validator and when it runs the validation it considers the rates as valid when at least on of the registered validators returned true. This is problematic, as the custom validator would not even run when the default validator returns true.

Examples

N/A

Proposed solution

Change this function validateAddressData in module-checkout/view/frontend/web/js/model/shipping-rates-validator.js

From:

        validateAddressData: function (address) {
            return validators.some(function (validator) {
                return validator.validate(address);
            });
        },

To:

        validateAddressData: function (address) {
            return validators.forEach(function (validator) {
                return validator.validate(address);
            });
        },

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 months ago

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

m2-assistant[bot] commented 2 months 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 months ago

Hello @kooliahmd,

Thanks for the report and collaboration!

We have tried to reproduce the issue in the latest 2.4-develop branch. In order to reproduce it we have made a custom module as follows:

https://github.com/engcom-Hotel/magento2/tree/issue39039/app/code/Magz/Issue39039

But we are unable to reproduce it, can you please let us know if we missed anything?

Thanks

engcom-Hotel commented 1 month ago

Dear @kooliahmd,

We've observed that there haven't been any updates on this issue for quite some time. Therefore, we assume it's been resolved and will close it. Feel free to open a new ticket or reopen this one if you require further assistance.

Regards