src/Sulu/Bundle/Sales/OrderBundle/Cart/CartManager.php
protected function createEmptyCart($user, $persist, $currencyCode = null)
    {
        $cart = new Order();
        $cart->setCreator($user);
        $cart->setChanger($user);
        $cart->setCreated(new \DateTime());
        $cart->setChanged(new \DateTime());
        $cart->setOrderDate(new \DateTime());

        // set currency - if not defined use default
        $currencyCode = $currencyCode ?: $this->defaultCurrency;
        $cart->setCurrencyCode($currencyCode);

        // get address from contact and account
        $contact = $user->getContact();
        $account = $contact->getMainAccount();
        $cart->setCustomerContact($contact);
        $cart->setCustomerAccount($account);

        /** Account $account */
        if ($account && $account->getResponsiblePerson()) {
            $cart->setResponsibleContact($account->getResponsiblePerson());
        }

        $addressSource = $contact;
        if ($account) {
            $addressSource = $account;
        }
        // get billing address
        $invoiceOrderAddress = null;
        $invoiceAddress = $this->accountManager->getBillingAddress($addressSource, true);
        if ($invoiceAddress) {
            // convert to order-address
            $invoiceOrderAddress = $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                $invoiceAddress,
                $contact,
                $account
            );
            $cart->setInvoiceAddress($invoiceOrderAddress);
        }
        $deliveryOrderAddress = null;
        $deliveryAddress = $this->accountManager->getDeliveryAddress($addressSource, true);
        if ($deliveryAddress) {
            // convert to order-address
            $deliveryOrderAddress = $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                $deliveryAddress,
                $contact,
                $account
            );
            $cart->setDeliveryAddress($deliveryOrderAddress);
        }

        // TODO: anonymous order
        // set order type
        if ($user) {
            $name = $user->getContact()->getFullName();
            $cart->setType($this->orderManager->getOrderTypeEntityById(OrderType::SHOP));
        } else {
            $name = 'Anonymous';
            $cart->setType($this->orderManager->getOrderTypeEntityById(OrderType::ANONYMOUS));
        }
        $cart->setCustomerName($name);

        $this->orderManager->convertStatus($cart, OrderStatus::STATUS_IN_CART, false, $persist);

        if ($persist) {
            $this->em->persist($cart);
            if ($invoiceOrderAddress) {
                $this->em->persist($invoiceOrderAddress);
            }
            if ($deliveryOrderAddress) {
                $this->em->persist($deliveryOrderAddress);
            }
        }

        return $cart;
    }
protected function createEmptyCart($user, $persist, $currencyCode = null)
    {
        $cart = new Order();
        $cart->setCreator($user);
        $cart->setChanger($user);
        $cart->setCreated(new \DateTime());
        $cart->setChanged(new \DateTime());
        $cart->setOrderDate(new \DateTime());

        // set currency - if not defined use default
        $currencyCode = $currencyCode ?: $this->defaultCurrency;
        $cart->setCurrencyCode($currencyCode);

        // get address from contact and account
        $contact = $user->getContact();
        $account = $contact->getMainAccount();
        $cart->setCustomerContact($contact);
        $cart->setCustomerAccount($account);

        /** Account $account */
        if ($account && $account->getResponsiblePerson()) {
            $cart->setResponsibleContact($account->getResponsiblePerson());
        }

        $addressSource = $contact;
        if ($account) {
            $addressSource = $account;
        }
        // get billing address
        $invoiceOrderAddress = null;
        $invoiceAddress = $this->accountManager->getBillingAddress($addressSource, true);
        if ($invoiceAddress) {
            // convert to order-address
            $invoiceOrderAddress = $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                $invoiceAddress,
                $contact,
                $account
            );
            $cart->setInvoiceAddress($invoiceOrderAddress);
        }
        $deliveryOrderAddress = null;
        $deliveryAddress = $this->accountManager->getDeliveryAddress($addressSource, true);
        if ($deliveryAddress) {
            // convert to order-address
            $deliveryOrderAddress = $this->orderAddressManager->getAndSetOrderAddressByContactAddress(
                $deliveryAddress,
                $contact,
                $account
            );
            $cart->setDeliveryAddress($deliveryOrderAddress);
        }

        // TODO: anonymous order
        // set order type
        if ($user) {
            $name = $user->getContact()->getFullName();
            $cart->setType($this->orderManager->getOrderTypeEntityById(OrderType::SHOP));
        } else {
            $name = 'Anonymous';
            $cart->setType($this->orderManager->getOrderTypeEntityById(OrderType::ANONYMOUS));
        }
        $cart->setCustomerName($name);

        $this->orderManager->convertStatus($cart, OrderStatus::STATUS_IN_CART, false, $persist);

        if ($persist) {
            $this->em->persist($cart);
            if ($invoiceOrderAddress) {
                $this->em->persist($invoiceOrderAddress);
            }
            if ($deliveryOrderAddress) {
                $this->em->persist($deliveryOrderAddress);
            }
        }

        return $cart;
    }
protected function createEmptyCart ( $ user , $ persist , $ currencyCode = null ) { $ cart = new Order ( ) ; $ cart -> setCreator ( $ user ) ; $ cart -> setChanger ( $ user ) ; $ cart -> setCreated ( new \ DateTime ( ) ) ; $ cart -> setChanged ( new \ DateTime ( ) ) ; $ cart -> setOrderDate ( new \ DateTime ( ) ) ; // set currency - if not defined use default $ currencyCode = $ currencyCode ? : $ this -> defaultCurrency ; $ cart -> setCurrencyCode ( $ currencyCode ) ; // get address from contact and account $ contact = $ user -> getContact ( ) ; $ account = $ contact -> getMainAccount ( ) ; $ cart -> setCustomerContact ( $ contact ) ; $ cart -> setCustomerAccount ( $ account ) ; /** Account $account */ if ( $ account && $ account -> getResponsiblePerson ( ) ) { $ cart -> setResponsibleContact ( $ account -> getResponsiblePerson ( ) ) ; } $ addressSource = $ contact ; if ( $ account ) { $ addressSource = $ account ; } // get billing address $ invoiceOrderAddress = null ; $ invoiceAddress = $ this -> accountManager -> getBillingAddress ( $ addressSource , true ) ; if ( $ invoiceAddress ) { // convert to order-address $ invoiceOrderAddress = $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ invoiceAddress , $ contact , $ account ) ; $ cart -> setInvoiceAddress ( $ invoiceOrderAddress ) ; } $ deliveryOrderAddress = null ; $ deliveryAddress = $ this -> accountManager -> getDeliveryAddress ( $ addressSource , true ) ; if ( $ deliveryAddress ) { // convert to order-address $ deliveryOrderAddress = $ this -> orderAddressManager -> getAndSetOrderAddressByContactAddress ( $ deliveryAddress , $ contact , $ account ) ; $ cart -> setDeliveryAddress ( $ deliveryOrderAddress ) ; } // TODO: anonymous order // set order type if ( $ user ) { $ name = $ user -> getContact ( ) -> getFullName ( ) ; $ cart -> setType ( $ this -> orderManager -> getOrderTypeEntityById ( OrderType :: SHOP ) ) ; } else { $ name = 'Anonymous' ; $ cart -> setType ( $ this -> orderManager -> getOrderTypeEntityById ( OrderType :: ANONYMOUS ) ) ; } $ cart -> setCustomerName ( $ name ) ; $ this -> orderManager -> convertStatus ( $ cart , OrderStatus :: STATUS_IN_CART , false , $ persist ) ; if ( $ persist ) { $ this -> em -> persist ( $ cart ) ; if ( $ invoiceOrderAddress ) { $ this -> em -> persist ( $ invoiceOrderAddress ) ; } if ( $ deliveryOrderAddress ) { $ this -> em -> persist ( $ deliveryOrderAddress ) ; } } return $ cart ; }
Function creates an empty cart
this means an order with status 'in_cart' is created and all necessary data is set

@param UserInterface $user
@param bool $persist
@param null|string $currencyCode

@return Order
@throws \Sulu\Component\Rest\Exception\EntityNotFoundException
Function creates an empty cart this means an order with status in_cart is created and all necessary data is set