magento2
magento2 copied to clipboard
Fixes problem with latest versions of ICU library where AmPmMarkers i…
…s no longer defined for each locale. If that's the case fall back to AmPmMarkersAbbr and if that one doesn't exist, fallback to null. This fixes a second problem where previously we always returned 'null' due to the index being a string instead of an integer. That's also fixed now.
Description (*)
See discussions in #38214
The second commit in this PR is to deal with static test failures where a method can contain at most 100 lines, which we just managed to reach with the change in the first commit.
I think this is quite an important fix, because an update of the ICU library on a server will start crashing the shop on every frontend page that contains a JS calendar widget. So if a Linux operating system decides to upgrade to a different version of ICU, your shop might be in trouble despite no other changes have being made to it. Which could be surprising to the merchant & developers. Maybe it's worth turning this into a quality patch as every Magento version might run into this issue one day or another.
Here's an example of how this data is defined in ICU:
- English: https://github.com/unicode-org/icu/blob/d0672fa8ab11a9795ad7d42f20e63dd2307cd8e2/icu4c/source/data/locales/en.txt#L783-L802
- Swedish: https://github.com/unicode-org/icu/blob/d0672fa8ab11a9795ad7d42f20e63dd2307cd8e2/icu4c/source/data/locales/sv.txt#L695-L698
- German: https://github.com/unicode-org/icu/blob/d0672fa8ab11a9795ad7d42f20e63dd2307cd8e2/icu4c/source/data/locales/de.txt#L484 (nothing is here)
This PR fixes the problem mentioned in the issue and fixes a second bug that has existed since forever in Magento where we always outputted null
to the am
& pm
variables that get exposed in the phtml files that use this block. This was due to using ['0']
and ['1']
instead of [0]
& [1]
After some thinking, I decided to implement a fallback system, where we first try to fetch AmPmMarkers
. If that doesn't exists, try fetching AmPmMarkersAbbr
and if that doesn't exists, fallback to null
.
As far as I can see, these am
and pm
variable assignments aren't used in core Magento, but are send to the calendar.phtml file and can be outputted with <?= $am; ?>
and <?= $pm; ?>
. So that if custom theme needs this info, they can use it.
I've added some more locale's to be tested in the unit tests, those will also fail without the fixes proposed here when the ICU library is 74.1 or 74.2
Related Pull Requests
Fixed Issues (if relevant)
- Fixes #38214
Manual testing scenarios (*)
- Setup clean Magento
- In backoffice, go to Stores > Attributes > Product
- Find and edit the special_from_date attribute
- Under Storefront Properties, enable both 'Use in Search' and 'Visible in Advanced Search' and save the attribute
- Reindex
- Edit the file
app/code/Magento/Theme/view/frontend/templates/js/calendar.phtml
and add this line at the very bottom:<ul><li>am: <?= $am; ?></li><li>pm: <?= $pm; ?></li></ul>
- Configure "lv_LV" locale:
bin/magento config:set general/locale/code lv_LV
- Flush the caches
- In frontend click on the Advanced Search link in the footer
- Expected to see "priekšpusdienā" & "pēcpusdienā" (but then escaped for JS)
- Configure "sv_SE" locale:
bin/magento config:set general/locale/code sv_SE
- Flush the caches
- In frontend click on the Advanced Search link in the footer
- Expected to see "fm" & "em"
- Configure "de_AT" locale:
bin/magento config:set general/locale/code de_AT
- Flush the caches
- In frontend click on the Advanced Search link in the footer
- Expected to see "null" & "null"
The biggest thing to check for is that this page doesn't crash. It will not crash with older versions of the ICU library but will crash without these fixes with ICU 74.1 or 74.2. The output for "de_AT" will also be different when using older versions of the ICU library.
Questions or comments
Contribution checklist (*)
- [x] Pull request has a meaningful description of its purpose
- [x] All commits are accompanied by meaningful commit messages
- [ ] All new or changed code is covered with unit/integration tests (if applicable)
- [ ] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- [ ] All automated tests passed successfully (all builds are green)
Hi @hostep. Thank you for your contribution! Here are some useful tips on how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:
-
@magento give me test instance
- deploy test instance based on PR changes -
@magento give me 2.4-develop instance
- deploy vanilla Magento instance
:exclamation: Automated tests can be triggered manually with an appropriate comment:
-
@magento run all tests
- run or re-run all required tests against the PR changes -
@magento run <test-build(s)>
- run or re-run specific test build(s) For example:@magento run Unit Tests
<test-build(s)>
is a comma-separated list of build names.
Allowed build names are:
-
Database Compare
-
Functional Tests CE
-
Functional Tests EE
-
Functional Tests B2B
-
Integration Tests
-
Magento Health Index
-
Sample Data Tests CE
-
Sample Data Tests EE
-
Sample Data Tests B2B
-
Static Tests
-
Unit Tests
-
WebAPI Tests
-
Semantic Version Checker
You can find more information about the builds here :information_source: Run only required test builds during development. Run all test builds before sending your pull request for review.
For more details, review the Code Contributions documentation. Join Magento Community Engineering Slack and ask your questions in #github channel.
@magento run all tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.
@magento run all tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.
@magento run all tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.
Hello @hostep Thank you for your contribution Looks like the failed tests are not related on your changes
@magento run Functional Tests B2B, WebAPI Tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.
I don't see why that DevExperience label was added? Because this will cause issues on production environments once the ICU library used by PHP is at the latest version...
@magento run all tests
:heavy_check_mark: QA Passed
Preconditions:
- Install fresh Magento
2.4-develop
Manual testing scenario: We have followed steps from comment
Before: :heavy_multiplication_x:
After: :heavy_check_mark:
Builds are failed. Hence, moving this PR to Extended Testing.
@magento run all tests
@magento run WebAPI Tests,Unit Tests,Functional Tests EE,Functional Tests CE,Functional Tests B2B,Integration Tests
@magento run Functional Tests EE,Functional Tests CE,Functional Tests B2B
@magento run Unit Tests,Integration Tests
WebAPI Tests failure are known failure not related to PR changes.
Functional Tests EE,Functional Tests B2B failure are different on last two run on same commit.
Functional Tests EE
Run1
Run2
Functional Tests B2B
Run1
Run2
Hence moving to merge in progress