/** * @param array $data * @param Order $order * @param bool $patch * * @throws MissingOrderAttributeException * @throws OrderDependencyNotFoundException * * @return null|object */ private function setTermsOfDelivery($data, Order $order, $patch = false) { $terms = null; // Terms of delivery. $termsOfDeliveryData = $this->getProperty($data, 'termsOfDelivery'); $termsOfDeliveryContentData = $this->getProperty($data, 'termsOfDeliveryContent'); if ($termsOfDeliveryData) { if (!array_key_exists('id', $termsOfDeliveryData)) { throw new MissingOrderAttributeException('termsOfDelivery.id'); } // TODO: inject repository class $terms = $this->em->getRepository(static::$termsOfDeliveryEntityName)->find($termsOfDeliveryData['id']); if (!$terms) { throw new OrderDependencyNotFoundException(static::$termsOfDeliveryEntityName, $termsOfDeliveryData['id']); } $order->setTermsOfDelivery($terms); $order->setTermsOfDeliveryContent($terms->getTerms()); } elseif (!$patch) { $order->setTermsOfDelivery(null); $order->setTermsOfDeliveryContent(null); } // Set content data. if ($termsOfDeliveryContentData) { $order->setTermsOfDeliveryContent($termsOfDeliveryContentData); } return $terms; }