Example #1
0
 if ($isSavingOperation || $isRefreshDataAndSaveOperation) {
     $order = OrderEdit::editOrderByFormData($_POST, $order, $USER->GetID(), true, $_FILES, $result);
 }
 if ($isRefreshDataAndSaveOperation) {
     /** @var \Bitrix\Sale\Basket $basket */
     if (!($basket = $order->getBasket())) {
         throw new \Bitrix\Main\ObjectNotFoundException('Entity "Basket" not found');
     }
     $res = $basket->refreshData(array('PRICE', 'QUANTITY', 'COUPONS'));
     if (!$res->isSuccess()) {
         $result->addErrors($res->getErrors());
     }
 }
 if (($isSavingOperation || $isRefreshDataAndSaveOperation) && $result->isSuccess()) {
     if ($order) {
         $res = OrderEdit::saveCoupons($order->getUserId(), $_POST);
         if (!$res) {
             $result->addError(new \Bitrix\Main\Entity\EntityError("Can't save coupons!"));
         }
         $discount = $order->getDiscount();
         $res = $discount->calculate();
         if (!$res->isSuccess()) {
             $result->addErrors($res->getErrors());
         }
         if ($isRefreshDataAndSaveOperation && !$order->isCanceled() && !$order->isPaid()) {
             /** @var \Bitrix\Sale\PaymentCollection $paymentCollection */
             if (($paymentCollection = $order->getPaymentCollection()) && count($paymentCollection) == 1) {
                 /** @var \Bitrix\Sale\Payment $payment */
                 if (($payment = $paymentCollection->rewind()) && !$payment->isPaid()) {
                     $payment->setFieldNoDemand('SUM', $order->getPrice());
                 }