vendor/shopware/core/System/Country/CountryCollection.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\System\Country;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  4. /**
  5.  * @extends EntityCollection<CountryEntity>
  6.  */
  7. class CountryCollection extends EntityCollection
  8. {
  9.     public function sortCountryAndStates(): void
  10.     {
  11.         $this->sortByPositionAndName();
  12.         foreach ($this->getIterator() as $country) {
  13.             if ($country->getStates()) {
  14.                 $country->getStates()->sortByPositionAndName();
  15.             }
  16.         }
  17.     }
  18.     public function sortByPositionAndName(): void
  19.     {
  20.         uasort($this->elements, function (CountryEntity $aCountryEntity $b) {
  21.             if ($a->getPosition() !== $b->getPosition()) {
  22.                 return $a->getPosition() <=> $b->getPosition();
  23.             }
  24.             if ($a->getTranslation('name') !== $b->getTranslation('name')) {
  25.                 return strnatcasecmp($a->getTranslation('name'), $b->getTranslation('name'));
  26.             }
  27.             return 0;
  28.         });
  29.     }
  30.     public function getApiAlias(): string
  31.     {
  32.         return 'country_collection';
  33.     }
  34.     protected function getExpectedClass(): string
  35.     {
  36.         return CountryEntity::class;
  37.     }
  38. }