getCountries example

$dispatchModel->getPayments()->add($paymentModel);
            }
        }

        // Convert the countries to their country models         foreach ($countries as $country) {
            if (empty($country['id'])) {
                continue;
            }
            $countryModel = $this->getModelManager()->find(Country::class$country['id']);
            if ($countryModel instanceof Country) {
                $dispatchModel->getCountries()->add($countryModel);
            }
        }

        foreach ($categories as $category) {
            if (empty($category['id'])) {
                continue;
            }

            $categoryModel = $this->getModelManager()->find(Category::class$category['id']);
            if ($categoryModel instanceof Category) {
                $dispatchModel->getCategories()->add($categoryModel);
            }

    public function load(Request $request, SalesChannelContext $salesChannelContext): AccountLoginPage
    {
        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = AccountLoginPage::createFrom($page);

        if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        $page->setCountries($this->getCountries($salesChannelContext));

        $page->setSalutations($this->getSalutations($salesChannelContext));

        $this->eventDispatcher->dispatch(
            new AccountLoginPageLoadedEvent($page$salesChannelContext$request)
        );

        return $page;
    }

    /** * @throws InconsistentCriteriaIdsException */
private Connection $connection;

    public function __construct(CountryGatewayInterface $gateway, Connection $connection)
    {
        $this->gateway = $gateway;
        $this->connection = $connection;
    }

    public function getCountries(ShopContextInterface $context)
    {
        $ids = $this->getCountryIds();
        $countries = $this->gateway->getCountries($ids$context);

        $states = $this->gateway->getCountryStates($ids$context);

        $result = [];
        foreach ($countries as $country) {
            if (!$country->isActive()) {
                continue;
            }

            if (isset($states[$country->getId()])) {
                $country->setStates(
                    
/** * 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(
            

        $request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

        /** @var AccountLoginPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(AccountLoginPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(AccountLoginPage::class$page);
        static::assertSame(StorefrontPageTestConstants::COUNTRY_COUNT, $page->getCountries()->count());
        static::assertInstanceOf(CountryStateCollection::class$page->getCountries()->first()->getStates());
        self::assertPageEvent(AccountLoginPageLoadedEvent::class$event$context$request$page);
    }

    public function testItLoadsWithoutACustomer(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();
        $page = $this->getPageLoader()->load($request$context);

        static::assertSame(StorefrontPageTestConstants::COUNTRY_COUNT, $page->getCountries()->count());
        
$addresses = $this->addressRepository->getListArray(
            $this->container->get('session')->get('sUserId')
        );

        // Create a list of ids of occurring countries and states         $countryIds = array_unique(array_filter(array_column($addresses, 'countryId')));
        $stateIds = array_unique(array_filter(array_column($addresses, 'stateId')));

        $countryRepository = $this->container->get(CountryGatewayInterface::class);
        $context = $this->container->get(ContextServiceInterface::class)->getShopContext();

        $countries = $countryRepository->getCountries($countryIds$context);
        $states = $countryRepository->getStates($stateIds$context);

        // Apply translations for countries and states to address array, converting them from structs to arrays in the process         foreach ($addresses as &$address) {
            if (\array_key_exists($address['countryId']$countries)) {
                $address['country'] = json_decode(json_encode($countries[$address['countryId']]), true);
            }
            if (\array_key_exists($address['stateId']$states)) {
                $address['state'] = json_decode(json_encode($states[$address['stateId']]), true);
            }
        }
        


        yield 'render with shipping address' => [
            [7],
            function DDocumentGenerateOperation $operation, ContainerInterface $container): void {
                $orderId = $operation->getOrderId();
                $criteria = OrderDocumentCriteriaFactory::create([$orderId]);
                /** @var OrderEntity $order */
                $order = $container->get('order.repository')->search($criteria, Context::createDefaultContext())->get($orderId);
                static::assertNotNull($order->getDeliveries());
                /** @var CountryEntity $country */
                $country = $order->getDeliveries()->getShippingAddress()->getCountries()->first();
                $country->setCompanyTax(new TaxFreeConfig(true, Defaults::CURRENCY, 0));

                $container->get('country.repository')->update([[
                    'id' => $country->getId(),
                    'companyTax' => ['enabled' => true, 'currencyId' => Defaults::CURRENCY, 'amount' => 0],
                ]], Context::createDefaultContext());
                $companyPhone = '123123123';
                $vatIds = ['VAT-123123'];

                static::assertNotNull($order->getOrderCustomer());
                $container->get('customer.repository')->update([[
                    
try {
            $id = $this->Request()->getParam('id');
            $payment = $this->get('models')->find(Payment::class$id);
            $action = $payment->getAction();
            $data = $this->Request()->getParams();
            $data['surcharge'] = str_replace(',', '.', $data['surcharge'] ?? '');
            $data['debitPercent'] = str_replace(',', '.', $data['debitPercent'] ?? '');

            $countries = new ArrayCollection();
            if (!empty($data['countries'])) {
                // Clear all countries, to save the old and new ones then                 $payment->getCountries()->clear();
                foreach ($data['countries'] as $country) {
                    $model = $this->get('models')->find(Country::class$country['id']);
                    $countries->add($model);
                }
                $data['countries'] = $countries;
            }

            $shops = new ArrayCollection();
            if (!empty($data['shops'])) {
                // Clear all shops, to save the old and new ones then                 $payment->getShops()->clear();
                

    public function load(Request $request, SalesChannelContext $salesChannelContext): CheckoutRegisterPage
    {
        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = CheckoutRegisterPage::createFrom($page);

        if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        $page->setCountries($this->getCountries($salesChannelContext));
        $page->setCart($this->cartService->getCart($salesChannelContext->getToken()$salesChannelContext));
        $page->setSalutations($this->getSalutations($salesChannelContext));

        $addressId = $request->attributes->get('addressId');
        if ($addressId) {
            $address = $this->getById((string) $addressId$salesChannelContext);
            $page->setAddress($address);
        }

        $this->eventDispatcher->dispatch(
            new CheckoutRegisterPageLoadedEvent($page$salesChannelContext$request)
        );

    public function load(Request $request, SalesChannelContext $salesChannelContext): CheckoutCartPage
    {
        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = CheckoutCartPage::createFrom($page);

        if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        $page->setCountries($this->getCountries($salesChannelContext));

        $page->setPaymentMethods($this->getPaymentMethods($salesChannelContext));

        $page->setShippingMethods($this->getShippingMethods($salesChannelContext));

        $page->setCart($this->cartService->get($salesChannelContext->getToken()$salesChannelContext));

        $this->eventDispatcher->dispatch(
            new CheckoutCartPageLoadedEvent($page$salesChannelContext$request)
        );

        

        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = AddressDetailPage::createFrom($page);

        if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        $page->setSalutations($this->getSalutations($salesChannelContext));

        $page->setCountries($this->getCountries($salesChannelContext));

        $page->setAddress($this->getAddress($request$salesChannelContext$customer));

        $this->eventDispatcher->dispatch(
            new AddressDetailPageLoadedEvent($page$salesChannelContext$request)
        );

        return $page;
    }

    /** * @throws InconsistentCriteriaIdsException */

        $areas = $this->getAreas([$id]$context);

        return array_shift($areas);
    }

    /** * {@inheritdoc} */
    public function getCountry($id, ShopContextInterface $context)
    {
        $countries = $this->getCountries([$id]$context);

        return array_shift($countries);
    }

    /** * {@inheritdoc} */
    public function getState($id, ShopContextInterface $context)
    {
        $states = $this->getStates([$id]$context);

        

    public function load(Request $request, SalesChannelContext $salesChannelContext, CustomerEntity $customer): AddressListingPage
    {
        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = AddressListingPage::createFrom($page);

        $page->setSalutations($this->getSalutations($salesChannelContext));

        $page->setCountries($this->getCountries($salesChannelContext));

        $criteria = (new Criteria())->addSorting(new FieldSorting('firstName', FieldSorting::ASCENDING));

        $page->setAddresses($this->listAddressRoute->load($criteria$salesChannelContext$customer)->getAddressCollection());

        $page->setCart($this->cartService->getCart($salesChannelContext->getToken()$salesChannelContext));

        $page->setAddress(
            $page->getAddresses()->get($request->get('addressId'))
        );

        
Home | Imprint | This part of the site doesn't use cookies.