public static function chStatusNew($entity)
 {
     try {
         $fields = $entity->getFields();
         self::$values = $fields->getValues();
         $old_values = $fields->getOriginalValues();
         self::$o_erip = new \Dm\Erip();
         self::$opt_status = \Bitrix\Main\Config\Option::get(self::$module_id, "order_status_code_erip");
         self::$opt_payment = \Bitrix\Main\Config\Option::get(self::$module_id, "payment_system_id");
         //var_dump(self::$opt_status == self::$values["STATUS_ID"]);
         //var_dump($old_values["STATUS_ID"] != self::$values["STATUS_ID"]);
         //var_dump(self::$values["PAY_SYSTEM_ID"] == self::$opt_payment);
         //die;
         if (self::$opt_status == self::$values["STATUS_ID"] && $old_values["STATUS_ID"] != self::$values["STATUS_ID"] && self::$values["PAY_SYSTEM_ID"] == self::$opt_payment) {
             static::setTehnicalInfo();
             static::setUserInfo();
             static::setMoneyInfo();
             $r = self::$o_erip->submit();
             self::$o_response = json_decode($r);
             if (isset(self::$o_response->errors)) {
                 throw new \Exception(self::$o_response->message);
             }
             if (\Bitrix\Sale\Internals\OrderTable::update(self::$values["ID"], array("COMMENTS" => "status: " . self::$o_response->transaction->status . "\n" . "transaction_id: " . self::$o_response->transaction->transaction_id . "\n" . "order_id: " . self::$o_response->transaction->order_id . "\n" . "account_number: " . self::$o_response->transaction->erip->account_number . "\n"))) {
                 static::sendMail();
             }
             return true;
         }
     } catch (Exception $e) {
         $GLOBALS["APPLICATION"]->ThrowException($e->getMessage());
         return false;
     }
 }
 public static function chStatusNew($entity)
 {
     if ($GLOBALS["STOP_ERIP_HANDLER"] === true) {
         return true;
     }
     //отмена запуска обработчика
     $GLOBALS["STOP_ERIP_HANDLER"] = true;
     try {
         $fields = $entity->getFields();
         self::$values = $fields->getValues();
         $old_values = $fields->getOriginalValues();
         self::$o_erip = new \Dm\Erip();
         self::$opt_status = \Bitrix\Main\Config\Option::get(self::$module_id, "order_status_code_erip");
         self::$opt_payment = \Bitrix\Main\Config\Option::get(self::$module_id, "payment_system_id");
         if (self::$opt_status == self::$values["STATUS_ID"] && $old_values["STATUS_ID"] != self::$values["STATUS_ID"] && self::$values["PAY_SYSTEM_ID"] == self::$opt_payment) {
             self::set_and_send();
             if (\Bitrix\Sale\Internals\OrderTable::update(self::$values["ID"], array("COMMENTS" => "status: " . self::$o_response->transaction->status . "\n" . "transaction_id: " . self::$o_response->transaction->transaction_id . "\n" . "order_id: " . self::$o_response->transaction->order_id . "\n" . "account_number: " . self::$o_response->transaction->erip->account_number . "\n"))) {
                 static::sendMail();
             }
             return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS);
         }
     } catch (Exception $e) {
         $error = new \Bitrix\Sale\ResultError($e->getMessage(), $values['ID']);
         return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, array('ERROR' => $error), 'sale');
     }
 }
示例#3
0
 /**
  * Unlock order.
  *
  * @param int $id			Order id.
  * @return Entity\UpdateResult|Result
  * @throws Main\ArgumentNullException
  * @throws \Exception
  */
 public static function unlock($id)
 {
     global $USER;
     $result = new Result();
     $id = (int) $id;
     if ($id <= 0) {
         $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_WRONG_ID'), 'SALE_ORDER_WRONG_ID'));
         return $result;
     }
     if (!($order = Order::load($id))) {
         $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_ENTITY_NOT_FOUND'), 'SALE_ORDER_ENTITY_NOT_FOUND'));
         return $result;
     }
     $userRights = \CMain::getUserRight("sale", $USER->getUserGroupArray(), "Y", "Y");
     if ($userRights >= "W" || $order->getField("LOCKED_BY") == $USER->getID()) {
         return Internals\OrderTable::update($id, array('DATE_LOCK' => null, 'LOCKED_BY' => null));
     }
     return $result;
 }
示例#4
0
 /**
  * The agent function. Moves reserved quantity back to the quantity field for each product
  * for orders which were placed earlier than specific date
  *
  * @return agent name string
  */
 public static function ClearProductReservedQuantity()
 {
     global $DB, $USER;
     if (!is_object($USER)) {
         $USER = new CUser();
     }
     $days_ago = (int) COption::GetOptionString("sale", "product_reserve_clear_period");
     if ($days_ago > 0) {
         $shipmentList = array();
         $date = new \Bitrix\Main\Type\DateTime();
         $filter = array('filter' => array("<=DATE_INSERT" => $date->add('-' . $days_ago . ' day'), "=SHIPMENT.RESERVED" => "Y", "=SHIPMENT.DEDUCTED" => "N", "=SHIPMENT.MARKED" => "N", "=SHIPMENT.ALLOW_DELIVERY" => "N", "=PAYED" => "N", "=CANCELED" => "N"), 'select' => array("ID", "SHIPMENT_ID" => "SHIPMENT.ID", "SHIPMENT_RESERVED" => "SHIPMENT.RESERVED", "SHIPMENT_DEDUCTED" => "SHIPMENT.DEDUCTED", "DATE_INSERT", "PAYED", "CANCELED", "MARKED"));
         $res = \Bitrix\Sale\Internals\OrderTable::getList($filter);
         while ($data = $res->fetch()) {
             if (!array_key_exists($data['ID'], $shipmentList)) {
                 $shipmentList[$data['ID']] = array();
             }
             if (in_array($data['SHIPMENT_ID'], $shipmentList[$data['ID']])) {
                 continue;
             }
             $shipmentList[$data['ID']][] = $data['SHIPMENT_ID'];
         }
         if (!empty($shipmentList)) {
             foreach ($shipmentList as $orderId => $shipmentData) {
                 /** @var Sale\Order $order */
                 $order = Sale\Order::load($orderId);
                 $orderSaved = false;
                 $errors = array();
                 try {
                     /** @var Sale\ShipmentCollection $shipmentCollection */
                     if ($shipmentCollection = $order->getShipmentCollection()) {
                         foreach ($shipmentData as $shipmentId) {
                             /** @var Sale\Shipment $shipment */
                             if ($shipment = $shipmentCollection->getItemById($shipmentId)) {
                                 $r = $shipment->tryUnreserve();
                                 if (!$r->isSuccess()) {
                                     if (!$shipment->isMarked()) {
                                         $shipment->setField('MARKED', 'Y');
                                         if (is_array($r->getErrorMessages())) {
                                             $oldErrorText = $shipment->getField('REASON_MARKED');
                                             foreach ($r->getErrorMessages() as $error) {
                                                 $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error;
                                             }
                                             $shipment->setField('REASON_MARKED', $oldErrorText);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $r = $order->save();
                     if ($r->isSuccess()) {
                         $orderSaved = true;
                     } else {
                         $errors = $r->getErrorMessages();
                     }
                 } catch (Exception $e) {
                     $errors[] = $e->getMessage();
                 }
                 if (!$orderSaved) {
                     if (!empty($errors)) {
                         $oldErrorText = $order->getField('REASON_MARKED');
                         foreach ($errors as $error) {
                             $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error;
                         }
                         Sale\Internals\OrderTable::update($order->getId(), array("MARKED" => "Y", "REASON_MARKED" => $oldErrorText));
                     }
                 }
             }
         }
     }
     return "CSaleOrder::ClearProductReservedQuantity();";
 }
 /**
  * @param $id
  * @param $value
  * @return \Bitrix\Main\Entity\UpdateResult
  * @throws \Exception
  */
 public static function setAccountNumber($id, $value)
 {
     return OrderTable::update($id, array('ACCOUNT_NUMBER' => $value));
 }
示例#6
0
 protected function saveCommentsAction()
 {
     if (!isset($this->request['orderId']) || intval($this->request['orderId']) <= 0) {
         throw new SystemException("Wrong order id!");
     }
     if (!isset($this->request['comments'])) {
         throw new SystemException("Can't find the comments content!");
     }
     $res = Sale\Internals\OrderTable::update($this->request['orderId'], array("COMMENTS" => $this->request['comments']));
     if (!$res->isSuccess()) {
         $this->addResultError(join("\n", $res->getErrorMessages()));
     }
     $CBXSanitizer = new \CBXSanitizer();
     $CBXSanitizer->SetLevel(\CBXSanitizer::SECURE_LEVEL_MIDDLE);
     $this->addResultData("COMMENTS", $CBXSanitizer->SanitizeHtml($this->request['comments']));
 }
示例#7
0
 /**
  * @internal
  * @param $id
  *
  * @return Sale\Result
  * @throws Exception
  * @throws \Bitrix\Main\ArgumentNullException
  */
 protected static function setIdAsAccountNumber($id)
 {
     $result = new Sale\Result();
     $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N');
     if ($isOrderConverted == "Y") {
         try {
             /** @var \Bitrix\Sale\Result $r */
             $r = \Bitrix\Sale\Internals\OrderTable::update($id, array("ACCOUNT_NUMBER" => $id));
             $res = $r->isSuccess(true);
         } catch (\Bitrix\Main\DB\SqlQueryException $exception) {
             $res = false;
         }
     } else {
         $res = CSaleOrder::Update($id, array("ACCOUNT_NUMBER" => $id), false);
     }
     if (!$res) {
         $result->addError(new Sale\ResultError(Loc::getMessage('SALE_ORDER_GENERATE_ACCOUNT_NUMBER_ORDER_NUMBER_IS_NOT_SET_AS_ID'), 'SALE_ORDER_GENERATE_ACCOUNT_NUMBER_ORDER_NUMBER_IS_NOT_SET_AS_ID'));
         return $result;
     }
     $result->setData(array('ACCOUNT_NUMBER' => $id));
     return $result;
 }