Beispiel #1
0
 function ReserveOrder($ID, $val)
 {
     global $APPLICATION;
     $ID = IntVal($ID);
     $val = $val != "Y" ? "N" : "Y";
     $errorMessage = "";
     $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N');
     if ($ID <= 0) {
         $APPLICATION->ThrowException(Loc::getMessage("SKGO_NO_ORDER_ID"), "NO_ORDER_ID");
         return false;
     }
     $arOrder = CSaleOrder::GetByID($ID);
     if (!$arOrder) {
         $APPLICATION->ThrowException(str_replace("#ID#", $ID, Loc::getMessage("SKGO_NO_ORDER")), "NO_ORDER");
         return false;
     }
     if ($arOrder["RESERVED"] == $val) {
         $APPLICATION->ThrowException(str_replace("#ID#", $ID, Loc::getMessage("SKGO_DUB_RESERVATION")), "ALREADY_FLAG");
         return false;
     }
     foreach (GetModuleEvents("sale", "OnSaleBeforeReserveOrder", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID, $val)) === false) {
             return false;
         }
     }
     unset($GLOBALS["SALE_ORDER"]["SALE_ORDER_CACHE_" . $ID]);
     if ($isOrderConverted == "Y") {
         /** @var \Bitrix\Sale\Result $r */
         $r = \Bitrix\Sale\Compatible\OrderCompatibility::reserve($ID, $val);
         if (!$r->isSuccess(true)) {
             foreach ($r->getErrorMessages() as $error) {
                 $errorMessage .= " " . $error;
             }
             $APPLICATION->ThrowException(Loc::getMessage("SKGB_RESERVE_ERROR", array("#MESSAGE#" => $errorMessage)), "RESERVATION_ERROR");
             return false;
         }
         $res = true;
     } else {
         $res = CSaleOrder::Update($ID, array("RESERVED" => $val), false);
         $arRes = CSaleBasket::OrderReservation($ID, $val == "N" ? true : false);
         if (array_key_exists("ERROR", $arRes)) {
             foreach ($arRes["ERROR"] as $arError) {
                 $errorMessage .= " " . $arError["MESSAGE"];
             }
             CSaleOrder::SetMark($ID, Loc::getMessage("SKGB_RESERVE_ERROR", array("#MESSAGE#" => $errorMessage)));
             $APPLICATION->ThrowException(Loc::getMessage("SKGB_RESERVE_ERROR", array("#MESSAGE#" => $errorMessage)), "RESERVATION_ERROR");
             return false;
         } else {
             if ($arOrder["MARKED"] == "Y") {
                 CSaleOrder::UnsetMark($ID);
             }
         }
     }
     foreach (GetModuleEvents("sale", "OnSaleReserveOrder", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $val));
     }
     return $res;
 }
Beispiel #2
0
 function ReserveOrder($ID, $val, $recurringID = 0)
 {
     global $DB, $USER;
     $ID = IntVal($ID);
     $val = $val != "Y" ? "N" : "Y";
     $recurringID = IntVal($recurringID);
     if ($ID <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGO_NO_ORDER_ID"), "NO_ORDER_ID");
         return false;
     }
     $arOrder = CSaleOrder::GetByID($ID);
     if (!$arOrder) {
         $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $ID, GetMessage("SKGO_NO_ORDER")), "NO_ORDER");
         return false;
         //TODO - UnsetMark?
     }
     if ($arOrder["RESERVED"] == $val) {
         $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $ID, GetMessage("SKGO_DUB_RESERVATION")), "ALREADY_FLAG");
         return false;
     }
     foreach (GetModuleEvents("sale", "OnSaleBeforeReserveOrder", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID, $val, $recurringID, $arAdditionalFields)) === false) {
             return false;
         }
     }
     unset($GLOBALS["SALE_ORDER"]["SALE_ORDER_CACHE_" . $ID]);
     if ($recurringID <= 0) {
         if (IntVal($arOrder["RECURRING_ID"]) > 0) {
             $recurringID = IntVal($arOrder["RECURRING_ID"]);
         }
     }
     //TODO - recurring?
     $res = CSaleOrder::Update($ID, array("RESERVED" => $val));
     $arRes = CSaleBasket::OrderReservation($ID, $val == "N" ? true : false, $recurringID);
     if (array_key_exists("ERROR", $arRes)) {
         foreach ($arRes["ERROR"] as $productId => $arError) {
             $errorMessage .= " " . $arError["MESSAGE"];
         }
         CSaleOrder::SetMark($ID, GetMessage("SKGB_RESERVE_ERROR", array("#MESSAGE#" => $errorMessage)));
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGB_RESERVE_ERROR", array("#MESSAGE#" => $errorMessage)), "RESERVATION_ERROR");
         return false;
     } else {
         //don't unset if not set yet
         CSaleOrder::UnsetMark($ID);
     }
     foreach (GetModuleEvents("sale", "OnSaleReserveOrder", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $val));
     }
     return $res;
 }
Beispiel #3
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 = COption::GetOptionString("sale", "product_reserve_clear_period", "0");

		if (intval($days_ago) > 0)
		{
			$date = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time() - intval($days_ago)*24*60*60);

			$arFilter = array(
				"<=DATE_INSERT" => $date,
				"RESERVED" => "Y",
				"DEDUCTED" => "N",
				"PAYED" => "N",
				"ALLOW_DELIVERY" => "N",
				"CANCELED" => "N"
			);

			$dbRes = CSaleOrder::GetList(
				array(),
				$arFilter,
				false,
				false,
				array("ID", "RESERVED", "DATE_INSERT", "DEDUCTED", "PAYED", "CANCELED", "MARKED")
			);
			while ($arRes = $dbRes->GetNext())
			{
				foreach(GetModuleEvents("sale", "OnSaleBeforeReserveOrder", true) as $arEvent)
						if (ExecuteModuleEventEx($arEvent, array($arRes["ID"], "N", $arAdditionalFields))===false)
							return false;

				// undoing reservation
				$res = CSaleBasket::OrderReservation($arRes["ID"], true);

				if (array_key_exists("ERROR", $res))
				{
					foreach ($res["ERROR"] as $productId => $arError)
						$errorMessage .= " ".$arError["MESSAGE"];

					CSaleOrder::SetMark($arRes["ID"], GetMessage("SKGB_RESERVE_ERROR", array("#MESSAGE#" => $errorMessage)));
				}
				else
				{
					if ($arOrder["MARKED"] == "Y")
						CSaleOrder::UnsetMark($arRes["ID"]);
				}

				$res = CSaleOrder::Update($arRes["ID"], array("RESERVED" => "N"), false);

				foreach(GetModuleEvents("sale", "OnSaleReserveOrder", true) as $arEvent)
					ExecuteModuleEventEx($arEvent, Array($arRes["ID"], "N"));
			}
		}

		return "CSaleOrder::ClearProductReservedQuantity();";
	}