コード例 #1
0
ファイル: component.php プロジェクト: ASDAFF/gpbitrix
function getGPDeliveryInput() {
	var name = 'DELIVERY_ID',
		value = 'goparcel:simple',
		inputList = document.getElementsByName(name);
	for (var i = 0, len = inputList.length; i < len; i++) {
		if (inputList[i].value == value) {
			return inputList[i];
		}
	}
	return false;
}
</script>
<?
	$this->IncludeComponentTemplate();
} catch (Exception $e) {
	if (CModule::IncludeModule('getparcel.gpwidget')) { CGPWidget::LogException($e); }
}

// в случае, если форма заказа пошаговая, делаем дополнительную обработку нового заказа для получения ORDER_GP_ID
if($_REQUEST["order"]){
    $arFilter = Array(
       "ACCOUNT_NUMBER" =>$_REQUEST["order"]
    );
    $db_sales = CSaleOrder::GetList(array(), $arFilter);
    while ($ar_sales = $db_sales->Fetch())
    {
        $ID = $ar_sales["ID"];
    }
    
    $MODULE_ID = "getparcel.gpwidget";
    CModule::IncludeModule($MODULE_ID);
コード例 #2
0
ファイル: receive.php プロジェクト: ASDAFF/gpbitrix
							}
						}
					}
					if ($total_price > 0) {
						$total_price = $total_price + $unchanged_total_price + $order['PRICE_DELIVERY'];
						if (!CSaleOrder::Update($order['ID'], array('PRICE' => $total_price), true)) { $error[] = 'could not update order price'; }
					}
					if (count($error) == 0 && count($update) > 0) { $message[] = 'order.goods is updated'; }
					*/
					
				} else { $error[] = 'bitrix order error'; }
			} else { $error[] = 'bitrix delivery_id is not gp'; }
		} else { $error[] = 'invalid order.shop_order_code'; }
	} else { $error[] = 'invalid api_auth_token'; }
}

// $filename = $_SERVER['DOCUMENT_ROOT'] . '/templogrec_output.log';
// $data = array("DATE" => date('d.m.Y h:i:s'), "INPUT" => $raw, "DATA" => $json,/*  "props2" => $props2, "props4" => $props4, */ "RESULT" => $result, "ERRORS" => $error, "MESSAGES" => $message);
// file_put_contents($filename, "\r\n---------------------------------------------------------\r\n".var_export($data, true), FILE_APPEND | LOCK_EX);

if (is_array($error) && count($error) > 0) {
	CModule::IncludeModule('getparcel.gpwidget');
	$error_message = implode(',', $error);
	CGPWidget::LogError($error_message, __FILE__);
}
$result = (is_array($error) && count($error) > 0) ? json_encode(array("error_message" => $error)) : json_encode(array("result" => !empty($message) ? $message : "success"));
echo $result;

// endif;
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
コード例 #3
0
ファイル: options.php プロジェクト: ASDAFF/gpbitrix
		}
		
		// status options
		if (CModule::IncludeModule('sale')) {
			COption::SetOptionString($module_id, "error_status_code", $_REQUEST['error_status_code']);
			$gp_status_list = CGPWidget::GetStatusList();
			foreach ($gp_status_list as $gp_status) {
				$name = "status_match_".$gp_status['CODE'];
				$val = $_REQUEST[$name];
				COption::SetOptionString($module_id, $name, $val);
			}
		}
		
		// payment options
		if (CModule::IncludeModule('sale')) {
			if ($delivery_names = CGPWidget::GetDeliveryNames()) {
				$paysystem_id_res = CSaleDelivery2PaySystem::GetList(array('DELIVERY_ID' => $delivery_names['SID'], 'DELIVERY_PROFILE_ID' => $delivery_names['PROFILE']));
				while ($paysystem_id_ar = $paysystem_id_res->GetNext()) {
					$paysystem_id_list[] = $paysystem_id_ar['PAYSYSTEM_ID'];
				}
				if (is_array($paysystem_id_list) && !empty($paysystem_id_list)) {
					$paysystem_res = CSalePaySystem::GetList(array(), array("ID" => $paysystem_id_list));
					while ($paysystem_ar = $paysystem_res->GetNext()) {
						$name = "paysystem_match_".$paysystem_ar['ID'];
						$val = $_REQUEST[$name];
						COption::SetOptionString($module_id, $name, $val);
					}
				}
			}
		}
	}
コード例 #4
0
ファイル: options_paysystem.php プロジェクト: ASDAFF/gpbitrix
<?
if (CModule::IncludeModule('sale') && CModule::IncludeModule('gpwidget')) {
	if ($delivery_names = CGPWidget::GetDeliveryNames()) {
		$delivery_handler_res = CSaleDeliveryHandler::GetList(array(), array('ACTIVE' => 'Y', 'SID' => $delivery_names['SID']));
		if ($delivery_handler_ar = $delivery_handler_res->GetNext()) {
			if (is_array($delivery_handler_ar['PROFILES']) && !empty($delivery_handler_ar['PROFILES'][$delivery_names['PROFILE']])) {
				$delivery = $delivery_handler_ar;
			}
		}
		if ($delivery) {
			$payment_types = CGPWidget::GetPaymentTypes();
			$paysystem_id_res = CSaleDelivery2PaySystem::GetList(array('DELIVERY_ID' => $delivery['SID'], 'DELIVERY_PROFILE_ID' => $delivery_names['PROFILE']));
			while ($paysystem_id_ar = $paysystem_id_res->GetNext()) {
				$paysystem_id_list[] = $paysystem_id_ar['PAYSYSTEM_ID'];
			}
			if (is_array($paysystem_id_list) && !empty($paysystem_id_list)) {
				$paysystem_res = CSalePaySystem::GetList(array(), array("ID" => $paysystem_id_list));
				while ($paysystem_ar = $paysystem_res->GetNext()):
					$name = "paysystem_match_".$paysystem_ar['ID'];
					$val = COption::GetOptionString("gpwidget", $name);
					?>
					<tr>
						<td width="40%" nowrap>
							<label for="<?php 
echo htmlspecialcharsbx($name);
?>
"><?php 
echo $paysystem_ar['NAME'];
?>
 [<?php 
echo $paysystem_ar['ID'];
コード例 #5
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);
	}