getDefaultBillingAddress example

$repository = $this->getModelManager()->getRepository(Customer::class);
        $customer = $repository->find($mapCustomerAccountValue);

        if (!$customer) {
            return;
        }

        echo sprintf(
            '%s %s %s %s|%d',
            $customer->getNumber(),
            $customer->getFirstname() . ' ' . $customer->getLastname(),
            $customer->getDefaultBillingAddress() ? $customer->getDefaultBillingAddress()->getCompany() : '',
            $customer->getEmail(),
            $customer->getId()
        );
    }

    /** * Deletes a Partner from the database * * @return void */
    public function deletePartnerAction()
    {

        $userId = (int) $userId;
        $order = Shopware()->Models()->createQueryBuilder()
            ->select(['orders.invoiceAmount', 'orders.number'])
            ->from(Order::class, 'orders')
            ->where('orders.id = ?1')
            ->setParameter(1, $orderId)
            ->getQuery()
            ->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);

        $addressData = Shopware()->Models()->getRepository(Customer::class)
            ->find($userId)->getDefaultBillingAddress();
        $paymentData = $this->getCurrentPaymentDataAsArray($userId);
        if (!\is_array($paymentData)) {
            $paymentData = [
                'sSepaUseBillingData' => null,
                'sSepaBankName' => null,
                'sSepaBic' => null,
                'sSepaIban' => null,
            ];
        }

        $date = new DateTime();
        
$params = $this->prepareCustomerData($params$customer);
        $params = $this->prepareAssociatedData($params$customer);
        $params = $this->applyAddressData($params$customer);

        $customer->fromArray($params);

        $customerValidator = $this->getContainer()->get(CustomerValidatorInterface::class);
        $addressValidator = $this->getContainer()->get(AddressValidatorInterface::class);
        $addressService = $this->getContainer()->get(AddressServiceInterface::class);

        $customerValidator->validate($customer);
        $defaultBillingAddress = $customer->getDefaultBillingAddress();
        if ($defaultBillingAddress === null) {
            throw new CustomValidationException('Default billing address not set');
        }
        $defaultShippingAddress = $customer->getDefaultShippingAddress();
        if ($defaultShippingAddress === null) {
            throw new CustomValidationException('Default shipping address not set');
        }
        $addressValidator->validate($defaultBillingAddress);
        $addressValidator->validate($defaultShippingAddress);

        $addressService->update($defaultBillingAddress);
        

    private function getUserBillingData(int $userId, array $userData): array
    {
        $entityManager = Shopware()->Container()->get(ModelManager::class);
        $customer = $entityManager->find(Customer::class$userId);
        if (!$customer) {
            throw new Exception(sprintf('Customer with id %s not found', $userId));
        }
        $billing = $this->convertToLegacyAddressArray($customer->getDefaultBillingAddress());
        $billing['attributes'] = $this->attributeLoader->load('s_user_addresses_attributes', $billing['id']);
        $userData['billingaddress'] = $billing;

        return $userData;
    }

    /** * Helper method for sAdmin::sNewsletterSubscription * Subscribes the provided email address to the newsletter group * * @return array<string, mixed> */
public function createPaymentInstance($orderId$userId$paymentId)
    {
        $orderAmount = Shopware()->Models()->createQueryBuilder()
            ->select('orders.invoiceAmount')
            ->from(Order::class, 'orders')
            ->where('orders.id = ?1')
            ->setParameter(1, $orderId)
            ->getQuery()
            ->getSingleScalarResult();

        $addressData = Shopware()->Models()->getRepository(Customer::class)
            ->find($userId)->getDefaultBillingAddress();

        $date = new DateTime();
        $data = [
            'payment_mean_id' => $paymentId,
            'order_id' => $orderId,
            'user_id' => $userId,
            'firstname' => $addressData->getFirstname(),
            'lastname' => $addressData->getLastname(),
            'address' => $addressData->getStreet(),
            'zipcode' => $addressData->getZipcode(),
            'city' => $addressData->getCity(),
            
#[Route(path: '/store-api/account/change-profile', name: 'store-api.account.change-profile', methods: ['POST'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true])]     public function change(RequestDataBag $data, SalesChannelContext $context, CustomerEntity $customer): SuccessResponse
    {
        $validation = $this->customerProfileValidationFactory->update($context);

        if ($data->has('accountType') && empty($data->get('accountType'))) {
            $data->remove('accountType');
        }

        if ($data->get('accountType') === CustomerEntity::ACCOUNT_TYPE_BUSINESS) {
            $validation->add('company', new NotBlank());
            $billingAddress = $customer->getDefaultBillingAddress();
            if ($billingAddress) {
                $this->addVatIdsValidation($validation$billingAddress);
            }
        } else {
            $data->set('company', '');
            $data->set('vatIds', null);
        }

        /** @var ?RequestDataBag $vatIds */
        $vatIds = $data->get('vatIds');
        if ($vatIds) {
            
public function createPaymentInstance($orderId$userId$paymentId)
    {
        $orderAmount = Shopware()->Models()->createQueryBuilder()
            ->select('orders.invoiceAmount')
            ->from(Order::class, 'orders')
            ->where('orders.id = ?1')
            ->setParameter(1, $orderId)
            ->getQuery()
            ->getSingleScalarResult();

        $addressData = Shopware()->Models()->getRepository(Customer::class)
            ->find($userId)->getDefaultBillingAddress();

        $debitData = $this->getCurrentPaymentDataAsArray($userId);
        if (!\is_array($debitData)) {
            $debitData = [];
        }

        $date = new DateTime();
        $data = [
            'payment_mean_id' => $paymentId,
            'order_id' => $orderId,
            'user_id' => $userId,
            
$data['register']['personal']['password'],
            $data['register']['personal']['passwordConfirmation'],
            $data['register']['billing']['password'],
            $data['register']['billing']['passwordConfirmation']
        );

        if ($doubleOptinRegister) {
            $eventManager->notify(
                'Shopware_Modules_Admin_SaveRegister_DoubleOptIn_Waiting',
                [
                    'id' => $customer->getId(),
                    'billingID' => $customer->getDefaultBillingAddress()->getId(),
                    'shippingID' => $customer->getDefaultShippingAddress()->getId(),
                ]
            );

            $session->offsetSet('isAccountless', $accountMode === Customer::ACCOUNT_MODE_FAST_LOGIN);

            $this->redirectCustomer([
                'location' => 'register',
                'optinsuccess' => true,
            ]);

            
/** * {@inheritdoc} */
    public function create(Address $address, Customer $customer)
    {
        $address->setCustomer($customer);

        $this->validator->validate($address);
        $this->modelManager->persist($address);

        if (!$customer->getDefaultBillingAddress()) {
            $customer->setDefaultBillingAddress($address);
        }

        if (!$customer->getDefaultShippingAddress()) {
            $customer->setDefaultShippingAddress($address);
        }

        $this->modelManager->flush([$address$customer]);

        $this->modelManager->refresh($address);
        $this->modelManager->refresh($customer);
    }
$result = $this->db->executeUpdate($sql$array);

        $billingID = $this->db->lastInsertId();

        $billingAddressId = null;

        if ($this->session !== null) {
            $billingAddressId = $this->session->get('checkoutBillingAddressId');
        }

        if ($billingAddressId === null) {
            $defaultBillingAddress = $customer->getDefaultBillingAddress();
            if (!$defaultBillingAddress instanceof Address) {
                throw new RuntimeException('Customer does not have a default billing address');
            }
            $billingAddressId = $defaultBillingAddress->getId();
        }

        $attributes = $this->attributeLoader->load('s_user_addresses_attributes', $billingAddressId);

        if (!\is_array($attributes)) {
            $attributes = [];
        }

        
$repository = $this->getContainer()->get('customer.repository');
        /** @var CustomerCollection $result */
        $result = $repository->search($criteria, Context::createDefaultContext())->getEntities();

        static::assertCount(3, $result);

        static::assertTrue($result->has('0a1dea4bd2de43929ac210fd17339dde'));
        $customerWithMultipleAddresses = $result->get('0a1dea4bd2de43929ac210fd17339dde');

        static::assertInstanceOf(CustomerAddressCollection::class$customerWithMultipleAddresses->getAddresses());
        static::assertCount(4, $customerWithMultipleAddresses->getAddresses());
        static::assertInstanceOf(CustomerAddressEntity::class$customerWithMultipleAddresses->getDefaultBillingAddress());
        static::assertSame('shopware AG', $customerWithMultipleAddresses->getDefaultBillingAddress()->getCompany());

        static::assertTrue($result->has('f3bb913bc8cc48479c3834a75e82920b'));
        $customerWithUpdatedAddresses = $result->get('f3bb913bc8cc48479c3834a75e82920b');

        static::assertInstanceOf(CustomerAddressCollection::class$customerWithUpdatedAddresses->getAddresses());
        static::assertCount(2, $customerWithUpdatedAddresses->getAddresses());
        static::assertInstanceOf(CustomerAddressEntity::class$customerWithUpdatedAddresses->getDefaultShippingAddress());
        static::assertSame('shopware AG', $customerWithUpdatedAddresses->getDefaultShippingAddress()->getCompany());

        $progress = $this->export($context, CustomerDefinition::ENTITY_NAME);

        
'sMAIL' => $customer->getEmail(),
            'firstname' => $customer->getFirstname(),
            'lastname' => $customer->getLastname(),
            'salutation' => $customer->getSalutation(),
            'customer_type' => $customer->getCustomerType(),
            'additional' => [
                'customer_type' => $customer->getCustomerType(),
            ],
            'accountmode' => $customer->getAccountMode(),
        ];

        $address = $customer->getDefaultBillingAddress();
        if ($address) {
            $context = array_merge($context[
                'street' => $address->getStreet(),
                'zipcode' => $address->getZipcode(),
                'city' => $address->getCity(),
                'country' => $address->getCountry() ? $address->getCountry()->getId() : null,
                'state' => $address->getState() ? $address->getState()->getId() : null,
            ]);
        }

        $context = $container->get('events')->filter(
            
public function getLastPaymentMethods(): PaymentMethodCollection
    {
        return new PaymentMethodCollection(
            $this->fmap(fn (CustomerEntity $customer) => $customer->getLastPaymentMethod())
        );
    }

    public function getDefaultBillingAddress(): CustomerAddressCollection
    {
        return new CustomerAddressCollection(
            $this->fmap(fn (CustomerEntity $customer) => $customer->getDefaultBillingAddress())
        );
    }

    public function getDefaultShippingAddress(): CustomerAddressCollection
    {
        return new CustomerAddressCollection(
            $this->fmap(fn (CustomerEntity $customer) => $customer->getDefaultShippingAddress())
        );
    }

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