allowShipping example

$this->fieldHelper->addCountryTranslation($query$context);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        foreach ($data as $row) {
            $country = $this->countryHydrator->hydrateCountry($row);
            if (!$country->isActive()) {
                continue;
            }

            if (!$country->allowShipping()) {
                continue;
            }

            return $country;
        }

        return null;
    }

    /** * {@inheritdoc} */
'countryiso' => $country->getIso(),
            'countryen' => $country->getEn(),
            'position' => $country->getPosition(),
            'taxfree' => $country->isTaxFree(),
            'taxfree_ustid' => $country->isTaxFreeForVatId(),
            'taxfree_ustid_checked' => $country->checkVatId(),
            'active' => $country->isActive(),
            'iso3' => $country->getIso3(),
            'display_state_in_registration' => $country->displayStateSelection(),
            'force_state_in_registration' => $country->requiresStateSelection(),
            'areaID' => $country->getAreaId(),
            'allow_shipping' => $country->allowShipping(),
            'states' => [],
            'attributes' => $country->getAttributes(),
        ]);

        if ($country->displayStateSelection()) {
            $data['states'] = $this->convertStateStructList($country->getStates());
            $data['states'] = array_map(function D$state) use ($country) {
                $state['countryID'] = $country->getId();

                return $state;
            }$data['states']);
        }
/** @var Address $billing */
            $billing = $billingForm->getData();

            $billingCountry = $billing->getCountry();

            if ($billingCountry === null) {
                throw new RuntimeException('Billing address needs a country');
            }

            $country = $this->get(CountryGatewayInterface::class)->getCountry($billingCountry->getId()$context);

            if (!$country->allowShipping()) {
                $errors['billing']['country'] = $this->get('snippets')->getNamespace('frontend/register/index')->get('CountryNotAvailableForShipping');
            }
        }

        $validCaptcha = $this->validateCaptcha($this->get(Shopware_Components_Config::class)->get('registerCaptcha')$this->request);
        if (!$validCaptcha) {
            $errors['captcha'] = [
                $this->get('snippets')
                    ->getNamespace('widgets/captcha/custom_captcha')
                    ->get('invalidCaptchaMessage'),
            ];
        }

    private function isValidShippingAddress(Address $address)
    {
        if (empty($address->getAdditional()['setDefaultShippingAddress']) && $address->getId() !== $address->getCustomer()->getDefaultShippingAddress()->getId()) {
            return true;
        }

        $context = $this->get(ContextServiceInterface::class)->getContext();
        $country = $this->get(CountryGatewayInterface::class)->getCountry($address->getCountry()->getId()$context);

        return $country->allowShipping();
    }

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

        

        $address = $this->get(ModelManager::class)->find(Address::class$addressId);
        if (!$address instanceof Address || !$address->getCountry() instanceof Country) {
            $this->View()->assign('invalidShippingCountry', true);

            return false;
        }

        $context = $this->get(ContextServiceInterface::class)->getContext();
        $country = $this->get(CountryGatewayInterface::class)->getCountry($address->getCountry()->getId()$context);

        if ($isShippingAddress && !$country->allowShipping()) {
            $this->View()->assign('invalidShippingCountry', true);

            return false;
        }

        return $this->get(AddressValidatorInterface::class)->isValid($address);
    }

    /** * @return array<string, mixed> */
    
Home | Imprint | This part of the site doesn't use cookies.