getOneByUser example

        if (!$this->session->offsetGet('checkoutBillingAddressId')
            || \strtolower(Shopware()->Front()->Request()->getControllerName()) !== 'checkout'
        ) {
            return $userData;
        }

        $addressRepository = Shopware()->Models()->getRepository(Address::class);
        $addressId = $this->session->offsetGet('checkoutBillingAddressId');

        try {
            $legacyAddress = $this->convertToLegacyAddressArray(
                $addressRepository->getOneByUser($addressId$this->session->offsetGet('sUserId'))
            );

            $userData['billingaddress'] = array_merge($userData['billingaddress']$legacyAddress);
            $userData = $this->completeUserCountryData($userData);
        } catch (Exception $ex) {
            // No need to overwrite default billing address             $this->session->offsetUnset('checkoutBillingAddressId');
        }

        return $userData;
    }

    
$this->View()->assign($this->getFormViewData($form));
    }

    /** * Shortcut action for more fluent urls */
    public function editAction()
    {
        $userId = $this->get('session')->get('sUserId');
        $addressId = $this->Request()->getParam('id');
        $address = $this->addressRepository->getOneByUser($addressId$userId);

        $form = $this->createForm(AddressFormType::class$address);
        $form->handleRequest($this->Request());

        if ($form->isSubmitted() && $form->isValid() && $this->isValidShippingAddress($address)) {
            $this->addressService->update($address);

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

            
if (!$this->Request()->getPost('setAsDefaultBillingAddress') && !$setBoth) {
            $billingId = false;
        }

        if (!$this->Request()->getPost('setAsDefaultShippingAddress') && !$setBoth) {
            $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(
                    
Home | Imprint | This part of the site doesn't use cookies.