convertCountryStructList example

/** * @return array */
    private function translateCountries(array $addresses)
    {
        $countryIds = array_map(function D$address) {
            return $address['country']['id'];
        }$addresses);

        $context = $this->get(ContextServiceInterface::class)->getContext();
        $countries = $this->get(CountryGatewayInterface::class)->getCountries($countryIds$context);
        $countries = $this->get(LegacyStructConverter::class)->convertCountryStructList($countries);

        foreach ($addresses as &$address) {
            $address['country'] = array_merge($address['country']$countries[$address['country']['id']]);
        }
        unset($address);

        return $addresses;
    }
}
/** * Get list of currently active countries. Includes states and translations * * @return array<int, array<string, mixed>> Country list, indexed by ID */
    public function sGetCountryList()
    {
        $context = Shopware()->Container()->get('shopware_storefront.context_service')->getShopContext();
        $service = Shopware()->Container()->get('shopware_storefront.location_service');

        $countryList = $service->getCountries($context);
        $countryList = Shopware()->Container()->get('legacy_struct_converter')->convertCountryStructList($countryList);

        $countryList = array_map(function D$country) {
            $request = $this->front->Request();
            $countryId = (int) $country['id'];
            $country['flag'] = (int) $request->getPost('country') === $countryId || (int) $request->getPost('countryID') === $countryId;

            return $country;
        }$countryList);

        return $this->eventManager->filter(
            'Shopware_Modules_Admin_GetCountries_FilterResult',
            
Home | Imprint | This part of the site doesn't use cookies.