Example #1
0
 /**
  * creates a ShippingItem Entity by a given (shipping-)data array
  * @param $data
  * @return ShippingItemEntity
  * @throws Exception\ShippingDependencyNotFoundException
  * @throws Exception\MissingShippingAttributeException
  */
 private function createShippingItemEntity($data)
 {
     // check if necessary item data is set
     if (array_key_exists('item', $data) && array_key_exists('id', $data['item'])) {
         $itemId = $data['item']['id'];
         $item = $this->itemManager->findEntityById($itemId);
         if (!$item) {
             throw new ShippingDependencyNotFoundException('SuluSalesCoreBundle:Items', $itemId);
         }
         $shippingItem = new ShippingItemEntity();
         $shippingItem->setItem($item);
         $this->em->persist($shippingItem);
     } else {
         throw new MissingShippingAttributeException('ShippingItems.item.id');
     }
     return $shippingItem;
 }
Example #2
0
 /**
  * Get order item by id and checks if item belongs to the order.
  *
  * @param int $itemId
  * @param OrderInterface $order
  * @param bool $hasMultiple Returns if multiple orders exist for the item
  *
  * @throws EntityNotFoundException
  * @throws ItemNotFoundException
  * @throws OrderException
  *
  * @return null|Item
  */
 public function getOrderItemById($itemId, OrderInterface $order, &$hasMultiple = false)
 {
     $item = $this->itemManager->findEntityById($itemId);
     if (!$item) {
         throw new ItemNotFoundException($itemId);
     }
     $match = false;
     $orders = $this->findOrderEntityForItemWithId($itemId, true);
     if ($orders) {
         if (count($orders) > 1) {
             $hasMultiple = true;
         }
         foreach ($orders as $itemOrders) {
             if ($order === $itemOrders) {
                 $match = true;
             }
         }
     }
     if (!$match) {
         throw new OrderException('User not owner of order');
     }
     return $item;
 }