getDefaultShippingAddress example

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);

        static::assertImportExportSucceeded($progress$this->getInvalidLogContent($progress->getInvalidRecordsLogId()));

        $filesystem = $this->getContainer()->get('shopware.filesystem.private');
        $logfile = $this->getLogEntity($progress->getLogId())->getFile();
        static::assertInstanceOf(ImportExportFileEntity::class$logfile);
        $csv = $filesystem->read($logfile->getPath());

        
$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,
            ]);

            return;
        }
$shippingId = $this->db->lastInsertId();

        $shippingAddressId = null;

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

        if ($shippingAddressId === null) {
            /** @var Customer $customer */
            $customer = $this->modelManager->getRepository(Customer::class)->find($address['userID']);
            $defaultShippingAddress = $customer->getDefaultShippingAddress();
            if (!$defaultShippingAddress instanceof Address) {
                throw new RuntimeException('Customer does not have a default billing address');
            }
            $shippingAddressId = $defaultShippingAddress->getId();
        }

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

        $this->attributePersister->persist($attributes, 's_order_shippingaddress_attributes', $shippingId);

        return $result;
    }
return;
            }

            $this->redirect(['action' => 'index', 'success' => 'update']);

            return;
        }

        $this->View()->assign('countryNotAvailableForShipping', !$this->isValidShippingAddress($address));
        $this->View()->assign($this->getFormViewData($form));
        $this->View()->assign('isShipping', $address->getId() === $address->getCustomer()->getDefaultShippingAddress()->getId());
    }

    /** * Delete confirm action */
    public function deleteAction()
    {
        $userId = $this->get('session')->get('sUserId');
        $addressId = $this->Request()->getParam('id');

        $address = $this->addressRepository->getOneByUser($addressId$userId);

        
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);
    }

    /** * {@inheritdoc} */
$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);
        $addressService->update($defaultShippingAddress);

        $this->flush();

        


    private function hydrateFromCustomer(RequestDataBag $dataBag, CustomerEntity $customer): RequestDataBag
    {
        $dataBag->set('email', $customer->getEmail());
        $dataBag->set('salutationId', $customer->getSalutationId());
        $dataBag->set('title', $customer->getTitle());
        $dataBag->set('firstName', $customer->getFirstName());
        $dataBag->set('lastName', $customer->getLastName());
        $dataBag->set(
            'zipCode',
            $customer->getDefaultShippingAddress() ? $customer->getDefaultShippingAddress()->getZipCode() : ''
        );
        $dataBag->set(
            'city',
            $customer->getDefaultShippingAddress() ? $customer->getDefaultShippingAddress()->getCity() : ''
        );
        $dataBag->set(
            'street',
            $customer->getDefaultShippingAddress() ? $customer->getDefaultShippingAddress()->getStreet() : ''
        );

        return $dataBag;
    }
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> */
    public function getListVatIds(): array
    {
        return $this->fmap(fn (CustomerEntity $customer) => $customer->getVatIds());
    }

    

    private function getShippingAddressData(ModelManager $entityManager, Customer $customer): ?array
    {
        $shippingAddress = null;

        if ($this->session->offsetExists('checkoutShippingAddressId')) {
            $shippingId = (int) $this->session->offsetGet('checkoutShippingAddressId');
            $shippingAddress = $entityManager->find(Address::class$shippingId);
        }

        if ($shippingAddress === null) {
            $shippingAddress = $customer->getDefaultShippingAddress();
        }

        if (!$shippingAddress instanceof Address) {
            return null;
        }

        $shippingAddressArray = $this->convertToLegacyAddressArray($shippingAddress);

        $shippingAddressArray['attributes'] = $this->attributeLoader->load(
            's_user_addresses_attributes',
            $shippingAddress->getid()
        );
Home | Imprint | This part of the site doesn't use cookies.