Example #1
0
 function Delete($ID)
 {
     global $APPLICATION;
     $ID = (int) $ID;
     if ($ID <= 0) {
         return false;
     }
     $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N');
     $arOrder = CSaleOrder::GetByID($ID);
     if ($arOrder) {
         if ($isOrderConverted == "Y") {
             $errorMessage = "";
             /** @var \Bitrix\Sale\Result $r */
             $r = \Bitrix\Sale\Compatible\OrderCompatibility::delete($ID);
             $orderDeleted = (bool) $r->isSuccess();
             if (!$r->isSuccess()) {
                 foreach ($r->getErrorMessages() as $error) {
                     $errorMessage .= " " . $error;
                 }
                 $APPLICATION->ThrowException(Loc::getMessage("SKGO_DELETE_ERROR", array("#MESSAGE#" => $errorMessage)), "DELETE_ERROR");
             }
             return $orderDeleted;
         } else {
             if ($arOrder["CANCELED"] != "Y") {
                 CSaleBasket::OrderCanceled($ID, "Y");
             }
             //used only for old catalog without reservation and deduction
             if ($arOrder["ALLOW_DELIVERY"] == "Y") {
                 CSaleOrder::DeliverOrder($ID, "N");
             }
             if ($arOrder["DEDUCTED"] == "Y") {
                 CSaleOrder::DeductOrder($ID, "N");
             }
             if ($arOrder["RESERVED"] == "Y") {
                 CSaleOrder::ReserveOrder($ID, "N");
             }
             if ($arOrder["PAYED"] != "Y") {
                 $arOrder["SUM_PAID"] = DoubleVal($arOrder["SUM_PAID"]);
                 if ($arOrder["SUM_PAID"] > 0) {
                     if (!CSaleUserAccount::UpdateAccount($arOrder["USER_ID"], $arOrder["SUM_PAID"], $arOrder["CURRENCY"], "ORDER_CANCEL_PART", $ID)) {
                         return False;
                     }
                 }
                 return CSaleOrder::_Delete($ID);
             } else {
                 if (CSaleOrder::PayOrder($ID, "N", True, True)) {
                     return CSaleOrder::_Delete($ID);
                 }
             }
         }
     }
     return false;
 }