- πΊπΈUnited States cindytwilliams Nashville, TN
Patch #4 works well for me. It adds a "sort by" option in the view, which allows us to sort the results by either the name or the code.
- Status changed to Needs work
over 1 year ago 6:33am 1 November 2023 - πΊπΈUnited States dww
Generally +1 to this. A few things needed before we can commit it:
- Unlike
#2783699: Views sorting by country name β
, this patch has no tests. π
Since y'all mostly copied the Views plugin from that issue, check out
commit 9a8756aeb
,tests/src/Functional/Views/CountrySortTest.php
andtests/modules/address_test/config/optional/views.view.address_test_sort_country.yml
for inspiration. - Minor doc nit:
+ * Constructs a new Country object.
that's not the class being constructed. I hate our boilerplate standards for constructors, but as long as those are still the standard, we need to be accurate with the docs.
Thanks!
-Derek - Unlike
#2783699: Views sorting by country name β
, this patch has no tests. π
Since y'all mostly copied the Views plugin from that issue, check out
- Status changed to Needs review
over 1 year ago 2:54pm 1 November 2023 - last update
over 1 year ago 34 pass - πΊπ¦Ukraine sickness29
Same code from #4 with new browser test for administrative area sort handler. Also fixed constructor phpdoc.
- Status changed to Needs work
over 1 year ago 6:45pm 1 November 2023 - πΊπΈUnited States dww
Thanks! That was fast. π However:
+ $this->assertSession()->pageTextContains('1-AL'); + $this->assertSession()->pageTextContains('2-AS'); + $this->assertSession()->pageTextContains('3-CT'); + $this->assertSession()->pageTextContains('4-CO'); + $this->assertSession()->pageTextContains('5-MA'); + $this->assertSession()->pageTextContains('6-ME'); + $this->assertSession()->pageTextContains('7-MD');
That maps to this list:
- Alabama
- American Samoa
- Connecticut
- Colorado
- Massachusetts
- Maine
- Maryland
That's buggy. Colorado vs. Connecticut are out of order, as is Massachusetts (which should be last).
- πΊπΈUnited States dww
p.s. I'd love to see these full names as at least comments in the test code so we can reason about such things without having to pull up
vendor/commerceguys/addressing/resources/subdivision/US.json
to compare.p.p.s. IA (Iowa) would be another good state to include in this test, since the code would sort first among other "I" states, but the name should be last (after Illinois and Indiana).
- Assigned to sickness29
- Issue was unassigned.
- Status changed to Needs review
over 1 year ago 2:07pm 2 November 2023 - last update
over 1 year ago 34 pass - πΊπ¦Ukraine sickness29
Updated patch with fix for solution from 4 which put all administrative areas for all countries in same sql expression and it bugged because some countries had administrative areas with same names. Fixed that by adding country check as well so administrative area's "weight" only applied when country and area match.
Also updated test to contain full admin area names and added Iowa with Illinois, replaced AL/AS with AZ/AR which makes more sense for testing purposes. - last update
over 1 year ago 33 pass, 2 fail - Status changed to Needs work
over 1 year ago 10:58am 3 December 2023 - π·πΈSerbia bojanz
2.0.x test is failing with:
```
1) Drupal\Tests\address\Functional\Views\AdministrativeAreaSortTest::testSortAdministrativeAreaName
Exception: Deprecated function: ctype_upper(): Argument of type int will be interpreted as string in the future
Drupal\address\Plugin\views\sort\AdministrativeArea->query()() (Line: 117)
```Please check how ctype_upper() is getting a non-string administrative area code passed in.
- Status changed to Needs review
over 1 year ago 3:13pm 27 December 2023 - last update
over 1 year ago 40 pass - πΊπ¦Ukraine sickness29
Hi @bojanz
with update of commerceguys/addressing we now have many admin area codes which are numeral, and ctype_upper was used to check for format before passing it into mysql case.
I have added a check for string there and it should be good now - π·πΈSerbia bojanz
+ $subdivisions = $this->subdivisionRepository->getList([$country_code], $this->langcode); + foreach (array_keys($subdivisions) as $administrative_area_code) { + // Administrative_area codes format check. + if (is_string($administrative_area_code) && ctype_upper($administrative_area_code)) { + $when[] = "WHEN $country_field = '$country_code' AND $field_name = '$administrative_area_code' THEN " . $i++; + } + }
So if an administrative area code is numeric (e.g. "82"), we will just skip it, and the handler won't work for that country?
Can't we just not pass it to ctype_upper() in that case, and add it as-is to the query?