Beispiel #1
0
 /**
  * @return Entity\AddResult|Entity\UpdateResult
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\ObjectNotFoundException
  * @throws \Exception
  */
 public function save()
 {
     $id = $this->getId();
     $fields = $this->fields->getValues();
     if ($id > 0) {
         $fields = $this->fields->getChangedValues();
         if (!empty($fields) && is_array($fields)) {
             //$fields['DATE_UPDATE'] = new Main\Type\DateTime();
             $r = Internals\PaymentTable::update($id, $fields);
             if (!$r->isSuccess()) {
                 return $r;
             }
         }
         $result = new Entity\UpdateResult();
     } else {
         $fields['ORDER_ID'] = $this->getParentOrderId();
         /** @var PaymentCollection $paymentCollection */
         if (!($paymentCollection = $this->getCollection())) {
             throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found');
         }
         /** @var Order $order */
         if (!($order = $paymentCollection->getOrder())) {
             throw new Main\ObjectNotFoundException('Entity "Order" not found');
         }
         if (!isset($fields['CURRENCY']) || strval($fields['CURRENCY']) == "") {
             $fields['CURRENCY'] = $order->getCurrency();
         }
         //$fields['DATE_INSERT'] = new Main\Type\DateTime();
         $r = Internals\PaymentTable::add($fields);
         if (!$r->isSuccess()) {
             return $r;
         }
         $id = $r->getId();
         $this->setFieldNoDemand('ID', $id);
         $result = new Entity\AddResult();
         if ($order->getId() > 0) {
             OrderHistory::addAction('PAYMENT', $order->getId(), 'PAYMENT_ADDED', $id, array('PAY_SYSTEM' => $this->getPaymentSystemName(), 'SUM' => $this->getSum()));
         }
     }
     if ($result->isSuccess()) {
         /** @var PaymentCollection $paymentCollection */
         if (!($paymentCollection = $this->getCollection())) {
             throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found');
         }
         /** @var Order $order */
         if (!($order = $paymentCollection->getOrder())) {
             throw new Main\ObjectNotFoundException('Entity "Order" not found');
         }
         OrderHistory::collectEntityFields('PAYMENT', $order->getId(), $id);
     }
     return $result;
 }
Beispiel #2
0
 /**
  * @return Entity\AddResult|Entity\UpdateResult
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\ObjectNotFoundException
  * @throws \Exception
  */
 public function save()
 {
     $id = $this->getId();
     $fields = $this->fields->getValues();
     if ($id > 0) {
         $fields = $this->fields->getChangedValues();
         if (!empty($fields) && is_array($fields)) {
             //$fields['DATE_UPDATE'] = new Main\Type\DateTime();
             $r = Internals\PaymentTable::update($id, $fields);
             if (!$r->isSuccess()) {
                 return $r;
             }
         }
         $result = new Entity\UpdateResult();
     } else {
         $fields['ORDER_ID'] = $this->getParentOrderId();
         /** @var PaymentCollection $paymentCollection */
         if (!($paymentCollection = $this->getCollection())) {
             throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found');
         }
         /** @var Order $order */
         if (!($order = $paymentCollection->getOrder())) {
             throw new Main\ObjectNotFoundException('Entity "Order" not found');
         }
         if (!isset($fields['CURRENCY']) || strval($fields['CURRENCY']) == "") {
             $fields['CURRENCY'] = $order->getCurrency();
         }
         //$fields['DATE_INSERT'] = new Main\Type\DateTime();
         $r = Internals\PaymentTable::add($fields);
         if (!$r->isSuccess()) {
             return $r;
         }
         $id = $r->getId();
         $this->setFieldNoDemand('ID', $id);
         $result = new Entity\AddResult();
         if ($order->getId() > 0) {
             OrderHistory::addAction('PAYMENT', $order->getId(), 'PAYMENT_ADDED', $id, $this);
         }
     }
     if ($result->isSuccess()) {
         /** @var PaymentCollection $paymentCollection */
         if (!($paymentCollection = $this->getCollection())) {
             throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found');
         }
         /** @var Order $order */
         if (!($order = $paymentCollection->getOrder())) {
             throw new Main\ObjectNotFoundException('Entity "Order" not found');
         }
         OrderHistory::collectEntityFields('PAYMENT', $order->getId(), $id);
         if ($eventName = static::getEntityEventName()) {
             $oldEntityValues = $this->fields->getOriginalValues();
             if (!empty($oldEntityValues)) {
                 /** @var Main\Event $event */
                 $event = new Main\Event('sale', 'On' . $eventName . 'EntitySaved', array('ENTITY' => $this, 'VALUES' => $oldEntityValues));
                 $event->send();
             }
         }
     }
     $this->fields->clearChanged();
     return $result;
 }