Esempio n. 1
0
					if (($arOldOrder["MARKED"] != $MARKED) || ($arOldOrder["MARKED"] == "Y" && $arOldOrder["REASON_MARKED"] != $REASON_MARKED))
					{
						$bUserCanMarkOrder = CSaleOrder::CanUserMarkOrder($ID, $arUserGroups, $intUserID);

						$errorMessageTmp = "";

						if (!$bUserCanMarkOrder)
						{
							$errorMessageTmp .= GetMessage("SOD_NO_PERMS2MARK").". ";
						}
						else
						{
							if ($MARKED == "Y")
								$rs = CSaleOrder::SetMark($ID, $REASON_MARKED, $intUserID);
							else
								$rs = CSaleOrder::UnsetMark($ID, $intUserID);

							if (!$rs)
							{
								if ($ex = $APPLICATION->GetException())
								{
									if ($ex->GetID() != "ALREADY_FLAG")
										$errorMessageTmp .= $ex->GetString();
								}
								else
									$errorMessageTmp .= GetMessage("ERROR_MARK_ORDER").". ";
							}
						}

						if ($errorMessageTmp != "")
							$arErrors[] = $errorMessageTmp;
Esempio n. 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;
 }
Esempio n. 3
0
		{
			$MARKED = trim($_REQUEST["MARKED"]);
			$REASON_MARKED = trim($_REQUEST["REASON_MARKED"]);
			if ($MARKED != "Y")
				$MARKED = "N";

			if ($MARKED != "Y" && $MARKED != "N")
				$errorMessageTmp .= GetMessage("SOD_WRONG_MARK_FLAG").". ";
		}

		if (strlen($errorMessageTmp) <= 0 && !CSaleOrder::IsLocked($ID, $lockedBY, $dateLock))
		{
			if ($MARKED == "Y")
				$rs = CSaleOrder::SetMark($ID, $REASON_MARKED, (0 < $intUserID ? $intUserID : 0));
			else
				$rs = CSaleOrder::UnsetMark($ID, (0 < $intUserID ? $intUserID : 0));

			if (!$rs)
			{
				if ($ex = $APPLICATION->GetException())
				{
					if ($ex->GetID() != "ALREADY_FLAG")
						$errorMessageTmp .= $ex->GetString();
				}
				else
					$errorMessageTmp .= GetMessage("ERROR_MARK_ORDER").". ";
			}
		}

		$arResult["message"] = "ok";
		if (strlen($errorMessageTmp) > 0)
Esempio n. 4
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;
 }
Esempio n. 5
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();";
	}
Esempio n. 6
0
 $REASON_MARKED = trim($_POST["REASON_MARKED"]);
 if ($MARKED != "Y") {
     $MARKED = "N";
 }
 $arOrder2Update = array();
 if ($arOldOrder["MARKED"] != $MARKED || $arOldOrder["MARKED"] == "Y" && $arOldOrder["REASON_MARKED"] != $REASON_MARKED) {
     $bUserCanMarkOrder = CSaleOrder::CanUserMarkOrder($ID, $GLOBALS["USER"]->GetUserGroupArray(), $GLOBALS["USER"]->GetID());
     $errorMessageTmp = "";
     if (!$bUserCanMarkOrder) {
         $errorMessageTmp .= GetMessage("SOD_NO_PERMS2MARK") . ". ";
     }
     if (strlen($errorMessageTmp) <= 0) {
         if ($MARKED == "Y") {
             $rs = CSaleOrder::SetMark($ID, $REASON_MARKED, intval($GLOBALS["USER"]->GetID()) > 0 ? IntVal($GLOBALS["USER"]->GetID()) : 0);
         } else {
             $rs = CSaleOrder::UnsetMark($ID, intval($GLOBALS["USER"]->GetID()) > 0 ? IntVal($GLOBALS["USER"]->GetID()) : 0);
         }
         if (!$rs) {
             if ($ex = $APPLICATION->GetException()) {
                 if ($ex->GetID() != "ALREADY_FLAG") {
                     $errorMessageTmp .= $ex->GetString();
                 }
             } else {
                 $errorMessageTmp .= GetMessage("ERROR_MARK_ORDER") . ". ";
             }
         }
     }
     if ($errorMessageTmp != "") {
         $arErrors[] = $errorMessageTmp;
     }
 } else {
Esempio n. 7
0
	public function formAndSendDataToGP($type, $options = array(), $arFields) {
		$ID = intVal($options['ID']);
		if ($ID) {
			CModule::IncludeModule('sale');
			$order = CSaleOrder::GetList(array(), array("ID" => $ID), false, false, array("MARKED", "PERSON_TYPE_ID"))->Fetch();
			if ($order['MARKED'] == 'Y') { $order_is_marked = true; } else { $order_is_marked = false; }
			
			if ($arFields['PERSON_TYPE_ID'] > 0) {
				$person_type_id = $arFields['PERSON_TYPE_ID'];
			} elseif ($order['PERSON_TYPE_ID'] > 0) {
				$person_type_id = $order['PERSON_TYPE_ID'];
			}
			
			if ($person_type_id) {
				// get $_POST keys for needed parameters from module options
				/*$keys_list = array(
					'customer_name', 'customer_phone', 'customer_email', 'delivery_address', 'location', 'city',
					'GP_PHONE_ADDITIONAL', 'GP_FLOOR', 'GP_ENTRY', 'GP_INTERCOM_CODE', 'GP_ORDER_ID'
				);*/
                $keys_list = array(
                    'customer_name', 
                    'customer_email', 
                    'customer_phone', 
                    'delivery_city', 
                    'delivery_alt_city',  
                    'delivery_address', 
                    'delivery_address_street', 
                    'delivery_address_house', 
                    'delivery_address_building', 
                    'delivery_address_housing', 
                    'delivery_address_apartment', 
                    'customer_second_phone',  
                    'floor', 
                    'porch', 
                    'intercom_code', 
                    'comments', 
                    //'system_choosen',
                    'gp_order_id_0'
                );
                foreach ($keys_list as $key) {
					$post_key[$key] = COption::GetOptionString(self::$MODULE_ID, 'match_id_'.$person_type_id.'_'.$key);
				}
				$filename = $_SERVER['DOCUMENT_ROOT'] . '/templog.log';
				file_put_contents($filename, var_export($post_key, true), FILE_APPEND | LOCK_EX);
				file_put_contents($filename, var_export($_POST, true), FILE_APPEND | LOCK_EX);
                
                $arOrder = CSaleOrder::GetByID($ID);
                
                if($options["ACTION"] == "ORDER"){
                    //var_dump($arOrder["ACCOUNT_NUMBER"]);die();
                
                    $db_props = CSaleOrderPropsValue::GetOrderProps($ID);
                    $arFields_props = array();
                            
                    while ($arProps = $db_props->Fetch())
                    {
                        $_POST["ORDER_PROP_".$arProps["ORDER_PROPS_ID"]]=$arProps["VALUE"];
                    }
                    $_POST['PAY_SYSTEM_ID'] = $arOrder["PAY_SYSTEM_ID"];
                    
                    $_POST[$post_key['comments']] = $arOrder["USER_DESCRIPTION"];
                }
                
				// get city for delivery_address
				/*if ($_POST[$post_key['delivery_city']]) {
					$city_name = $_POST[$post_key['delivery_city']] . ' ';
				} else*/
                
                if ($_POST[$post_key['delivery_city']] || $_POST['CITY_'.$post_key['delivery_city']]) {
					if ($_POST[$post_key['delivery_city']]) {
						$city_id = $_POST[$post_key['delivery_city']];
					} else {
						$city_id = $_POST['CITY_'.$post_key['delivery_city']];
					}
					$cityRes = CSaleLocation::GetList(
						array(), array("LID" => LANGUAGE_ID, "ID" => $city_id), false, array("nTopCount" => 1), array('CITY_NAME')
					);
					if ($cityAr = $cityRes->Fetch()) {
						$city_name = $cityAr['CITY_NAME'] . ' ';
					} else {
						$city_name = '';
					}
				}
                
                if($_POST[$post_key['delivery_alt_city']]){
                    $city_name = $_POST[$post_key['delivery_alt_city']];
                }
				
				// set parameters
                if($_POST[$post_key['customer_name']]){
	               $post_data['order']['customer_name'] = $_POST[$post_key['customer_name']];
                }
                if($_POST[$post_key['customer_email']]){
	               $post_data['order']['customer_email'] = $_POST[$post_key['customer_email']];
                }elseif($_POST["NEW_BUYER_EMAIL"]){
                    $post_data['order']['customer_email'] = $_POST["NEW_BUYER_EMAIL"];
                }else{
                    //get email from id
                    if($_POST["user_id"]){
                        $user_id = $_POST["user_id"];
                    }else{
                        $user_id = $arOrder["USER_ID"];
                    }
                    $rsUser = CUser::GetByID($user_id);
                    $arUser = $rsUser->Fetch();
                    if($arUser["EMAIL"]){
	                   $post_data['order']['customer_email'] = $arUser["EMAIL"];
                    }
                }
                
                //var_dump($_POST);die();
                
                if($_POST[$post_key['customer_phone']]){
	               $post_data['order']['customer_phone'] = $_POST[$post_key['customer_phone']];
                }
                if($city_name){
	               $post_data['order']['delivery_city'] = $city_name;
                }
                if($_POST[$post_key['delivery_address']] && $_POST[$post_key['delivery_address_street']]){
                    $post_data['order']['delivery_address'] = $_POST[$post_key['delivery_address']].", ".$_POST[$post_key['delivery_address_street']];
				}
                if($_POST[$post_key['delivery_address']] && !$_POST[$post_key['delivery_address_street']]){
                    $post_data['order']['delivery_address'] = $_POST[$post_key['delivery_address']];
				}
                if(!$_POST[$post_key['delivery_address']] && $_POST[$post_key['delivery_address_street']]){
                    $post_data['order']['delivery_address'] = $_POST[$post_key['delivery_address_street']];
				}
                if($_POST[$post_key['delivery_address_house']]){
	               $post_data['order']['delivery_address_house'] = $_POST[$post_key['delivery_address_house']];
                }
                if($_POST[$post_key['delivery_address_building']]){
	               $post_data['order']['delivery_address_building'] = $_POST[$post_key['delivery_address_building']];
                }
                if($_POST[$post_key['delivery_address_housing']]){
	               $post_data['order']['delivery_address_housing'] = $_POST[$post_key['delivery_address_housing']];
                }
                if($_POST[$post_key['delivery_address_apartment']]){
	               $post_data['order']['delivery_address_apartment'] = $_POST[$post_key['delivery_address_apartment']];
                }
                if($_POST[$post_key['customer_second_phone']]){
	               $post_data['order']['customer_second_phone'] = $_POST[$post_key['customer_second_phone']];
                }
                if($_POST[$post_key['floor']]){
	               $post_data['order']['floor'] = $_POST[$post_key['floor']];
                }
                if($_POST[$post_key['porch']]){
	               $post_data['order']['porch'] = $_POST[$post_key['porch']];
                }
                if($_POST[$post_key['intercom_code']]){
	               $post_data['order']['intercom_code'] = $_POST[$post_key['intercom_code']];
                }
                if($_POST[$post_key['comments']]){
	               $post_data['order']['comments'] = $_POST[$post_key['comments']];
                }
                
				//$post_data['order']['comments'] =  $_POST['USER_DESCRIPTION'];
				$post_data['api_auth_token'] = COption::GetOptionString(self::$MODULE_ID, 'secret_key');
				if (isset($options['widget_token']) && $options['widget_token']) { $post_data['order']['widget_token'] = $options['widget_token']; }
				$post_data['order']['widget_token'] = $_POST['widget_token'];
				//$post_data['order']['shop_order_code'] = $ID;
                $post_data['order']['shop_order_code'] = $arOrder["ACCOUNT_NUMBER"];
				//$post_data['order']['customer_name'] = $_POST[$post_key['customer_name']] ? $_POST[$post_key['customer_name']] : ($arFields['ORDER_USER'] ? $arFields['ORDER_USER'] : '');
				//$post_data['order']['customer_phone'] = $_POST[$post_key['customer_phone']];
				//$post_data['order']['customer_email'] = $_POST[$post_key['customer_email']];
				//$post_data['order']['delivery_address'] = $city_name . $_POST[$post_key['delivery_address']];
				//if ($_POST[$post_key['GP_PHONE_ADDITIONAL']]) { $post_data['order']['customer_second_phone'] = $_POST[$post_key['GP_PHONE_ADDITIONAL']]; }
				//if (intVal($_POST[$post_key['GP_FLOOR']])) { $post_data['order']['floor'] = intVal($_POST[$post_key['GP_FLOOR']]); }
				//if ($_POST[$post_key['GP_ENTRY']]) { $post_data['order']['porch'] = $_POST[$post_key['GP_ENTRY']]; }
				//if ($_POST[$post_key['GP_INTERCOM_CODE']]) { $post_data['order']['intercom_code'] = $_POST[$post_key['GP_INTERCOM_CODE']]; }

				$post_data['order']['payment_type'] = COption::GetOptionString(self::$MODULE_ID, 'paysystem_match_'.intVal($_POST['PAY_SYSTEM_ID']));
				
				// set products list for parameters
				if (!isset($_POST['PRODUCT']) || empty($_POST['PRODUCT'])) {
					$products = array();
					$productRes = CSaleBasket::GetList(
						array(), array("ORDER_ID" => $ID), false, false, array('PRODUCT_ID', 'PRICE_DEFAULT', 'PRICE', 'QUANTITY', 'WEIGHT', 'NAME')
					);
					while ($productAr = $productRes->Fetch()) {
						$products[] = $productAr;
					}
				} else {
					$products = $_POST['PRODUCT'];
				}
				
				// set products list parameters
				$cell = 0;
				foreach ($products as $arProduct) {
					// $post_data['order']['good_attributes'][$cell]['size'] = 'medium';
					$post_data['order']['good_attributes'][$cell]['shop_good_code'] = $arProduct['PRODUCT_ID'];
					$post_data['order']['good_attributes'][$cell]['estimated_price'] = $arProduct['PRICE_DEFAULT'];
					$post_data['order']['good_attributes'][$cell]['price'] = $arProduct['PRICE'];
					$post_data['order']['good_attributes'][$cell]['count'] = $arProduct['QUANTITY'];
					$post_data['order']['good_attributes'][$cell]['weight'] = $arProduct['WEIGHT'];
					$post_data['order']['good_attributes'][$cell]['name'] = $arProduct['NAME'];
					$cell++;
				}
			}
		}
		
		// send data to GP server
		if ($options["URL"]) {
		  
		    $arConfig = self::$CONFIG;
            
			$stop_send = false;
			$ch = curl_init();
			
			if (intVal($_POST[$post_key['gp_order_id']]) == 0) {
				$type = "POST";
				//$options["URL"] = COption::GetOptionString(self::$MODULE_ID, 'POST_url');
                $options["URL"] = COption::GetOptionString(self::$MODULE_ID, 'gp_script_url') . $arConfig["POST_URL"];
			}
			
			if ($type == "POST" && !empty($post_data['widget_token'])) {
				$post_data['with_draft'] = true;
			}elseif($type == "POST" && empty($post_data['widget_token'])){
			    $post_data['with_draft'] = false;
			}
			
			// set data for sending to GP server
			$send_data = json_encode($post_data);
            
            			
			if ($type == "POST") {
				curl_setopt($ch, CURLOPT_POST, true);
			} elseif ($type == "PATCH") {
				curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
			} else {
				$stop_send = true;
			}
			curl_setopt($ch, CURLOPT_URL, $options["URL"]);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $send_data);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			if (!$stop_send) {
				$result = json_decode(curl_exec($ch), true);
			}
			curl_close($ch);
            
			if (is_array($result['error_message']) && count($result['error_message']) == 1) {
				$comment = implode("\r\n", $result['error_message']);
                
                $comment = CGPWidget::Translate($comment);
                
				CSaleOrder::SetMark($ID, $comment);
			} elseif (is_array($result['error_message']) && count($result['error_message']) > 1) {
				$comment = $result['error_message'];
                $ar_comment = "";
                
                foreach($comment as $com){
                    $ar_comment .= CGPWidget::Translate($com).". ";
                }
                
				CSaleOrder::SetMark($ID, $ar_comment);
                
			} elseif ($result) {
				if ($order_is_marked) {
					CSaleOrder::UnsetMark($ID);
				}
				if (intVal($_POST[$post_key['gp_order_id_0']]) == 0 && $result['id']/* && intVal($_POST[$post_key['gp_order_id']]) != $result['id']*/) {
					// $_POST[$post_key['gp_order_id']] = $result['id'];
					if ($gp_order_id_prop_id = intVal(str_replace("ORDER_PROP_", "", $post_key['gp_order_id_0']))) {
						$gp_order_id_res = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $ID, "ORDER_PROPS_ID" => $gp_order_id_prop_id));
						if ($gp_order_id_ar = $gp_order_id_res->Fetch()) {
							$gp_order_id_prop_value_id = $gp_order_id_ar['ID'];
							if ($gp_order_id_prop_value_id) {
								$gp_order_id_add_result = CSaleOrderPropsValue::Update($gp_order_id_prop_value_id, array("ORDER_ID" => $ID, "VALUE" => $result['id']));
							}
						} else {
							$gp_order_id_prop_res = CSaleOrderProps::GetList(array(), array("ID" => $gp_order_id_prop_id));
							if ($gp_order_id_prop_ar = $gp_order_id_prop_res->Fetch()) {
								$gp_order_id_add_result = CSaleOrderPropsValue::Add(array("ORDER_ID" => $ID, "ORDER_PROPS_ID" => $gp_order_id_prop_id, "VALUE" => $result['id'], "NAME" => $gp_order_id_prop_ar['NAME'], "CODE" => $gp_order_id_prop_ar['CODE']));
							}
						}
					}
				}
			}
            /*
            echo "<pre>";
            var_dump($_POST);
            
            var_dump($post_data);
            
            var_dump($result);
            echo "</pre>";
            die();*/
		}

		// log everything
		$filename = $_SERVER['DOCUMENT_ROOT'] . '/templog.log';
		$data = array($type, date('d.m.Y h:i:s'), "ORDER" => $ID, "URL" => $options["URL"], "SEND" => $send_data, "RESULT" => $result, "ARFIELDS" => $arFields);
		// $data = array($type, date('d.m.Y h:i:s'), "ORDER" => $ID, "URL" => $options["URL"], "SEND" => $send_data, "gpid" => array('add' => $m, 'res' => $gp_order_id_add_result, '1' => array($gp_order_id_prop_value_id, array("ORDER_ID" => $ID, "VALUE" => $result['id'])),  'ar' => $gp_order_id_ar, 'val' => $gp_order_id_prop_value_id, 'post_gpoid' => $result['id'], "ORDER_ID" => $ID, 'ORDER_PROPS_ID' => str_replace("ORDER_PROP_", "", $post_key['gp_order_id'])), array($_POST[$post_key['gp_order_id']], $post_key['gp_order_id']), "RESULT" => $result);
		// $data = array($type, date('d.m.Y h:i:s'), $ID, $send_data, $result, $city_name, $city_id, $post_key, $_POST);
		file_put_contents($filename, var_export($data, true), FILE_APPEND | LOCK_EX);
	}