/** * Sets OrderType on an order. * * @param array $data * @param ApiOrderInterface $order * @param bool $patch * * @throws EntityNotFoundException * @throws OrderException */ private function setOrderType(array $data, ApiOrderInterface $order, $patch = false) { // Get OrderType. $type = $this->getProperty($data, 'type', $order->getType()); // Set order type. if (isset($data['type'])) { if (is_array($type) && isset($type['id'])) { // If provided as array. $typeId = $type['id']; } elseif (is_numeric($type)) { // If is numeric. $typeId = $type; } else { throw new OrderException('No typeid given'); } } elseif (!$patch) { // Default type is manual. $typeId = OrderType::MANUAL; } else { // Keep current type. return; } // Get entity. $orderType = $this->getOrderTypeEntityById($typeId); if (!$orderType) { throw new EntityNotFoundException(static::$orderTypeEntityName, $typeId); } // Set order type. $order->setType($orderType); }