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

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