setDefaultBillingAddress example

/** * {@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);
    }

    

        $rule = (new BillingStreetRule())->assign(['streetName' => 'example street']);

        $cart = new Cart('test');

        $context = $this->createMock(SalesChannelContext::class);

        $billing = new CustomerAddressEntity();
        $billing->setStreet('example street');

        $customer = new CustomerEntity();
        $customer->setDefaultBillingAddress($billing);

        $context
            ->method('getCustomer')
            ->willReturn($customer);

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }

    public function testCaseInsensitive(): void
    {
$address = new Address();
        $form = $this->createForm(AddressFormType::class$address);
        $form->handleRequest($this->Request());

        if ($form->isSubmitted() && $form->isValid()) {
            $userId = $this->get('session')->get('sUserId');
            $customer = $this->get(ModelManager::class)->find(Customer::class$userId);

            $this->addressService->create($address$customer);

            if (!empty($address->getAdditional()['setDefaultBillingAddress'])) {
                $this->addressService->setDefaultBillingAddress($address);
            }

            if ($this->isValidShippingAddress($address) && !empty($address->getAdditional()['setDefaultShippingAddress'])) {
                $this->addressService->setDefaultShippingAddress($address);
            }

            if ($this->Request()->getParam('sTarget')) {
                $action = $this->Request()->getParam('sTargetAction', 'index') ?: 'index';
                $this->redirect([
                    'controller' => $this->Request()->getParam('sTarget'),
                    'action' => $action,
                    
throw new CustomValidationException('A country is required.');
        }

        $params = $this->prepareAddressData($params);

        $address = new AddressModel();
        $address->fromArray($params);

        $this->addressService->create($address$customer);

        if (!empty($params['__options_set_default_billing_address'])) {
            $this->addressService->setDefaultBillingAddress($address);
        }

        if (!empty($params['__options_set_default_shipping_address'])) {
            $this->addressService->setDefaultShippingAddress($address);
        }

        return $address;
    }

    /** * @param int $id * * @throws NotFoundException * @throws ParameterMissingException * @throws ValidationException * * @return AddressModel */

        if (!Uuid::isValid($addressId)) {
            throw new InvalidUuidException($addressId);
        }

        $success = true;

        try {
            if ($type === self::ADDRESS_TYPE_SHIPPING) {
                $this->accountService->setDefaultShippingAddress($addressId$context$customer);
            } elseif ($type === self::ADDRESS_TYPE_BILLING) {
                $this->accountService->setDefaultBillingAddress($addressId$context$customer);
            } else {
                $success = false;
            }
        } catch (AddressNotFoundException) {
            $success = false;
        }

        return new RedirectResponse(
            $this->generateUrl('frontend.account.address.page', ['changedDefaultAddress' => $success])
        );
    }

    

        $customer = new CustomerEntity();
        $customer->setId('customer-id');
        $customer->setEmail('customer-email');
        $customer->setSalutationId('customer-salutation-id');
        $customer->setFirstName('customer-first-name');
        $customer->setLastName('customer-last-name');
        $customer->setCustomerNumber('customer-number');
        $customer->setGroupId('customer-group-id');

        if (!$withoutBillingAddress) {
            $customer->setDefaultBillingAddress($this->getCustomerAddress());
        }

        return $customer;
    }

    private function getCustomerAddress(): CustomerAddressEntity
    {
        $address = new CustomerAddressEntity();
        $address->setId('billing-address-id');
        $address->setSalutationId('billing-address-salutation-id');
        $address->setFirstName('billing-address-first-name');
        
$addresses = $this->addressRepository->search($criteria$context);

        /** @var CustomerAddressEntity $activeBillingAddress */
        $activeBillingAddress = $addresses->get($activeBillingAddressId);
        $customer->setActiveBillingAddress($activeBillingAddress);
        /** @var CustomerAddressEntity $activeShippingAddress */
        $activeShippingAddress = $addresses->get($activeShippingAddressId);
        $customer->setActiveShippingAddress($activeShippingAddress);
        /** @var CustomerAddressEntity $defaultBillingAddress */
        $defaultBillingAddress = $addresses->get($customer->getDefaultBillingAddressId());
        $customer->setDefaultBillingAddress($defaultBillingAddress);
        /** @var CustomerAddressEntity $defaultShippingAddress */
        $defaultShippingAddress = $addresses->get($customer->getDefaultShippingAddressId());
        $customer->setDefaultShippingAddress($defaultShippingAddress);

        return $customer;
    }

    /** * @return CashRoundingConfig[] * * @group not-deterministic * NEXT-21735 - This is covered randomly * * @codeCoverageIgnore */

        $rule = (new BillingZipCodeRule())->assign(['zipCodes' => ['ABC123']]);

        $cart = new Cart('test');

        $context = $this->createMock(SalesChannelContext::class);

        $billing = new CustomerAddressEntity();
        $billing->setZipcode('ABC123');

        $customer = new CustomerEntity();
        $customer->setDefaultBillingAddress($billing);

        $context
            ->method('getCustomer')
            ->willReturn($customer);

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }

    public function testEqualsWithMultipleCodes(): void
    {
$cart = new Cart('test');

        $context = $this->createMock(SalesChannelContext::class);

        $country = new CountryEntity();
        $country->setId('SWAG-AREA-COUNTRY-ID-1');

        $billing = new CustomerAddressEntity();
        $billing->setCountry($country);

        $customer = new CustomerEntity();
        $customer->setDefaultBillingAddress($billing);

        $context
            ->method('getCustomer')
            ->willReturn($customer);

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }

    public function testWithNotMatch(): void
    {
$cart = new Cart('test');

        $context = $this->createMock(SalesChannelContext::class);

        $billing = new CustomerAddressEntity();
        $billing->setId('SWAG-CUSTOMER-ADDRESS-ID-1');

        $shipping = new CustomerAddressEntity();
        $shipping->setId('SWAG-CUSTOMER-ADDRESS-ID-2');

        $customer = new CustomerEntity();
        $customer->setDefaultBillingAddress($billing);
        $customer->setDefaultShippingAddress($shipping);

        $context
            ->method('getCustomer')
            ->willReturn($customer);

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }

    
$model = $form->getData();

        if ($model->getId()) {
            $this->addressService->update($model);
        } else {
            $customer = $this->get(ModelManager::class)->find(Customer::class$data['user_id']);
            $this->addressService->create($model$customer);
        }

        if (!empty($data['setDefaultBillingAddress'])) {
            $this->addressService->setDefaultBillingAddress($model);
        }

        if (!empty($data['setDefaultShippingAddress'])) {
            $this->addressService->setDefaultShippingAddress($model);
        }

        $detail = $this->getDetail($model->getId());

        return ['success' => true, 'data' => $detail['data']];
    }

    
$billingAddress->setId('SWAG-ADDRESS-ID-1');
        $billingAddress->setSalutationId($this->getValidSalutationId());
        $billingAddress->setFirstName($faker->firstName);
        $billingAddress->setLastName($faker->lastName);
        $billingAddress->setStreet($faker->streetAddress);
        $billingAddress->setZipcode($faker->postcode);
        $billingAddress->setCity($faker->city);
        $billingAddress->setCountryId('SWAG-AREA-COUNTRY-ID-1');

        $customer = new CustomerEntity();
        $customer->setId('SWAG-CUSTOMER-ID-1');
        $customer->setDefaultBillingAddress($billingAddress);
        $customer->setEmail('test@example.com');
        $customer->setSalutationId($this->getValidSalutationId());
        $customer->setFirstName($faker->firstName);
        $customer->setLastName($faker->lastName);
        $customer->setCustomerNumber('Test');

        return $customer;
    }

    private function getSalesChannelContext(): MockObject&SalesChannelContext
    {
        
$shippingId = false;
        }

        if ($billingId && $billingId != $this->View()->getAssign('sUserData')['additional']['user']['default_billing_address_id']) {
            $address = $this->get(ModelManager::class)
                ->getRepository(Address::class)
                ->getOneByUser(
                    $billingId,
                    $this->View()->getAssign('sUserData')['additional']['user']['id']
                );

            $this->get(AddressServiceInterface::class)->setDefaultBillingAddress($address);
        }

        if ($shippingId && $shippingId != $this->View()->getAssign('sUserData')['additional']['user']['default_shipping_address_id']) {
            $address = $this->get(ModelManager::class)
                ->getRepository(Address::class)
                ->getOneByUser(
                    $shippingId,
                    $this->View()->getAssign('sUserData')['additional']['user']['id']
                );

            $this->get(AddressServiceInterface::class)->setDefaultShippingAddress($address);
        }
public function register(
        ShopStruct $shop,
        Customer $customer,
        Address $billing,
        ?Address $shipping = null
    ) {
        $this->modelManager->beginTransaction();
        try {
            $this->saveCustomer($shop$customer);

            $this->addressService->create($billing$customer);
            $this->addressService->setDefaultBillingAddress($billing);

            if ($shipping !== null) {
                $this->addressService->create($shipping$customer);
                $this->addressService->setDefaultShippingAddress($shipping);
            } else {
                $this->addressService->setDefaultShippingAddress($billing);
            }

            if (
                ($optinAttribute = $shop->getAttribute('sendOptinMail')) !== null
                && $optinAttribute->get('sendOptinMail') === true
                
Home | Imprint | This part of the site doesn't use cookies.