Exemple #1
0
 public static function createLink($id, $parentId, $type = self::LINK_TYPE_FINISH_START, array $behaviour = array())
 {
     $id = Assert::expectIntegerPositive($id, '$id');
     $parentId = Assert::expectIntegerPositive($parentId, '$parentId');
     $type = Assert::expectEnumerationMember($type, array(self::LINK_TYPE_START_START, self::LINK_TYPE_START_FINISH, self::LINK_TYPE_FINISH_START, self::LINK_TYPE_FINISH_FINISH), '$type');
     $exceptionInfo = array('AUX' => array('MESSAGE' => array('FROM_TASK_ID' => $parentId, 'TASK_ID' => $id, 'LINK_TYPE' => $type)));
     $result = new AddResult();
     if (is_array($behaviour['TASK_DATA']) && !empty($behaviour['TASK_DATA'])) {
         $toTask = $behaviour['TASK_DATA'];
     } else {
         $toTask = TaskTable::getById($id)->fetch();
     }
     if (empty($toTask)) {
         throw new ActionFailedException('Task not found', $exceptionInfo);
     }
     if (is_array($behaviour['PARENT_TASK_DATA']) && !empty($behaviour['PARENT_TASK_DATA'])) {
         $fromTask = $behaviour['PARENT_TASK_DATA'];
     } else {
         $fromTask = TaskTable::getById($parentId)->fetch();
     }
     if (empty($fromTask)) {
         throw new ActionFailedException('Parent task not found', $exceptionInfo);
     }
     if ((string) $toTask['CREATED_DATE'] == '') {
         $result->addError(new Error(Loc::getMessage('DEPENDENCE_ENTITY_CANT_ADD_LINK_CREATED_DATE_NOT_SET')));
     }
     if ((string) $toTask['END_DATE_PLAN'] == '') {
         $result->addError(new Error(Loc::getMessage('DEPENDENCE_ENTITY_CANT_ADD_LINK_END_DATE_PLAN_NOT_SET')));
     }
     if ((string) $fromTask['CREATED_DATE'] == '') {
         $result->addError(new Error(Loc::getMessage('DEPENDENCE_ENTITY_CANT_ADD_LINK_CREATED_DATE_NOT_SET_PARENT_TASK')));
     }
     if ((string) $fromTask['END_DATE_PLAN'] == '') {
         $result->addError(new Error(Loc::getMessage('DEPENDENCE_ENTITY_CANT_ADD_LINK_END_DATE_PLAN_NOT_SET_PARENT_TASK')));
     }
     if (!$result->isSuccess()) {
         return $result;
     } else {
         return parent::createLink($id, $parentId, array('LINK_DATA' => array('TYPE' => $type)));
     }
 }
Exemple #2
0
 /**
  * Add discount.
  *
  * @param array $data			Discount data.
  * @return Main\Entity\AddResult
  */
 public static function add(array $data)
 {
     $result = new Main\Entity\AddResult();
     $result->addError(new Main\Entity\EntityError(Loc::getMessage('CATALOG_DISCOUNT_ENTITY_MESS_ADD_BLOCKED')));
     return $result;
 }
Exemple #3
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\ShipmentTable::update($id, $fields);
             if (!$r->isSuccess()) {
                 return $r;
             }
         }
         $result = new Entity\UpdateResult();
         if (!empty($fields['TRACKING_NUMBER'])) {
             $oldEntityValues = $this->fields->getOriginalValues();
             /** @var Main\Event $event */
             $event = new Main\Event('sale', EventActions::EVENT_ON_SHIPMENT_TRACKING_NUMBER_CHANGE, array('ENTITY' => $this, 'VALUES' => $oldEntityValues));
             $event->send();
         }
     } else {
         $fields['ORDER_ID'] = $this->getParentOrderId();
         $fields['DATE_INSERT'] = new Main\Type\DateTime();
         $fields['SYSTEM'] = $fields['SYSTEM'] ? 'Y' : 'N';
         $r = Internals\ShipmentTable::add($fields);
         if (!$r->isSuccess()) {
             return $r;
         }
         $id = $r->getId();
         $this->setFieldNoDemand('ID', $id);
         $result = new Entity\AddResult();
         /** @var ShipmentItemCollection $shipmentItemCollection */
         if (!($shipmentItemCollection = $this->getShipmentItemCollection())) {
             throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
         }
         /** @var Shipment $shipment */
         if (!($shipment = $shipmentItemCollection->getShipment())) {
             throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
         }
         /** @var ShipmentCollection $shipmentCollection */
         if (!($shipmentCollection = $shipment->getCollection())) {
             throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
         }
         /** @var Order $order */
         if (!($order = $shipmentCollection->getOrder())) {
             throw new Main\ObjectNotFoundException('Entity "Order" not found');
         }
         if ($order->getId() > 0 && !$this->isSystem()) {
             OrderHistory::addAction('SHIPMENT', $order->getId(), 'SHIPMENT_ADDED', $id, $this);
         }
     }
     if ($result->isSuccess() && !$this->isSystem()) {
         $this->saveExtraServices();
         $this->saveStoreId();
     }
     /** @var ShipmentItemCollection $shipmentItemCollection */
     if (!($shipmentItemCollection = $this->getShipmentItemCollection())) {
         throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
     }
     $r = $shipmentItemCollection->save();
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
     }
     if ($result->isSuccess()) {
         /** @var Shipment $shipment */
         if (!($shipment = $shipmentItemCollection->getShipment())) {
             throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
         }
         /** @var ShipmentCollection $shipmentCollection */
         if (!($shipmentCollection = $shipment->getCollection())) {
             throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
         }
         /** @var Order $order */
         if (!($order = $shipmentCollection->getOrder())) {
             throw new Main\ObjectNotFoundException('Entity "Order" not found');
         }
         if (!$this->isSystem()) {
             OrderHistory::collectEntityFields('SHIPMENT', $order->getId(), $id);
         }
     }
     return $result;
 }
Exemple #4
0
 /**
  * @return Entity\AddResult|Entity\UpdateResult
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\ObjectNotFoundException
  * @throws \Exception
  */
 public function save()
 {
     $id = $this->getId();
     $fields = $this->fields->getValues();
     /** @var ShipmentItemCollection $shipmentItemCollection */
     if (!($shipmentItemCollection = $this->getCollection())) {
         throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
     }
     /** @var Shipment $shipment */
     if (!($shipment = $shipmentItemCollection->getShipment())) {
         throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
     }
     /** @var ShipmentCollection $shipmentCollection */
     if (!($shipmentCollection = $shipment->getCollection())) {
         throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
     }
     /** @var Order $order */
     if (!($order = $shipmentCollection->getOrder())) {
         throw new Main\ObjectNotFoundException('Entity "Order" not found');
     }
     if ($id > 0) {
         $fields = $this->fields->getChangedValues();
         if (!empty($fields) && is_array($fields)) {
             /** @var ShipmentItemCollection $shipmentItemCollection */
             if (!($shipmentItemCollection = $this->getCollection())) {
                 throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
             }
             /** @var Shipment $shipment */
             if (!($shipment = $shipmentItemCollection->getShipment())) {
                 throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
             }
             if (!$shipment->isSystem()) {
                 if (isset($fields["QUANTITY"]) && floatval($fields["QUANTITY"]) == 0) {
                     return new Entity\UpdateResult();
                 }
             }
             //$fields['DATE_UPDATE'] = new Main\Type\DateTime();
             $r = Internals\ShipmentItemTable::update($id, $fields);
             if (!$r->isSuccess()) {
                 return $r;
             }
         }
         $result = new Entity\UpdateResult();
         if ($order && $order->getId() > 0) {
             OrderHistory::collectEntityFields('SHIPMENT_ITEM_STORE', $order->getId(), $id);
         }
     } else {
         $fields['ORDER_DELIVERY_ID'] = $this->getParentShipmentId();
         $fields['DATE_INSERT'] = new Main\Type\DateTime();
         $fields["BASKET_ID"] = $this->basketItem->getId();
         if (!isset($fields["QUANTITY"]) || floatval($fields["QUANTITY"]) == 0) {
             return new Entity\UpdateResult();
         }
         if (!isset($fields['RESERVED_QUANTITY'])) {
             $fields['RESERVED_QUANTITY'] = $this->getReservedQuantity() === null ? 0 : $this->getReservedQuantity();
         }
         $r = Internals\ShipmentItemTable::add($fields);
         if (!$r->isSuccess()) {
             return $r;
         }
         $id = $r->getId();
         $this->setFieldNoDemand('ID', $id);
         $result = new Entity\AddResult();
         if (!$shipment->isSystem()) {
             OrderHistory::addAction('SHIPMENT', $order->getId(), 'SHIPMENT_ITEM_BASKET_ADDED', $shipment->getId(), $this->basketItem, array('QUANTITY' => $this->getQuantity()));
         }
     }
     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();
         }
     }
     $shipmentItemStoreCollection = $this->getShipmentItemStoreCollection();
     $r = $shipmentItemStoreCollection->save();
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
     }
     if ($result->isSuccess()) {
         OrderHistory::collectEntityFields('SHIPMENT_ITEM', $order->getId(), $id);
     }
     $this->fields->clearChanged();
     return $result;
 }
Exemple #5
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;
 }
Exemple #6
0
 /**
  * @return Entity\AddResult|Entity\UpdateResult
  * @throws ArgumentException
  * @throws ArgumentNullException
  * @throws \Exception
  */
 public function save()
 {
     $id = $this->getId();
     $changedFields = $this->fields->getChangedValues();
     if ($id == 0 || !empty($changedFields)) {
         /** @var Event $event */
         $event = new Event('sale', EventActions::EVENT_ON_BASKET_ITEM_BEFORE_SAVED, array($this));
         $event->send();
         if ($event->getResults()) {
             $result = new Result();
             /** @var EventResult $eventResult */
             foreach ($event->getResults() as $eventResult) {
                 if ($eventResult->getType() == EventResult::ERROR) {
                     $errorMsg = new ResultError(Loc::getMessage('SALE_EVENT_ON_BEFORE_BASKET_ITEM_SAVED'), 'SALE_EVENT_ON_BEFORE_BASKET_ITEM_SAVED');
                     if (isset($eventResultData['ERROR']) && $eventResultData['ERROR'] instanceof ResultError) {
                         $errorMsg = $eventResultData['ERROR'];
                     }
                     $result->addError($errorMsg);
                 }
             }
             if (!$result->isSuccess()) {
                 return $result;
             }
         }
     }
     $fields = $this->fields->getValues();
     $newItem = $id > 0 ? false : true;
     if ($this->isBundleParent()) {
         $bundleBasketCollection = $this->getBundleCollection();
     }
     if ($id > 0) {
         $fields = $changedFields;
         if (!isset($fields["ORDER_ID"]) || intval($fields["ORDER_ID"]) == 0) {
             $orderId = null;
             if ($this->getParentOrderId() > 0) {
                 $orderId = $this->getParentOrderId();
             }
             if ($this->isBundleChild() && $orderId === null) {
                 /** @var BasketItem $parentBasket */
                 if (!($parentBasket = $this->getParentBasketItem())) {
                     throw new ObjectNotFoundException('Entity parent "BasketItem" not found');
                 }
                 $orderId = $parentBasket->getParentOrderId();
             }
             if (intval($orderId) > 0) {
                 $fields['ORDER_ID'] = $orderId;
             }
         }
         if (!empty($fields) && is_array($fields)) {
             if (isset($fields["QUANTITY"]) && floatval($fields["QUANTITY"]) == 0) {
                 return new Entity\UpdateResult();
             }
             $fields['DATE_UPDATE'] = new DateTime();
             $this->setFieldNoDemand('DATE_UPDATE', $fields['DATE_UPDATE']);
             $r = Internals\BasketTable::update($id, $fields);
             if (!$r->isSuccess()) {
                 return $r;
             }
         }
         $result = new Entity\UpdateResult();
     } else {
         $fields['ORDER_ID'] = $this->getParentOrderId();
         $fields['DATE_INSERT'] = new DateTime();
         $fields['DATE_UPDATE'] = new DateTime();
         $this->setFieldNoDemand('DATE_INSERT', $fields['DATE_INSERT']);
         $this->setFieldNoDemand('DATE_UPDATE', $fields['DATE_UPDATE']);
         if (!$this->isBundleChild() && (!isset($fields["FUSER_ID"]) || intval($fields["FUSER_ID"]) <= 0)) {
             /** @var Basket $basket */
             if (!($basket = $this->getCollection())) {
                 throw new ObjectNotFoundException('Entity "Basket" not found');
             }
             $fields["FUSER_ID"] = intval($basket->getFUserId());
         }
         /** @var Basket $basket */
         if (!($basket = $this->getCollection())) {
             throw new ObjectNotFoundException('Entity "Basket" not found');
         }
         /** @var Order $order */
         if ($order = $basket->getOrder()) {
             if (!isset($fields["LID"]) || strval($fields["LID"]) == '') {
                 $fields['LID'] = $order->getField('LID');
             }
         } else {
             if ($siteId = $basket->getSiteId()) {
                 $fields['LID'] = $siteId;
             }
         }
         if ($this->isBundleChild()) {
             if (!($parentBasketItem = $this->getParentBasketItem())) {
                 throw new ObjectNotFoundException('Entity parent "BasketItem" not found');
             }
             $fields['LID'] = $parentBasketItem->getField('LID');
             if (!isset($fields["FUSER_ID"]) || intval($fields["FUSER_ID"]) <= 0) {
                 $fields['FUSER_ID'] = intval($parentBasketItem->getField('FUSER_ID'));
             }
         }
         if (!isset($fields["LID"]) || strval(trim($fields["LID"])) == '') {
             throw new ArgumentNullException('lid');
         }
         if ($this->isBundleChild() && (!isset($fields["SET_PARENT_ID"]) || intval($fields["QUANTITY"]) <= 0)) {
             $fields["SET_PARENT_ID"] = $this->getParentBasketItemId();
             $this->setFieldNoDemand('SET_PARENT_ID', $fields['SET_PARENT_ID']);
         }
         if (!isset($fields["QUANTITY"]) || floatval($fields["QUANTITY"]) == 0) {
             return new Entity\AddResult();
         }
         if (!isset($fields["CURRENCY"]) || strval(trim($fields["CURRENCY"])) == '') {
             throw new ArgumentNullException('currency');
         }
         $r = Internals\BasketTable::add($fields);
         if (!$r->isSuccess()) {
             return $r;
         }
         $id = $r->getId();
         $this->setFieldNoDemand('ID', $id);
         $this->setFieldNoDemand('LID', $fields['LID']);
         $this->setFieldNoDemand('FUSER_ID', $fields['FUSER_ID']);
         if ($basket->getOrder() && $basket->getOrderId() > 0) {
             OrderHistory::addAction('BASKET', $order->getId(), 'BASKET_ADDED', $id, array('QUANTITY' => $this->getQuantity(), 'PRODUCT_ID' => $this->getProductId(), 'NAME' => $this->getField('NAME')));
         }
         $result = new Entity\AddResult();
     }
     // bundle
     if ($this->isBundleParent()) {
         if (!empty($bundleBasketCollection)) {
             if (!($order = $bundleBasketCollection->getOrder())) {
                 /** @var Basket $basketCollection */
                 $basketCollection = $this->getCollection();
                 if ($order = $basketCollection->getOrder()) {
                     $bundleBasketCollection->setOrder($order);
                 }
             }
             $itemsFromDb = array();
             if (!$newItem) {
                 $itemsFromDbList = Internals\BasketTable::getList(array("filter" => array("SET_PARENT_ID" => $id), "select" => array("ID")));
                 while ($itemsFromDbItem = $itemsFromDbList->fetch()) {
                     if ($itemsFromDbItem["ID"] == $id) {
                         continue;
                     }
                     $itemsFromDb[$itemsFromDbItem["ID"]] = true;
                 }
             }
             /** @var BasketItem $bundleBasketItem */
             foreach ($bundleBasketCollection as $bundleBasketItem) {
                 $r = $bundleBasketItem->save();
                 if (!$r->isSuccess()) {
                     $result->addErrors($r->getErrors());
                 }
                 if (isset($itemsFromDb[$bundleBasketItem->getId()])) {
                     unset($itemsFromDb[$bundleBasketItem->getId()]);
                 }
             }
             foreach ($itemsFromDb as $k => $v) {
                 Internals\BasketTable::delete($k);
             }
         }
     }
     /** @var BasketPropertiesCollection $basketPropertyCollection */
     $basketPropertyCollection = $this->getPropertyCollection();
     $r = $basketPropertyCollection->save();
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
     }
     return $result;
 }
Exemple #7
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;
 }