protected function validateOrCreateAddresses($cart)
    {
        if ($cart instanceof ApiOrderInterface) {
            $cart = $cart->getEntity();
        }
        if (!$cart->getDeliveryAddress() || !$cart->getInvoiceAddress()) {
            $addresses = $cart->getCustomerAccount()->getAccountAddresses();
            if ($addresses->isEmpty()) {
                throw new Exception('customer has no addresses');
            }
            $mainAddress = $cart->getCustomerAccount()->getMainAddress();
            if (!$mainAddress) {
                throw new Exception('customer has no main-address');
            }

            if (!$cart->getDeliveryAddress()) {
                $newAddress = $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                    $mainAddress,
                    $cart->getCustomerContact(),
                    $cart->getCustomerAccount()
                );
                $cart->setDeliveryAddress($newAddress);
                $this->em->persist($newAddress);
            }
            if (!$cart->getInvoiceAddress()) {
                $newAddress = $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                    $mainAddress,
                    $cart->getCustomerContact(),
                    $cart->getCustomerAccount()
                );
                $cart->setInvoiceAddress($newAddress);
                $this->em->persist($newAddress);
            }
        }
    }
protected function validateOrCreateAddresses($cart)
    {
        if ($cart instanceof ApiOrderInterface) {
            $cart = $cart->getEntity();
        }
        if (!$cart->getDeliveryAddress() || !$cart->getInvoiceAddress()) {
            $addresses = $cart->getCustomerAccount()->getAccountAddresses();
            if ($addresses->isEmpty()) {
                throw new Exception('customer has no addresses');
            }
            $mainAddress = $cart->getCustomerAccount()->getMainAddress();
            if (!$mainAddress) {
                throw new Exception('customer has no main-address');
            }

            if (!$cart->getDeliveryAddress()) {
                $newAddress = $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                    $mainAddress,
                    $cart->getCustomerContact(),
                    $cart->getCustomerAccount()
                );
                $cart->setDeliveryAddress($newAddress);
                $this->em->persist($newAddress);
            }
            if (!$cart->getInvoiceAddress()) {
                $newAddress = $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                    $mainAddress,
                    $cart->getCustomerContact(),
                    $cart->getCustomerAccount()
                );
                $cart->setInvoiceAddress($newAddress);
                $this->em->persist($newAddress);
            }
        }
    }
protected function validateOrCreateAddresses ( $ cart ) { if ( $ cart instanceof ApiOrderInterface ) { $ cart = $ cart -> getEntity ( ) ; } if ( ! $ cart -> getDeliveryAddress ( ) || ! $ cart -> getInvoiceAddress ( ) ) { $ addresses = $ cart -> getCustomerAccount ( ) -> getAccountAddresses ( ) ; if ( $ addresses -> isEmpty ( ) ) { throw new Exception ( 'customer has no addresses' ) ; } $ mainAddress = $ cart -> getCustomerAccount ( ) -> getMainAddress ( ) ; if ( ! $ mainAddress ) { throw new Exception ( 'customer has no main-address' ) ; } if ( ! $ cart -> getDeliveryAddress ( ) ) { $ newAddress = $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ mainAddress , $ cart -> getCustomerContact ( ) , $ cart -> getCustomerAccount ( ) ) ; $ cart -> setDeliveryAddress ( $ newAddress ) ; $ this -> em -> persist ( $ newAddress ) ; } if ( ! $ cart -> getInvoiceAddress ( ) ) { $ newAddress = $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ mainAddress , $ cart -> getCustomerContact ( ) , $ cart -> getCustomerAccount ( ) ) ; $ cart -> setInvoiceAddress ( $ newAddress ) ; $ this -> em -> persist ( $ newAddress ) ; } } }
Checks if addresses have been set and sets new ones

@param ApiOrderInterface $cart
Checks if addresses have been set and sets new ones