private function processItems($data, Shipping $shipping, $locale, $userId)
    {
        $result = true;
        try {
            if ($this->checkDataSet($data, 'items', false)) {
                // items has to be an array
                if (!is_array($data['items'])) {
                    throw new MissingShippingAttributeException('items array');
                }

                $items = $data['items'];

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

                $delete = function ($item) use ($shipping){
                    $entity = $item->getEntity();
                    // remove from order
                    $shipping->removeShippingItem($entity);
                    // delete item
                    $this->em->remove($entity);
                };

                $update = function ($item, $matchedEntry) use ($locale){
                    $shippingItem = $this->saveShippingItem($matchedEntry, $item->getEntity());

                    return $shippingItem ? true : false;
                };

                $add = function ($itemData) use ($locale, $shipping){
                    $shippingItem = $this->saveShippingItem($itemData);
                    $shippingItem->setShipping($shipping->getEntity());
                    return $shipping->addShippingItem($shippingItem, null, $locale);
                };

                $result = $this->restHelper->processSubEntities($shipping->getItems(), $items, $get, $add, $update, $delete);
            }
        } catch (Exception $e) {
            throw new OrderException('Error while creating items: ' . $e->getMessage());
        }
        return $result;
    }
private function processItems($data, Shipping $shipping, $locale, $userId)
    {
        $result = true;
        try {
            if ($this->checkDataSet($data, 'items', false)) {
                // items has to be an array
                if (!is_array($data['items'])) {
                    throw new MissingShippingAttributeException('items array');
                }

                $items = $data['items'];

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

                $delete = function ($item) use ($shipping){
                    $entity = $item->getEntity();
                    // remove from order
                    $shipping->removeShippingItem($entity);
                    // delete item
                    $this->em->remove($entity);
                };

                $update = function ($item, $matchedEntry) use ($locale){
                    $shippingItem = $this->saveShippingItem($matchedEntry, $item->getEntity());

                    return $shippingItem ? true : false;
                };

                $add = function ($itemData) use ($locale, $shipping){
                    $shippingItem = $this->saveShippingItem($itemData);
                    $shippingItem->setShipping($shipping->getEntity());
                    return $shipping->addShippingItem($shippingItem, null, $locale);
                };

                $result = $this->restHelper->processSubEntities($shipping->getItems(), $items, $get, $add, $update, $delete);
            }
        } catch (Exception $e) {
            throw new OrderException('Error while creating items: ' . $e->getMessage());
        }
        return $result;
    }
private function processItems ( $ data , Shipping $ shipping , $ locale , $ userId ) { $ result = true ; try { if ( $ this -> checkDataSet ( $ data , 'items' , false ) ) { // items has to be an array if ( ! is_array ( $ data [ 'items' ] ) ) { throw new MissingShippingAttributeException ( 'items array' ) ; } $ items = $ data [ 'items' ] ; $ get = function ( $ item ) { return $ item -> getId ( ) ; } ; $ delete = function ( $ item ) use ( $ shipping ) { $ entity = $ item -> getEntity ( ) ; // remove from order $ shipping -> removeShippingItem ( $ entity ) ; // delete item $ this -> em -> remove ( $ entity ) ; } ; $ update = function ( $ item , $ matchedEntry ) use ( $ locale ) { $ shippingItem = $ this -> saveShippingItem ( $ matchedEntry , $ item -> getEntity ( ) ) ; return $ shippingItem ? true : false ; } ; $ add = function ( $ itemData ) use ( $ locale , $ shipping ) { $ shippingItem = $ this -> saveShippingItem ( $ itemData ) ; $ shippingItem -> setShipping ( $ shipping -> getEntity ( ) ) ; return $ shipping -> addShippingItem ( $ shippingItem , null , $ locale ) ; } ; $ result = $ this -> restHelper -> processSubEntities ( $ shipping -> getItems ( ) , $ items , $ get , $ add , $ update , $ delete ) ; } } catch ( Exception $ e ) { throw new OrderException ( 'Error while creating items: ' . $ e -> getMessage ( ) ) ; } return $ result ; }
process shipping items
@param $data
@param Shipping $shipping
@param $locale
@param $userId
@return bool
@throws OrderException
@throws Exception\MissingShippingAttributeException
process shipping items