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