当前位置: 首页>>代码示例>>PHP>>正文


PHP Provider::onOrderSave方法代码示例

本文整理汇总了PHP中Provider::onOrderSave方法的典型用法代码示例。如果您正苦于以下问题:PHP Provider::onOrderSave方法的具体用法?PHP Provider::onOrderSave怎么用?PHP Provider::onOrderSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Provider的用法示例。


在下文中一共展示了Provider::onOrderSave方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 /**
  * @return Entity\AddResult|Entity\UpdateResult|Result|mixed
  * @throws Main\ArgumentOutOfRangeException
  */
 public function save()
 {
     global $USER;
     $result = new Result();
     $id = $this->getId();
     $this->isNew = $id == 0;
     /** @var array $oldEntityValues */
     $oldEntityValues = $this->fields->getOriginalValues();
     /** @var Main\Entity\Event $event */
     $event = new Main\Event('sale', EventActions::EVENT_ON_ORDER_BEFORE_SAVED, array('ENTITY' => $this, 'VALUES' => $oldEntityValues));
     $event->send();
     if ($event->getResults()) {
         $result = new Result();
         /** @var Main\EventResult $eventResult */
         foreach ($event->getResults() as $eventResult) {
             if ($eventResult->getType() == Main\EventResult::ERROR) {
                 $errorMsg = new ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_ON_BEFORE_ORDER_SAVED_ERROR'), 'SALE_EVENT_ON_BEFORE_ORDER_SAVED_ERROR');
                 if ($eventResultData = $eventResult->getParameters()) {
                     if (isset($eventResultData['ERROR']) && $eventResultData['ERROR'] instanceof ResultError) {
                         $errorMsg = $eventResultData['ERROR'];
                     }
                 }
                 $result->addError($errorMsg);
             }
         }
         if (!$result->isSuccess()) {
             return $result;
         }
     }
     $r = Provider::onOrderSave($this);
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
         return $result;
     }
     $fields = $this->fields->getValues();
     if ($id > 0) {
         $fields = $this->fields->getChangedValues();
         if ($this->isChanged()) {
             $fields['DATE_UPDATE'] = new Type\DateTime();
             $this->setFieldNoDemand('DATE_UPDATE', $fields['DATE_UPDATE']);
             $fields['VERSION'] = intval($this->getField('VERSION')) + 1;
             $this->setFieldNoDemand('VERSION', $fields['VERSION']);
             $fields['UPDATED_1C'] = 'N';
             $this->setFieldNoDemand('UPDATED_1C', $fields['UPDATED_1C']);
         }
         if (!empty($fields) && is_array($fields)) {
             $result = Internals\OrderTable::update($id, $fields);
             if (!$result->isSuccess()) {
                 return $result;
             }
         } else {
             $result = new Entity\UpdateResult();
         }
     } else {
         $fields['DATE_UPDATE'] = $fields['DATE_INSERT'] = new Type\DateTime();
         $this->setFieldNoDemand('DATE_INSERT', $fields['DATE_INSERT']);
         $this->setFieldNoDemand('DATE_UPDATE', $fields['DATE_UPDATE']);
         if ($USER->isAuthorized()) {
             $fields['CREATED_BY'] = $USER->getID();
             $this->setFieldNoDemand('CREATED_BY', $fields['CREATED_BY']);
         }
         if (!isset($fields['STATUS_ID']) || strval($fields['STATUS_ID']) == '') {
             $orderStatus = OrderStatus::getInitialStatus();
             if (!empty($orderStatus) && !is_array($orderStatus)) {
                 $fields['STATUS_ID'] = $orderStatus;
                 $this->setFieldNoDemand('STATUS_ID', $fields['STATUS_ID']);
             }
         }
         if (isset($fields['STATUS_ID']) && strval($fields['STATUS_ID']) != '') {
             if (!isset($fields['DATE_STATUS']) || strval($fields['DATE_STATUS']) == '') {
                 $fields['DATE_STATUS'] = new Type\DateTime();
                 $this->setFieldNoDemand('DATE_STATUS', $fields['DATE_STATUS']);
             }
             if ((!isset($fields['EMP_STATUS_ID']) || (int) $fields['EMP_STATUS_ID'] <= 0) && $USER->isAuthorized()) {
                 $fields['EMP_STATUS_ID'] = $USER->getID();
                 $this->setFieldNoDemand('EMP_STATUS_ID', $fields['EMP_STATUS_ID']);
             }
         }
         $result = Internals\OrderTable::add($fields);
         if (!$result->isSuccess()) {
             return $result;
         }
         $id = $result->getId();
         $this->setFieldNoDemand('ID', $id);
         /** @var Result $r */
         $r = static::setAccountNumber($id);
         if ($r->isSuccess()) {
             if ($accountData = $r->getData()) {
                 if (array_key_exists('ACCOUNT_NUMBER', $accountData)) {
                     $this->setField('ACCOUNT_NUMBER', $accountData['ACCOUNT_NUMBER']);
                 }
             }
         }
         OrderHistory::addAction('ORDER', $id, 'ORDER_ADDED', $id, $this);
     }
     if ($eventName = static::getEntityEventName()) {
//.........这里部分代码省略.........
开发者ID:webgksupport,项目名称:alpina,代码行数:101,代码来源:order.php

示例2: save

 /**
  * @return Entity\AddResult|Entity\UpdateResult|Result|mixed
  * @throws Main\ArgumentOutOfRangeException
  */
 public function save()
 {
     global $USER, $CACHE_MANAGER;
     $result = new Result();
     $id = $this->getId();
     $this->isNew = $id == 0;
     if ($this->isNew) {
         $fields = $this->fields->getChangedValues();
         if (empty($fields['STATUS_ID'])) {
             /** @var Result $r */
             $r = $this->setField("STATUS_ID", OrderStatus::getInitialStatus());
             if (!$r->isSuccess()) {
                 $result->addErrors($r->getErrors());
             }
         }
     }
     /** @var array $oldEntityValues */
     $oldEntityValues = $this->fields->getOriginalValues();
     /** @var Main\Entity\Event $event */
     $event = new Main\Event('sale', EventActions::EVENT_ON_ORDER_BEFORE_SAVED, array('ENTITY' => $this, 'VALUES' => $oldEntityValues));
     $event->send();
     if ($event->getResults()) {
         /** @var Main\EventResult $eventResult */
         foreach ($event->getResults() as $eventResult) {
             if ($eventResult->getType() == Main\EventResult::ERROR) {
                 $errorMsg = new ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_ON_BEFORE_ORDER_SAVED_ERROR'), 'SALE_EVENT_ON_BEFORE_ORDER_SAVED_ERROR');
                 if ($eventResultData = $eventResult->getParameters()) {
                     if (isset($eventResultData) && $eventResultData instanceof ResultError) {
                         /** @var ResultError $errorMsg */
                         $errorMsg = $eventResultData;
                     }
                 }
                 $result->addError($errorMsg);
             }
         }
     }
     if (!$result->isSuccess()) {
         return $result;
     }
     $r = $this->verify();
     if (!$r->isSuccess()) {
         $oldErrorText = $this->getField('REASON_MARKED');
         /** @var ResultError $error */
         foreach ($r->getErrors() as $error) {
             if ($error instanceof ResultNotice) {
                 continue;
             } elseif ($error instanceof ResultWarning) {
                 $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $error->getMessage();
                 continue;
             } else {
                 $result->addError($error);
             }
         }
         if (strval(trim($oldErrorText)) != '') {
             $this->setField('MARKED', "Y");
             $this->setField('REASON_MARKED', $oldErrorText);
         }
         if (!$result->isSuccess()) {
             return $result;
         }
     }
     $r = Provider::onOrderSave($this);
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
         return $result;
     }
     $fields = $this->fields->getValues();
     if ($id > 0) {
         $fields = $this->fields->getChangedValues();
         $isChanged = (bool) (!empty($fields));
         if ($this->isChanged()) {
             if (!isset($fields['DATE_UPDATE']) || strval($fields['DATE_UPDATE']) == '') {
                 $fields['DATE_UPDATE'] = new Type\DateTime();
                 $this->setFieldNoDemand('DATE_UPDATE', $fields['DATE_UPDATE']);
             }
             $fields['VERSION'] = intval($this->getField('VERSION')) + 1;
             $this->setFieldNoDemand('VERSION', $fields['VERSION']);
             if (array_key_exists('REASON_MARKED', $fields) && strlen($fields['REASON_MARKED']) > 255) {
                 $fields['REASON_MARKED'] = substr($fields['REASON_MARKED'], 0, 255);
             }
         }
         if (!empty($fields) && is_array($fields)) {
             $r = Internals\OrderTable::update($id, $fields);
             if (!$r->isSuccess()) {
                 OrderHistory::addAction('ORDER', $id, 'ORDER_UPDATE_ERROR', $id, $this, array("ERROR" => $r->getErrorMessages()));
                 $result->addWarnings($r->getErrors());
                 return $result;
             }
             if ($resultData = $r->getData()) {
                 $result->setData($resultData);
             }
             OrderHistory::addAction('ORDER', $id, 'ORDER_UPDATED', $id, $this);
         }
     } else {
         $isChanged = true;
         if (!isset($fields['DATE_INSERT']) || strval($fields['DATE_INSERT']) == '') {
//.........这里部分代码省略.........
开发者ID:akniyev,项目名称:itprom_dobrohost,代码行数:101,代码来源:order.php


注:本文中的Provider::onOrderSave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。