getCountryId example

/** * @extends EntityCollection<CountryStateEntity> */
#[Package('buyers-experience')] class CountryStateCollection extends EntityCollection
{
    /** * @return array<string> */
    public function getCountryIds(): array
    {
        return $this->fmap(fn (CountryStateEntity $countryState) => $countryState->getCountryId());
    }

    public function filterByCountryId(string $id): self
    {
        return $this->filter(fn (CountryStateEntity $countryState) => $countryState->getCountryId() === $id);
    }

    public function sortByPositionAndName(): void
    {
        uasort($this->elements, static function DCountryStateEntity $a, CountryStateEntity $b) {
            $aPosition = $a->getPosition();
            

    public function deserialize(Config $config, EntityDefinition $definition$entity)
    {
        $deserialized = parent::deserialize($config$definition$entity);

        $deserialized = \is_array($deserialized) ? $deserialized : iterator_to_array($deserialized);

        if (!isset($deserialized['id']) && isset($deserialized['iso'])) {
            $id = $this->getCountryId($deserialized['iso']);

            if ($id) {
                $deserialized['id'] = $id;
            }
        }

        yield from $deserialized;
    }

    public function supports(string $entity): bool
    {
        
/** * @extends EntityCollection<OrderAddressEntity> */
#[Package('checkout')] class OrderAddressCollection extends EntityCollection
{
    /** * @return list<string> */
    public function getCountryIds(): array
    {
        return $this->fmap(fn (OrderAddressEntity $orderAddress) => $orderAddress->getCountryId());
    }

    public function filterByCountryId(string $id): self
    {
        return $this->filter(fn (OrderAddressEntity $orderAddress) => $orderAddress->getCountryId() === $id);
    }

    /** * @return list<string> */
    public function getCountryStateIds(): array
    {

    }

    private function shouldCheckVatIdFormat(CustomerVatIdentification $constraint): bool
    {
        if ($constraint->getShouldCheck()) {
            return true;
        }

        return (bool) $this->connection->fetchOne(
            'SELECT check_vat_id_pattern FROM `country` WHERE id = :id',
            ['id' => Uuid::fromHexToBytes($constraint->getCountryId())]
        );
    }

    private function getVatPattern(CustomerVatIdentification $constraint): string
    {
        return (string) $this->connection->fetchOne(
            'SELECT vat_id_pattern FROM `country` WHERE id = :id',
            ['id' => Uuid::fromHexToBytes($constraint->getCountryId())]
        );
    }
}
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\Log\Package;

/** * @extends EntityCollection<CountryTranslationEntity> */
#[Package('buyers-experience')] class CountryTranslationCollection extends EntityCollection
{
    public function getCountryIds(): array
    {
        return $this->fmap(fn (CountryTranslationEntity $countryTranslation) => $countryTranslation->getCountryId());
    }

    public function filterByCountryId(string $id): self
    {
        return $this->filter(fn (CountryTranslationEntity $countryTranslation) => $countryTranslation->getCountryId() === $id);
    }

    public function getLanguageIds(): array
    {
        return $this->fmap(fn (CountryTranslationEntity $countryTranslation) => $countryTranslation->getLanguageId());
    }

    


        return true;
    }

    private function metPreconditions(TaxRuleEntity $taxRuleEntity, ShippingLocation $shippingLocation): bool
    {
        if ($this->getZipCode($shippingLocation) === null) {
            return false;
        }

        return $shippingLocation->getCountry()->getId() === $taxRuleEntity->getCountryId();
    }

    private function getZipCode(ShippingLocation $shippingLocation): ?string
    {
        return $shippingLocation->getAddress() !== null ? $shippingLocation->getAddress()->getZipcode() : null;
    }
}
'name' => 'test',
                    'email' => $email,
                    'password' => $password,
                    'firstName' => 'foo',
                    'lastName' => 'bar',
                    'groupId' => $salesChannel->getCustomerGroupId(),
                    'salutationId' => $this->getValidSalutationId(),
                    'defaultPaymentMethodId' => $salesChannel->getPaymentMethodId(),
                    'salesChannelId' => $salesChannel->getId(),
                    'defaultBillingAddress' => [
                        'id' => $defaultBillingAddress,
                        'countryId' => $salesChannel->getCountryId(),
                        'salutationId' => $this->getValidSalutationId(),
                        'firstName' => 'foo',
                        'lastName' => 'bar',
                        'zipcode' => '48599',
                        'city' => 'gronau',
                        'street' => 'Schillerstr.',
                    ],
                    'defaultShippingAddressId' => $defaultBillingAddress,
                    'customerNumber' => 'asdf',
                ],
            ],
            
private function createSalesChannel(string $newId, array $shop, Connection $connection): void
    {
        $typeId = Defaults::SALES_CHANNEL_TYPE_STOREFRONT;

        $paymentMethod = $this->getFirstActivePaymentMethodId($connection);
        $shippingMethod = $this->getFirstActiveShippingMethodId($connection);

        $languageId = $this->getLanguageId($shop['locale']$connection);

        $currencyId = $this->getCurrencyId($shop['currency']$connection);

        $countryId = $this->getCountryId($shop['country']$connection);

        $statement = $connection->prepare(
            'INSERT INTO sales_channel ( id, type_id, access_key, navigation_category_id, navigation_category_version_id, language_id, currency_id, payment_method_id, shipping_method_id, country_id, customer_group_id, created_at ) VALUES ( ?, UNHEX(?), ?, ?, UNHEX(?), ?, ?, ?, ?, ?, ?, ? )'
static::assertInstanceOf(OrderCustomerEntity::class$orderCustomer = $serialized['orderCustomer']);
        static::assertSame($orderCustomer->getFirstName()$order->getOrderCustomer()->getFirstName());
        static::assertSame($orderCustomer->getLastName()$order->getOrderCustomer()->getLastName());
        static::assertSame($orderCustomer->getEmail()$order->getOrderCustomer()->getEmail());

        static::assertInstanceOf(OrderAddressEntity::class$billingAddress = $serialized['billingAddress']);
        static::assertSame($billingAddress->getZipcode()$order->getBillingAddress()->getZipcode());
        static::assertSame($billingAddress->getStreet()$order->getBillingAddress()->getStreet());
        static::assertSame($billingAddress->getCity()$order->getBillingAddress()->getCity());
        static::assertSame($billingAddress->getCompany()$order->getBillingAddress()->getCompany());
        static::assertSame($billingAddress->getDepartment()$order->getBillingAddress()->getDepartment());
        static::assertSame($billingAddress->getCountryId()$order->getBillingAddress()->getCountryId());
        static::assertSame($billingAddress->getCountryStateId()$order->getBillingAddress()->getCountryStateId());

        static::assertNotNull($deliveries = $order->getDeliveries());
        static::assertNotNull($delivery = $deliveries->first());
        $shippingAddress = $delivery->getShippingOrderAddress();

        static::assertNotNull($shippingAddress);

        static::assertNotEmpty($serialized['deliveries']);
        static::assertNotEmpty($serialized['deliveries']['shippingOrderAddress']);
        static::assertSame($serialized['deliveries']['trackingCodes']implode('|', $delivery->getTrackingCodes()));
        

        $validationEvent = new BuildValidationEvent($definition$data$context);
        $this->eventDispatcher->dispatch($validationEvent$validationEvent->getName());
    }

    private function addVatIdsValidation(DataValidationDefinition $validation, CustomerAddressEntity $address): void
    {
        /** @var Constraint[] $constraints */
        $constraints = [
            new Type('array'),
            new CustomerVatIdentification(
                ['countryId' => $address->getCountryId()]
            ),
        ];
        if ($address->getCountry() && $address->getCountry()->getVatIdRequired()) {
            $constraints[] = new NotBlank();
        }

        $validation->add('vatIds', ...$constraints);
    }

    private function getBirthday(DataBag $data): ?\DateTimeInterface
    {
        
$address->setLastname($data['__address_lastname']);
        $address->setStreet($data['__address_street']);
        $address->setZipcode($data['__address_zipcode']);
        $address->setCity($data['__address_city']);
        $address->setCountryId((int) $data['__address_country_id']);
        $address->setStateId((int) $data['__address_state_id']);
        $address->setVatId($data['__address_ustid']);
        $address->setPhone($data['__address_phone']);
        $address->setAdditionalAddressLine1($data['__address_additional_address_line1']);
        $address->setAdditionalAddressLine2($data['__address_additional_address_line2']);

        if ($address->getCountryId()) {
            $address->setCountry(
                $this->countryHydrator->hydrateCountry($data)
            );
        }
        if ($address->getStateId()) {
            $address->setState(
                $this->countryHydrator->hydrateState($data)
            );
        }

        if ($data['__addressAttribute_id']) {
            
if (!$state instanceof CountryStateEntity) {
                throw SalesChannelException::countryStateNotFound($countryStateId);
            }

            /** @var CountryEntity $country */
            $country = $state->getCountry();

            return new ShippingLocation($country$state, null);
        }

        $countryId = $options[SalesChannelContextService::COUNTRY_ID] ?? $salesChannel->getCountryId();
        \assert(\is_string($countryId) && Uuid::isValid($countryId));

        $criteria = new Criteria([$countryId]);
        $criteria->setTitle('base-context-factory::country');

        $country = $this->countryRepository->search($criteria$context)->get($countryId);

        if (!$country instanceof CountryEntity) {
            throw SalesChannelException::countryNotFound($countryId);
        }

        
public function filterByShippingMethodId(string $id): SalesChannelCollection
    {
        return $this->filter(fn (SalesChannelEntity $salesChannel) => $salesChannel->getShippingMethodId() === $id);
    }

    /** * @return list<string> */
    public function getCountryIds(): array
    {
        return $this->fmap(fn (SalesChannelEntity $salesChannel) => $salesChannel->getCountryId());
    }

    public function filterByCountryId(string $id): SalesChannelCollection
    {
        return $this->filter(fn (SalesChannelEntity $salesChannel) => $salesChannel->getCountryId() === $id);
    }

    /** * @return list<string> */
    public function getTypeIds(): array
    {
public function filterByCustomerId(string $id): self
    {
        return $this->filter(fn (CustomerAddressEntity $customerAddress) => $customerAddress->getCustomerId() === $id);
    }

    /** * @return list<string> */
    public function getCountryIds(): array
    {
        return $this->fmap(fn (CustomerAddressEntity $customerAddress) => $customerAddress->getCountryId());
    }

    public function filterByCountryId(string $id): self
    {
        return $this->filter(fn (CustomerAddressEntity $customerAddress) => $customerAddress->getCountryId() === $id);
    }

    /** * @return list<string> */
    public function getCountryStateIds(): array
    {


        return true;
    }

    private function metPreconditions(TaxRuleEntity $taxRuleEntity, ShippingLocation $shippingLocation): bool
    {
        if ($this->getZipCode($shippingLocation) === null) {
            return false;
        }

        return $shippingLocation->getCountry()->getId() === $taxRuleEntity->getCountryId();
    }

    private function getZipCode(ShippingLocation $shippingLocation): ?string
    {
        return $shippingLocation->getAddress() !== null ? $shippingLocation->getAddress()->getZipcode() : null;
    }
}
Home | Imprint | This part of the site doesn't use cookies.