Beispiel #1
0
 /**
  * @param array $data
  * @param Order $order
  * @param bool $patch
  *
  * @throws MissingOrderAttributeException
  * @throws OrderDependencyNotFoundException
  *
  * @return null|object
  */
 private function setTermsOfPayment($data, Order $order, $patch = false)
 {
     $terms = null;
     // Terms of delivery.
     $termsOfPaymentData = $this->getProperty($data, 'termsOfPayment');
     $termsOfPaymentContentData = $this->getProperty($data, 'termsOfPaymentContent');
     if ($termsOfPaymentData) {
         if (!array_key_exists('id', $termsOfPaymentData)) {
             throw new MissingOrderAttributeException('termsOfPayment.id');
         }
         // TODO: inject repository class
         $terms = $this->em->getRepository(static::$termsOfPaymentEntityName)->find($termsOfPaymentData['id']);
         if (!$terms) {
             throw new OrderDependencyNotFoundException(static::$termsOfPaymentEntityName, $termsOfPaymentData['id']);
         }
         $order->setTermsOfPayment($terms);
         $order->setTermsOfPaymentContent($terms->getTerms());
     } elseif (!$patch) {
         $order->setTermsOfPayment(null);
         $order->setTermsOfPaymentContent(null);
     }
     // Set content data.
     if ($termsOfPaymentContentData) {
         $order->setTermsOfPaymentContent($termsOfPaymentContentData);
     }
     return $terms;
 }