src/Sulu/Bundle/Sales/OrderBundle/Order/OrderManager.php
private function processItems($data, Order $order, $locale, $userId = null)
    {
        $result = true;
        try {
            if ($this->checkIfSet('items', $data)) {
                // items has to be an array
                if (!is_array($data['items'])) {
                    throw new MissingOrderAttributeException('items array');
                }

                $items = $data['items'];

                $get = function ($item) {
                    return $item->getId();
                };

                $delete = function ($item) use ($order) {
                    $this->removeItem($item->getEntity(), $order->getEntity());
                };

                $update = function ($item, $matchedEntry) use ($locale, $userId, $order) {
                    $item = $item->getEntity();
                    $itemEntity = $this->updateItem($item, $matchedEntry, $locale, $userId);

                    return $itemEntity ? true : false;
                };

                $add = function ($itemData) use ($locale, $userId, $order) {
                    return $this->addItem($itemData, $locale, $userId, $order);
                };

                $result = $this->processSubEntities(
                    $order->getItems(),
                    $items,
                    $get,
                    $add,
                    $update,
                    $delete
                );
            }
        } catch (\Exception $e) {
            throw new OrderException('Error while creating items: ' . $e->getMessage());
        }

        return $result;
    }
private function processItems($data, Order $order, $locale, $userId = null)
    {
        $result = true;
        try {
            if ($this->checkIfSet('items', $data)) {
                // items has to be an array
                if (!is_array($data['items'])) {
                    throw new MissingOrderAttributeException('items array');
                }

                $items = $data['items'];

                $get = function ($item) {
                    return $item->getId();
                };

                $delete = function ($item) use ($order) {
                    $this->removeItem($item->getEntity(), $order->getEntity());
                };

                $update = function ($item, $matchedEntry) use ($locale, $userId, $order) {
                    $item = $item->getEntity();
                    $itemEntity = $this->updateItem($item, $matchedEntry, $locale, $userId);

                    return $itemEntity ? true : false;
                };

                $add = function ($itemData) use ($locale, $userId, $order) {
                    return $this->addItem($itemData, $locale, $userId, $order);
                };

                $result = $this->processSubEntities(
                    $order->getItems(),
                    $items,
                    $get,
                    $add,
                    $update,
                    $delete
                );
            }
        } catch (\Exception $e) {
            throw new OrderException('Error while creating items: ' . $e->getMessage());
        }

        return $result;
    }
private function processItems ( $ data , Order $ order , $ locale , $ userId = null ) { $ result = true ; try { if ( $ this -> checkIfSet ( 'items' , $ data ) ) { // items has to be an array if ( ! is_array ( $ data [ 'items' ] ) ) { throw new MissingOrderAttributeException ( 'items array' ) ; } $ items = $ data [ 'items' ] ; $ get = function ( $ item ) { return $ item -> getId ( ) ; } ; $ delete = function ( $ item ) use ( $ order ) { $ this -> removeItem ( $ item -> getEntity ( ) , $ order -> getEntity ( ) ) ; } ; $ update = function ( $ item , $ matchedEntry ) use ( $ locale , $ userId , $ order ) { $ item = $ item -> getEntity ( ) ; $ itemEntity = $ this -> updateItem ( $ item , $ matchedEntry , $ locale , $ userId ) ; return $ itemEntity ? true : false ; } ; $ add = function ( $ itemData ) use ( $ locale , $ userId , $ order ) { return $ this -> addItem ( $ itemData , $ locale , $ userId , $ order ) ; } ; $ result = $ this -> processSubEntities ( $ order -> getItems ( ) , $ items , $ get , $ add , $ update , $ delete ) ; } } catch ( \ Exception $ e ) { throw new OrderException ( 'Error while creating items: ' . $ e -> getMessage ( ) ) ; } return $ result ; }
Processes items defined in an order and creates item entities

@param array $data
@param Order $order
@param string $locale
@param int $userId

@throws Exception\OrderException

@return bool
Processes items defined in an order and creates item entities