/** * @param null $oldPaid * @return Result * @throws Main\ObjectNotFoundException */ protected function onAfterSyncPaid($oldPaid = null) { global $USER; $result = new Result(); /** @var PaymentCollection $paymentCollection */ if (!($paymentCollection = $this->getPaymentCollection())) { throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found'); } /** @var ShipmentCollection $shipmentCollection */ if (!($shipmentCollection = $this->getShipmentCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found'); } $oldPaidBool = null; if ($oldPaid !== null) { $oldPaidBool = $oldPaid == "Y"; } if ($oldPaid == "N" && $this->isPaid() && $this->getField('STATUS_ID') != OrderStatus::getFinalStatus()) { $orderStatus = Config\Option::get('sale', 'status_on_paid', ''); if (strval($orderStatus) != '') { if ($USER && $USER->isAuthorized()) { $statusesList = OrderStatus::getAllowedUserStatuses($USER->getID(), $this->getField('STATUS_ID')); $statusesList = array_keys($statusesList); } else { $statusesList = OrderStatus::getAllStatuses(); } if ($this->getField('STATUS_ID') != $orderStatus && in_array($orderStatus, $statusesList)) { $this->setField('STATUS_ID', $orderStatus); } } } if ($oldPaid !== null && $this->isPaid() != $oldPaidBool) { Internals\EventsPool::addEvent($this, EventActions::EVENT_ON_ORDER_PAID, array('ENTITY' => $this)); Internals\EventsPool::addEvent($this, EventActions::EVENT_ON_ORDER_PAID_SEND_MAIL, array('ENTITY' => $this)); } if (Configuration::getProductReservationCondition() == Configuration::RESERVE_ON_PAY) { if ($paymentCollection->hasPaidPayment()) { $r = $shipmentCollection->tryReserve(); if (!$r->isSuccess()) { foreach ($r->getErrors() as $error) { if ($error instanceof ResultWarning) { $this->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $this->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $errorText) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $errorText; } $this->setField('REASON_MARKED', $oldErrorText); } continue; } else { $result->addError($error); } } } } else { $r = $shipmentCollection->tryUnreserve(); if (!$r->isSuccess()) { foreach ($r->getErrors() as $error) { if ($error instanceof ResultWarning) { $this->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $this->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $errorText) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $errorText; } $this->setField('REASON_MARKED', $oldErrorText); } continue; } else { $result->addError($error); } } } } } elseif (Configuration::getProductReservationCondition() == Configuration::RESERVE_ON_FULL_PAY) { if ($oldPaid == "N" && $this->isPaid()) { $r = $shipmentCollection->tryReserve(); if (!$r->isSuccess()) { foreach ($r->getErrors() as $error) { if ($error instanceof ResultWarning) { $this->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $this->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $errorText) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $errorText; } $this->setField('REASON_MARKED', $oldErrorText); } continue; } else { $result->addError($error); } } } } elseif ($oldPaid == "Y" && !$this->isPaid()) { $r = $shipmentCollection->tryUnreserve(); if (!$r->isSuccess()) { foreach ($r->getErrors() as $error) { if ($error instanceof ResultWarning) { $this->setField('MARKED', 'Y'); if (is_array($r->getErrorMessages())) { $oldErrorText = $this->getField('REASON_MARKED'); foreach ($r->getErrorMessages() as $errorText) { $oldErrorText .= (strval($oldErrorText) != '' ? "\n" : "") . $errorText; } $this->setField('REASON_MARKED', $oldErrorText); } continue; } else { $result->addError($error); } } } } } if (Configuration::needAllowDeliveryOnPay()) { if ($oldPaid == "N" && $this->isPaid()) { $r = $shipmentCollection->allowDelivery(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } elseif ($oldPaid == "Y" && !$this->isPaid()) { $r = $shipmentCollection->disallowDelivery(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } return $result; }
while ($row = $result->Fetch()) { if ($row['GROUP_ID'] > 2) { $saleGroupIds[] = $row['GROUP_ID']; } } if ($saleGroupIds) { $result = GroupTable::getList(array('select' => array('ID', 'NAME'), 'filter' => array('=ID' => $saleGroupIds), 'order' => array('C_SORT' => 'ASC', 'ID' => 'ASC'))); while ($row = $result->fetch()) { $groups[$row['ID']] = $row['NAME']; } } // A D D / U P D A T E ///////////////////////////////////////////////////////////////////////////////////////////////// if ($_SERVER['REQUEST_METHOD'] == 'POST' && !$readOnly && check_bitrix_sessid() && ($_POST['save'] || $_POST['apply'])) { $errors = array(); $statusType = $_REQUEST['TYPE'] == 'O' ? 'O' : 'D'; $lockedStatusList = array("O" => array(\Bitrix\Sale\OrderStatus::getInitialStatus(), \Bitrix\Sale\OrderStatus::getFinalStatus()), "D" => array(\Bitrix\Sale\DeliveryStatus::getInitialStatus(), \Bitrix\Sale\DeliveryStatus::getFinalStatus())); if ($statusId) { foreach ($lockedStatusList as $lockStatusType => $lockStatusIdList) { foreach ($lockStatusIdList as $lockStatusId) { if ($lockStatusId == $statusId && $statusType != $lockStatusType) { $errors[] = Loc::getMessage('SALE_STATUS_WRONG_TYPE', array('#STATUS_ID#' => htmlspecialcharsEx($statusId), '#STATUS_TYPE#' => Loc::getMessage('SSEN_TYPE_' . $statusType))); break; } } } } // prepare & check status $status = array('TYPE' => $statusType, 'SORT' => ($statusSort = intval($_POST['SORT'])) ? $statusSort : 100, 'NOTIFY' => $_POST['NOTIFY'] ? 'Y' : 'N'); $isNew = true; $result = new \Bitrix\Main\Entity\Result(); if ($statusId) {