sortByPositionAndName example

use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\Log\Package;

/** * @extends EntityCollection<CountryEntity> */
#[Package('core')] class CountryCollection extends EntityCollection
{
    public function sortCountryAndStates(): void
    {
        $this->sortByPositionAndName();

        foreach ($this->getIterator() as $country) {
            if ($country->getStates()) {
                $country->getStates()->sortByPositionAndName();
            }
        }
    }

    public function sortByPositionAndName(): void
    {
        uasort($this->elements, static function DCountryEntity $a, CountryEntity $b) {
            
if (!$shippingMethods->has($context->getShippingMethod()->getId())) {
            $shippingMethods->add($context->getShippingMethod());
        }

        return $shippingMethods;
    }

    private function getCountries(SalesChannelContext $context): CountryCollection
    {
        $countries = $this->countryRoute->load(new Request()new Criteria()$context)->getCountries();
        $countries->sortByPositionAndName();

        return $countries;
    }
}
Home | Imprint | This part of the site doesn't use cookies.