static function DoSaveUserProfile($userId, $profileId, $profileName, $personTypeId, $orderProps, &$arErrors) { $profileId = intval($profileId); $arIDs = array(); if ($profileId > 0) { $dbProfile = CSaleOrderUserProps::GetList(array(), array("ID" => $profileId), false, false, array("ID", "NAME", "USER_ID", "PERSON_TYPE_ID")); $arProfile = $dbProfile->Fetch(); if (!$arProfile) { $arErrors[] = array("CODE" => "PROFILE_NOT_FOUND", "TEXT" => GetMessage('SKGOUP_PROFILE_NOT_FOUND')); return false; } if ($arProfile["USER_ID"] != $userId || $arProfile["PERSON_TYPE_ID"] != $personTypeId) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGOUP_PARRAMS_ERROR')); return false; } //if (strlen($profileName) > 0 && $profileName != $arProfile["NAME"]) if (strlen($profileName) > 0) { $arFields = array("NAME" => $profileName, "USER_ID" => $userId); CSaleOrderUserProps::Update($profileId, $arFields); } $dbUserPropsValues = CSaleOrderUserPropsValue::GetList(array(), array("USER_PROPS_ID" => $profileId), false, false, array("ID", "ORDER_PROPS_ID")); while ($arUserPropsValue = $dbUserPropsValues->Fetch()) { $arIDs[$arUserPropsValue["ORDER_PROPS_ID"]] = $arUserPropsValue["ID"]; } } if (!is_array($orderProps)) { $dbOrderPropsValues = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => intval($orderProps)), false, false, array("ORDER_PROPS_ID", "VALUE")); $orderProps = array(); while ($arOrderPropsValue = $dbOrderPropsValues->Fetch()) { $orderProps[$arOrderPropsValue["ORDER_PROPS_ID"]] = $arOrderPropsValue["VALUE"]; } } $dbOrderProperties = CSaleOrderProps::GetList(array(), array("PERSON_TYPE_ID" => $personTypeId, "ACTIVE" => "Y", "UTIL" => "N", "USER_PROPS" => "Y"), false, false, array("ID", "TYPE", "NAME", "CODE")); while ($arOrderProperty = $dbOrderProperties->Fetch()) { $curVal = $orderProps[$arOrderProperty["ID"]]; if ($arOrderProperty["TYPE"] == "MULTISELECT" && is_array($curVal)) { $curVal = implode(",", $curVal); } if (strlen($curVal) > 0) { if ($profileId <= 0) { if (strlen($profileName) <= 0) { $profileName = GetMessage("SOA_PROFILE") . " " . Date("Y-m-d"); } $arFields = array("NAME" => $profileName, "USER_ID" => $userId, "PERSON_TYPE_ID" => $personTypeId); $profileId = CSaleOrderUserProps::Add($arFields); } if (array_key_exists($arOrderProperty["ID"], $arIDs)) { $arFields = array("NAME" => $arOrderProperty["NAME"], "VALUE" => $curVal); CSaleOrderUserPropsValue::Update($arIDs[$arOrderProperty["ID"]], $arFields); unset($arIDs[$arOrderProperty["ID"]]); } else { $arFields = array("USER_PROPS_ID" => $profileId, "ORDER_PROPS_ID" => $arOrderProperty["ID"], "NAME" => $arOrderProperty["NAME"], "VALUE" => $curVal); CSaleOrderUserPropsValue::Add($arFields); } } } foreach ($arIDs as $id) { CSaleOrderUserPropsValue::Delete($id); } }
} elseif ($arOrderProps["TYPE"] == "MULTISELECT") { if (!is_array($curVal) || count($curVal) <= 0) $bErrorField = true; } } if ($bErrorField) $errorMessage .= GetMessage("SALE_NO_FIELD")." \"".$arOrderProps["NAME"]."\".<br />"; } } if (strlen($errorMessage) <= 0) { $arFields = array("NAME" => $NAME); if (!CSaleOrderUserProps::Update($ID, $arFields)) $errorMessage .= GetMessage("SALE_ERROR_EDIT_PROF")."<br />"; } if (strlen($errorMessage) <= 0) { CSaleOrderUserPropsValue::DeleteAll($ID); $dbOrderProps = CSaleOrderProps::GetList( array("SORT" => "ASC", "NAME" => "ASC"), array( "PERSON_TYPE_ID" => $arUserProps["PERSON_TYPE_ID"], "USER_PROPS" => "Y", "ACTIVE" => "Y", "UTIL" => "N" ), false, false,
static function Update($profileID, $arFields) { global $DB; $result = new WS_SaleUserProfilesErrorsContainer(); if (empty($profileID)) { return $result->addErrorString(GetMessage("ws.saleuserprofiles_save_error_required_id")); } $DB->StartTransaction(); if (!empty($arFields["PROPS"])) { $props = $arFields["PROPS"]; unset($arFields["PROPS"]); } // ΡΠΎΡ ΡΠ°Π½ΡΠ΅ΠΌ ΠΏΠΎΠ»Ρ if (!empty($arFields)) { if(!$profileID = CSaleOrderUserProps::Update($profileID, $arFields)){ $result->addErrorString(GetMessage("ws.saleuserprofiles_save_error_save_fields")); } else { $arFields = CSaleOrderUserProps::GetByID($profileID); } } // ΡΠΎΡ ΡΠ°Π½ΡΠ΅ΠΌ ΡΠ²ΠΎΠΉΡΡΠ²Π° if (!empty($props) && !$result->getErrorsAsString()) { // ΡΠ΄Π°Π»ΡΠ΅ΠΌ Π²ΡΠ΅ ΡΠ²ΠΎΠΉΡΡΠ²Π° CSaleOrderUserPropsValue::DeleteAll($profileID); $res = CSaleOrderProps::GetList(array(), array("PERSON_TYPE_ID" => $arFields["PERSON_TYPE_ID"], "USER_PROPS" => "Y"), false, false, array()); while ($arRes = $res->Fetch()) { if ($arRes['REQUIED'] === 'Y' && empty($props[$arRes['ID']])) { $result->addErrorString(GetMessage("ws.saleuserprofiles_save_error_required_field") . "\"" . $arRes["NAME"] . "\""); continue; } $arValueTemp = $props[$arRes['ID']]; if (is_array($arValueTemp)) { $arValueTemp = ""; for ($i = 0; $i < count($props[$arRes['ID']]); $i++) { if ($i > 0) { $arValueTemp .= ","; } $arValueTemp .= $props[$arRes['ID']][$i]; } } $arProp = array( "VALUE" => $arValueTemp, "NAME" => $arRes["NAME"], "ORDER_PROPS_ID" => $arRes['ID'], "USER_PROPS_ID" => $profileID ); CSaleOrderUserPropsValue::Add($arProp); } } if ($result->getErrorsAsString()) { $DB->Rollback(); } else { $DB->Commit(); } return $result; }
function nodeHandler(CDataXML $value) { $value = $value->GetArray(); if(!empty($value[GetMessage("CC_BSC1_DOCUMENT")])) { $value = $value[GetMessage("CC_BSC1_DOCUMENT")]; $arOrder = $this->collectOrderInfo($value); if(!empty($arOrder)) { if(strlen($arOrder["ID"]) <= 0 && strlen($arOrder["ID_1C"]) > 0)//try to search order from 1C { $dbOrder = CSaleOrder::GetList(array("ID" => "DESC"), array("ID_1C" => $arOrder["ID_1C"]), false, false, array("ID", "ID_1C")); if($orderInfo = $dbOrder->Fetch()) { $arOrder["ID"] = $orderInfo["ID"]; } } if(strlen($arOrder["ID"]) > 0) // exists site order { $dbOrder = CSaleOrder::GetList(array(), array("ACCOUNT_NUMBER" => $arOrder["ID"]), false, false, array("ID", "LID", "PERSON_TYPE_ID", "PAYED", "DATE_PAYED", "CANCELED", "DATE_CANCELED", "REASON_CANCELED", "STATUS_ID", "DATE_STATUS", "PAY_VOUCHER_NUM", "PAY_VOUCHER_DATE", "PRICE_DELIVERY", "ALLOW_DELIVERY", "DATE_ALLOW_DELIVERY", "PRICE", "CURRENCY", "DISCOUNT_VALUE", "USER_ID", "PAY_SYSTEM_ID", "DELIVERY_ID", "DATE_INSERT", "DATE_INSERT_FORMAT", "DATE_UPDATE", "USER_DESCRIPTION", "ADDITIONAL_INFO", "COMMENTS", "TAX_VALUE", "DELIVERY_DOC_NUM", "DELIVERY_DOC_DATE", "STORE_ID", "ACCOUNT_NUMBER", "VERSION", "VERSION_1C", "ID_1C")); if($orderInfo = $dbOrder->Fetch()) { if($arOrder["VERSION_1C"] != $orderInfo["VERSION_1C"] || (strlen($orderInfo["VERSION_1C"]) <= 0 || strlen($arOrder["VERSION_1C"]) <= 0)) // skip update if the same version { $arOrderFields = array(); $orderId = $orderInfo["ID"]; CSaleOrderChange::AddRecord($orderId, "ORDER_1C_IMPORT"); if($arOrder["ID_1C"] != $orderInfo["ID_1C"]) $arOrderFields["ID_1C"] = $arOrder["ID_1C"]; $arOrderFields["VERSION_1C"] = $arOrder["VERSION_1C"]; if($orderInfo["PAYED"] != "Y" && $orderInfo["ALLOW_DELIVERY"] != "Y" && $orderInfo["STATUS_ID"] != "F") { $dbOrderTax = CSaleOrderTax::GetList( array(), array("ORDER_ID" => $orderId), false, false, array("ID", "TAX_NAME", "VALUE", "VALUE_MONEY", "CODE", "IS_IN_PRICE") ); $bTaxFound = false; if($arOrderTax = $dbOrderTax->Fetch()) { $bTaxFound = true; if(IntVal($arOrderTax["VALUE_MONEY"]) != IntVal($arOrder["TAX"]["VALUE_MONEY"]) || IntVal($arOrderTax["VALUE"]) != IntVal($arOrder["TAX"]["VALUE"]) || ($arOrderTax["IS_IN_PRICE"] != $arOrder["TAX"]["IS_IN_PRICE"])) { if(IntVal($arOrder["TAX"]["VALUE"])>0) { $arFields = Array( "TAX_NAME" => $arOrder["TAX"]["NAME"], "ORDER_ID" => $orderId, "VALUE" => $arOrder["TAX"]["VALUE"], "IS_PERCENT" => "Y", "IS_IN_PRICE" => $arOrder["TAX"]["IS_IN_PRICE"], "VALUE_MONEY" => $arOrder["TAX"]["VALUE_MONEY"], "CODE" => "VAT1C", "APPLY_ORDER" => "100" ); CSaleOrderTax::Update($arOrderTax["ID"], $arFields); $arOrderFields["TAX_VALUE"] = $arOrder["TAX"]["VALUE_MONEY"]; } else { CSaleOrderTax::Delete($arOrderTax["ID"]); $arOrderFields["TAX_VALUE"] = 0; } } } if(!$bTaxFound) { if(IntVal($arOrder["TAX"]["VALUE"])>0) { $arFields = Array( "TAX_NAME" => $arOrder["TAX"]["NAME"], "ORDER_ID" => $orderId, "VALUE" => $arOrder["TAX"]["VALUE"], "IS_PERCENT" => "Y", "IS_IN_PRICE" => $arOrder["TAX"]["IS_IN_PRICE"], "VALUE_MONEY" => $arOrder["TAX"]["VALUE_MONEY"] ); CSaleOrderTax::Add($arFields); $arOrderFields["TAX_VALUE"] = $arOrder["TAX"]["VALUE_MONEY"]; } } $arShoppingCart = array(); $bNeedUpdate = false; $dbBasket = CSaleBasket::GetList( array("NAME" => "ASC"), array("ORDER_ID" => $orderId), false, false, array( "ID", "QUANTITY", "CANCEL_CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "PRODUCT_PROVIDER_CLASS", "RESERVED", "RESERVE_QUANTITY", "TYPE", "SET_PARENT_ID", "PRICE", "VAT_RATE", "DISCOUNT_PRICE", "PRODUCT_XML_ID", ) ); while ($arBasket = $dbBasket->Fetch()) { $arFields = Array(); if(!empty($arOrder["items"][$arBasket["PRODUCT_XML_ID"]])) { if($arBasket["QUANTITY"] != $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["QUANTITY"]) $arFields["QUANTITY"] = $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["QUANTITY"]; if($arBasket["PRICE"] != $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["PRICE"]) $arFields["PRICE"] = $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["PRICE"]; if($arBasket["VAT_RATE"] != $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["VAT_RATE"]) $arFields["VAT_RATE"] = $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["VAT_RATE"]; if($arBasket["DISCOUNT_PRICE"] != $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["DISCOUNT_PRICE"]) $arFields["DISCOUNT_PRICE"] = $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["DISCOUNT_PRICE"]; if(count($arFields)>0) { $arFields["ID"] = $arBasket["ID"]; if(DoubleVal($arFields["QUANTITY"]) <= 0) $arFields["QUANTITY"] = $arBasket["QUANTITY"]; $bNeedUpdate = true; $arShoppingCart[] = $arFields; } else { $arShoppingCart[] = $arBasket; } //CSaleBasket::Update($arBasket["ID"], $arFields); $arOrder["items"][$arBasket["PRODUCT_XML_ID"]]["CHECKED"] = "Y"; } else { if($arOrder["TRAITS"][GetMessage("CC_BSC1_CANCELED")] != "true" && $orderInfo["CANCELED"] == "N") { $bNeedUpdate = true; //CSaleBasket::Delete($arBasket["ID"]); } } } if(!empty($arOrder["items"])) { foreach ($arOrder["items"] as $itemID => $arItem) { if ($arItem["CHECKED"] != "Y") { if ($arItem["TYPE"] == GetMessage("CC_BSC1_ITEM")) { if ($arBasketFields = $this->prepareProduct4Basket($itemID, $arItem, $orderId, $orderInfo)) { $arShoppingCart[] = $arBasketFields; $bNeedUpdate = true; } } elseif ($arItem["TYPE"] == GetMessage("CC_BSC1_SERVICE")) { if (IntVal($arItem["PRICE"]) != IntVal($orderInfo["PRICE_DELIVERY"])) $arOrderFields["PRICE_DELIVERY"] = $arItem["PRICE"]; } } } } if($bNeedUpdate) { $arErrors = array(); CSaleBasket::DoSaveOrderBasket($orderId, $orderInfo["LID"], $orderInfo["USER_ID"], $arShoppingCart, $arErrors); } if(DoubleVal($arOrder["AMOUNT"]) > 0 && $arOrder["AMOUNT"] != $orderInfo["PRICE"]) $arOrderFields["PRICE"] = $arOrder["AMOUNT"]; if(DoubleVal($orderInfo["DISCOUNT_VALUE"]) > 0) $arOrderFields["DISCOUNT_VALUE"] = 0; if(strlen($arOrder["COMMENT"]) > 0 && $arOrder["COMMENT"] != $orderInfo["COMMENTS"]) $arOrderFields["COMMENTS"] = $arOrder["COMMENT"]; $arOrderFields["UPDATED_1C"] = "Y"; if(!empty($arOrderFields)) CSaleOrder::Update($orderId, $arOrderFields); } else { $this->strError .= "\n".GetMessage("CC_BSC1_FINAL_NOT_EDIT", Array("#ID#" => $orderId)); } } $arAditFields = Array(); if($arOrder["TRAITS"][GetMessage("CC_BSC1_CANCELED")] == "true") { if($orderInfo["CANCELED"] == "N") CSaleOrder::CancelOrder($orderInfo["ID"], "Y", $arOrder["COMMENT"]); $arAditFields["UPDATED_1C"] = "Y"; } else { if(strlen($arOrder["TRAITS"][GetMessage("CC_BSC1_1C_PAYED_DATE")])>1) { if($orderInfo["PAYED"]=="N") CSaleOrder::PayOrder($orderInfo["ID"], "Y"); $arAditFields["PAY_VOUCHER_DATE"] = CDatabase::FormatDate(str_replace("T", " ", $arOrder["TRAITS"][GetMessage("CC_BSC1_1C_PAYED_DATE")]), "YYYY-MM-DD HH:MI:SS", CLang::GetDateFormat("FULL", LANG)); if(strlen($arOrder["TRAITS"][GetMessage("CC_BSC1_1C_PAYED_NUM")])>0) $arAditFields["PAY_VOUCHER_NUM"] = $arOrder["TRAITS"][GetMessage("CC_BSC1_1C_PAYED_NUM")]; $arAditFields["UPDATED_1C"] = "Y"; } if(strlen($arOrder["TRAITS"][GetMessage("CC_BSC1_1C_DELIVERY_DATE")])>1) { if($orderInfo["ALLOW_DELIVERY"]=="N") CSaleOrder::DeliverOrder($orderInfo["ID"], "Y"); $arAditFields["DATE_ALLOW_DELIVERY"] = CDatabase::FormatDate(str_replace("T", " ", $arOrder["TRAITS"][GetMessage("CC_BSC1_1C_DELIVERY_DATE")]), "YYYY-MM-DD HH:MI:SS", CLang::GetDateFormat("FULL", LANG)); if(strlen($this->arParams["FINAL_STATUS_ON_DELIVERY"])>0 && $orderInfo["STATUS_ID"] != "F" && $orderInfo["STATUS_ID"] != $this->arParams["FINAL_STATUS_ON_DELIVERY"]) CSaleOrder::StatusOrder($orderInfo["ID"], $this->arParams["FINAL_STATUS_ON_DELIVERY"]); $arAditFields["UPDATED_1C"] = "Y"; } } if(count($arAditFields)>0) CSaleOrder::Update($orderInfo["ID"], $arAditFields); } else $this->strError .= "\n".GetMessage("CC_BSC1_ORDER_NOT_FOUND", Array("#ID#" => $arOrder["ID"])); } elseif($this->arParams["IMPORT_NEW_ORDERS"] == "Y") // create new order (ofline 1C) { if(!empty($arOrder["AGENT"]) && strlen($arOrder["AGENT"]["ID"]) > 0) { $arOrder["PERSON_TYPE_ID"] = 0; $arOrder["USER_ID"] = 0; $arErrors = array(); $dbUProp = CSaleOrderUserProps::GetList(array(), array("XML_ID" => $arOrder["AGENT"]["ID"]), false, false, array("ID", "NAME", "USER_ID", "PERSON_TYPE_ID", "XML_ID", "VERSION_1C")); if($arUProp = $dbUProp->Fetch()) { $arOrder["USER_ID"] = $arUProp["USER_ID"]; $arOrder["PERSON_TYPE_ID"] = $arUProp["PERSON_TYPE_ID"]; $arOrder["USER_PROFILE_ID"] = $arUProp["ID"]; $arOrder["USER_PROFILE_VERSION"] = $arUProp["VERSION_1C"]; $dbUPropValue = CSaleOrderUserPropsValue::GetList(array(), array("USER_PROPS_ID" => $arUProp["ID"])); while($arUPropValue = $dbUPropValue->Fetch()) { $arOrder["USER_PROPS"][$arUPropValue["ORDER_PROPS_ID"]] = $arUPropValue["VALUE"]; } } else { if(strlen($arOrder["AGENT"]["ID"]) > 0) { $arAI = explode("#", $arOrder["AGENT"]["ID"]); if(IntVal($arAI[0]) > 0) { $dbUser = CUser::GetByID($arAI[0]); if($arU = $dbUser->Fetch()) { if(htmlspecialcharsback(substr(htmlspecialcharsbx($arU["ID"]."#".$arU["LOGIN"]."#".$arU["LAST_NAME"]." ".$arU["NAME"]." ".$arU["SECOND_NAME"]), 0, 80)) == $arOrder["AGENT"]["ID"]) { $arOrder["USER_ID"] = $arU["ID"]; } } } } if(IntVal($arOrder["USER_ID"]) <= 0) { //create new user $arUser = array( "NAME" => $arOrder["AGENT"]["ITEM_NAME"], "EMAIL" => $arOrder["AGENT"]["CONTACT"]["MAIL_NEW"], ); if (strlen($arUser["NAME"]) <= 0) $arUser["NAME"] = $arOrder["AGENT"]["CONTACT"]["CONTACT_PERSON"]; if (strlen($arUser["EMAIL"]) <= 0) $arUser["EMAIL"] = "buyer".time().GetRandomCode(2)."@".$_SERVER["SERVER_NAME"]; $arOrder["USER_ID"] = CSaleUser::DoAutoRegisterUser($arUser["EMAIL"], $arUser["NAME"], $this->arParams["SITE_NEW_ORDERS"], $arErrors); } } if(empty($this->arPersonTypesIDs)) { $dbPT = CSalePersonType::GetList(array(), array("ACTIVE" => "Y", "LIDS" => $this->arParams["SITE_NEW_ORDERS"])); while($arPT = $dbPT->Fetch()) { $this->arPersonTypesIDs[] = $arPT["ID"]; } } if(empty($this->arExportInfo)) { $dbExport = CSaleExport::GetList(array(), array("PERSON_TYPE_ID" => $this->arPersonTypesIDs)); while($arExport = $dbExport->Fetch()) { $this->arExportInfo[$arExport["PERSON_TYPE_ID"]] = unserialize($arExport["VARS"]); } } if(IntVal($arOrder["PERSON_TYPE_ID"]) <= 0) { foreach($this->arExportInfo as $pt => $value) { if( (($value["IS_FIZ"] == "Y" && $arOrder["AGENT"]["TYPE"] == "FIZ") || ($value["IS_FIZ"] == "N" && $arOrder["AGENT"]["TYPE"] != "FIZ")) ) $arOrder["PERSON_TYPE_ID"] = $pt; } } if(IntVal($arOrder["PERSON_TYPE_ID"]) > 0) { $arAgent = $this->arExportInfo[$arOrder["PERSON_TYPE_ID"]]; foreach($arAgent as $k => $v) { if((strlen($v["VALUE"]) <= 0 || $v["TYPE"] != "PROPERTY") && (empty($arOrder["USER_PROPS"]) || empty($arOrder["USER_PROPS"][$v["VALUE"]]))) unset($arAgent[$k]); } if(IntVal($arOrder["USER_ID"]) > 0) { $orderFields = array( "SITE_ID" => $this->arParams["SITE_NEW_ORDERS"], "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"], "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE" => $arOrder["AMOUNT"], "CURRENCY" => CSaleLang::GetLangCurrency($this->arParams["SITE_NEW_ORDERS"]), "USER_ID" => $arOrder["USER_ID"], "TAX_VALUE" => doubleval($arOrder["TAX"]["VALUE_MONEY"]), "COMMENTS" => $arOrder["COMMENT"], "BASKET_ITEMS" => array(), "TAX_LIST" => array(), "ORDER_PROP" => array(), ); $arAditFields = array( "EXTERNAL_ORDER" => "Y", "ID_1C" => $arOrder["ID_1C"], "VERSION_1C" => $arOrder["VERSION_1C"], "UPDATED_1C" => "Y", "DATE_INSERT" => CDatabase::FormatDate($arOrder["DATE"]." ".$arOrder["TIME"], "YYYY-MM-DD HH:MI:SS", CLang::GetDateFormat("FULL", LANG)), ); foreach($arOrder["items"] as $productID => $val) { $orderFields["BASKET_ITEMS"][] = $this->prepareProduct4Basket($productID, $val, false, $orderFields); } if(!empty($arOrder["TAX"])) { $orderFields["TAX_LIST"][] = array( "NAME" => $arOrder["TAX"]["NAME"], "IS_PERCENT" => "Y", "VALUE" => $arOrder["TAX"]["VALUE"], "VALUE_MONEY" => $arOrder["TAX"]["VALUE_MONEY"], "IS_IN_PRICE" => $arOrder["TAX"]["IS_IN_PRICE"], ); } foreach($arAgent as $k => $v) { if(!empty($arOrder["ORDER_PROPS"][$k])) { $orderFields["ORDER_PROP"][$v["VALUE"]] = $arOrder["ORDER_PROPS"][$k]; } if(empty($orderFields["ORDER_PROP"][$v["VALUE"]]) && !empty($arOrder["USER_PROPS"][$v["VALUE"]])) { $orderFields["ORDER_PROP"][$v["VALUE"]] = $arOrder["USER_PROPS"][$v["VALUE"]]; } } if($arOrder["ID"] = CSaleOrder::DoSaveOrder($orderFields, $arAditFields, 0, $arErrors)) { $arAditFields = array("UPDATED_1C" => "Y"); CSaleOrder::Update($arOrder["ID"], $arAditFields); //add/update user profile if(IntVal($arOrder["USER_PROFILE_ID"]) > 0) { if($arOrder["USER_PROFILE_VERSION"] != $arOrder["AGENT"]["VERSION"]) CSaleOrderUserProps::Update($arOrder["USER_PROFILE_ID"], array("VERSION_1C" => $arOrder["AGENT"]["VERSION"], "NAME" => $arOrder["AGENT"]["AGENT_NAME"])); $dbUPV = CSaleOrderUserPropsValue::GetList(array(), array("USER_PROPS_ID" =>$arOrder["USER_PROFILE_ID"])); while($arUPV = $dbUPV->Fetch()) { $arOrder["AGENT"]["PROFILE_PROPS_VALUE"][$arUPV["ORDER_PROPS_ID"]] = array("ID" => $arUPV["ID"], "VALUE" => $arUPV["VALUE"]); } } if(IntVal($arOrder["USER_PROFILE_ID"]) <= 0 || (IntVal($arOrder["USER_PROFILE_ID"]) > 0 && $arOrder["USER_PROFILE_VERSION"] != $arOrder["AGENT"]["VERSION"])) { $dbOrderProperties = CSaleOrderProps::GetList( array("SORT" => "ASC"), array( "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"], "ACTIVE" => "Y", "UTIL" => "N", "USER_PROPS" => "Y", ), false, false, array("ID", "TYPE", "NAME", "CODE", "USER_PROPS", "SORT", "MULTIPLE") ); while ($arOrderProperties = $dbOrderProperties->Fetch()) { $curVal = $orderFields["ORDER_PROP"][$arOrderProperties["ID"]]; if (strlen($curVal) > 0) { if (IntVal($arOrder["USER_PROFILE_ID"]) <= 0) { $arFields = array( "NAME" => $arOrder["AGENT"]["AGENT_NAME"], "USER_ID" => $arOrder["USER_ID"], "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"], "XML_ID" => $arOrder["AGENT"]["ID"], "VERSION_1C" => $arOrder["AGENT"]["VERSION"], ); $arOrder["USER_PROFILE_ID"] = CSaleOrderUserProps::Add($arFields); } if(IntVal($arOrder["USER_PROFILE_ID"]) > 0) { $arFields = array( "USER_PROPS_ID" => $arOrder["USER_PROFILE_ID"], "ORDER_PROPS_ID" => $arOrderProperties["ID"], "NAME" => $arOrderProperties["NAME"], "VALUE" => $curVal ); if(empty($arOrder["AGENT"]["PROFILE_PROPS_VALUE"][$arOrderProperties["ID"]])) { CSaleOrderUserPropsValue::Add($arFields); } elseif($arOrder["AGENT"]["PROFILE_PROPS_VALUE"][$arOrderProperties["ID"]]["VALUE"] != $curVal) { CSaleOrderUserPropsValue::Update($arOrder["AGENT"]["PROFILE_PROPS_VALUE"][$arOrderProperties["ID"]]["ID"], $arFields); } } } } } } else { $this->strError .= "\n".GetMessage("CC_BSC1_ORDER_ADD_PROBLEM", Array("#ID#" => $arOrder["ID_1C"])); } } else { $this->strError .= "\n".GetMessage("CC_BSC1_ORDER_USER_PROBLEM", Array("#ID#" => $arOrder["ID_1C"])); if(!empty($arErrors)) { foreach($arErrors as $v) { $this->strError .= "\n".$v["TEXT"]; } } } } else { $this->strError .= "\n".GetMessage("CC_BSC1_ORDER_PERSON_TYPE_PROBLEM", Array("#ID#" => $arOrder["ID_1C"])); } } else { $this->strError .= "\n".GetMessage("CC_BSC1_ORDER_NO_AGENT_ID", Array("#ID#" => $arOrder["ID_1C"])); } } } } elseif($this->arParams["IMPORT_NEW_ORDERS"] == "Y") { $value = $value[GetMessage("CC_BSC1_AGENT")]["#"]; $arAgentInfo = $this->collectAgentInfo($value); if(!empty($arAgentInfo["AGENT"])) { $mode = false; $arErrors = array(); $dbUProp = CSaleOrderUserProps::GetList(array(), array("XML_ID" => $arAgentInfo["AGENT"]["ID"]), false, false, array("ID", "NAME", "USER_ID", "PERSON_TYPE_ID", "XML_ID", "VERSION_1C")); if($arUProp = $dbUProp->Fetch()) { if($arUProp["VERSION_1C"] != $arAgentInfo["AGENT"]["VERSION"]) { $mode = "update"; $arAgentInfo["PROFILE_ID"] = $arUProp["ID"]; $arAgentInfo["PERSON_TYPE_ID"] = $arUProp["PERSON_TYPE_ID"]; } } else { $arUser = array( "NAME" => $arAgentInfo["AGENT"]["ITEM_NAME"], "EMAIL" => $arAgentInfo["AGENT"]["CONTACT"]["MAIL_NEW"], ); if(strlen($arUser["NAME"]) <= 0) $arUser["NAME"] = $arAgentInfo["AGENT"]["CONTACT"]["CONTACT_PERSON"]; $emServer = $_SERVER["SERVER_NAME"]; if(strpos($_SERVER["SERVER_NAME"], ".") === false) $emServer .= ".bx"; if(strlen($arUser["EMAIL"]) <= 0) $arUser["EMAIL"] = "buyer".time().GetRandomCode(2)."@".$emServer; $arAgentInfo["USER_ID"] = CSaleUser::DoAutoRegisterUser($arUser["EMAIL"], $arUser["NAME"], $this->arParams["SITE_NEW_ORDERS"], $arErrors); if(IntVal($arAgentInfo["USER_ID"]) > 0) { $mode = "add"; } else { $this->strError .= "\n".GetMessage("CC_BSC1_AGENT_USER_PROBLEM", Array("#ID#" => $arAgentInfo["AGENT"]["ID"])); if(!empty($arErrors)) { foreach($arErrors as $v) { $this->strError .= "\n".$v["TEXT"]; } } } } if($mode) { if(empty($this->arPersonTypesIDs)) { $dbPT = CSalePersonType::GetList(array(), array("ACTIVE" => "Y", "LIDS" => $this->arParams["SITE_NEW_ORDERS"])); while($arPT = $dbPT->Fetch()) { $this->arPersonTypesIDs[] = $arPT["ID"]; } } if(empty($this->arExportInfo)) { $dbExport = CSaleExport::GetList(array(), array("PERSON_TYPE_ID" => $this->arPersonTypesIDs)); while($arExport = $dbExport->Fetch()) { $this->arExportInfo[$arExport["PERSON_TYPE_ID"]] = unserialize($arExport["VARS"]); } } if(IntVal($arAgentInfo["PERSON_TYPE_ID"]) <= 0) { foreach($this->arExportInfo as $pt => $value) { if(($value["IS_FIZ"] == "Y" && $arAgentInfo["AGENT"]["TYPE"] == "FIZ") || ($value["IS_FIZ"] == "N" && $arAgentInfo["AGENT"]["TYPE"] != "FIZ") ) $arAgentInfo["PERSON_TYPE_ID"] = $pt; } } if(IntVal($arAgentInfo["PERSON_TYPE_ID"]) > 0) { $arAgentInfo["ORDER_PROPS_VALUE"] = array(); $arAgentInfo["PROFILE_PROPS_VALUE"] = array(); $arAgent = $this->arExportInfo[$arAgentInfo["PERSON_TYPE_ID"]]; foreach($arAgent as $k => $v) { if(strlen($v["VALUE"]) <= 0 || $v["TYPE"] != "PROPERTY") unset($arAgent[$k]); } foreach($arAgent as $k => $v) { if(!empty($arAgentInfo["ORDER_PROPS"][$k])) $arAgentInfo["ORDER_PROPS_VALUE"][$v["VALUE"]] = $arAgentInfo["ORDER_PROPS"][$k]; } if (IntVal($arAgentInfo["PROFILE_ID"]) > 0) { CSaleOrderUserProps::Update($arUProp["ID"], array("VERSION_1C" => $arAgentInfo["AGENT"]["VERSION"], "NAME" => $arAgentInfo["AGENT"]["AGENT_NAME"])); $dbUPV = CSaleOrderUserPropsValue::GetList(array(), array("USER_PROPS_ID" => $arAgentInfo["PROFILE_ID"])); while($arUPV = $dbUPV->Fetch()) { $arAgentInfo["PROFILE_PROPS_VALUE"][$arUPV["ORDER_PROPS_ID"]] = array("ID" => $arUPV["ID"], "VALUE" => $arUPV["VALUE"]); } } if(empty($this->arOrderProps[$arAgentInfo["PERSON_TYPE_ID"]])) { $dbOrderProperties = CSaleOrderProps::GetList( array("SORT" => "ASC"), array( "PERSON_TYPE_ID" => $arAgentInfo["PERSON_TYPE_ID"], "ACTIVE" => "Y", "UTIL" => "N", "USER_PROPS" => "Y", ), false, false, array("ID", "TYPE", "NAME", "CODE", "USER_PROPS", "SORT", "MULTIPLE") ); while ($arOrderProperties = $dbOrderProperties->Fetch()) { $this->arOrderProps[$arAgentInfo["PERSON_TYPE_ID"]][] = $arOrderProperties; } } foreach($this->arOrderProps[$arAgentInfo["PERSON_TYPE_ID"]] as $arOrderProperties) { $curVal = $arAgentInfo["ORDER_PROPS_VALUE"][$arOrderProperties["ID"]]; if (strlen($curVal) > 0) { if (IntVal($arAgentInfo["PROFILE_ID"]) <= 0) { $arFields = array( "NAME" => $arAgentInfo["AGENT"]["AGENT_NAME"], "USER_ID" => $arAgentInfo["USER_ID"], "PERSON_TYPE_ID" => $arAgentInfo["PERSON_TYPE_ID"], "XML_ID" => $arAgentInfo["AGENT"]["ID"], "VERSION_1C" => $arAgentInfo["AGENT"]["VERSION"], ); $arAgentInfo["PROFILE_ID"] = CSaleOrderUserProps::Add($arFields); } if(IntVal($arAgentInfo["PROFILE_ID"]) > 0) { $arFields = array( "USER_PROPS_ID" => $arAgentInfo["PROFILE_ID"], "ORDER_PROPS_ID" => $arOrderProperties["ID"], "NAME" => $arOrderProperties["NAME"], "VALUE" => $curVal ); if(empty($arAgentInfo["PROFILE_PROPS_VALUE"][$arOrderProperties["ID"]])) { CSaleOrderUserPropsValue::Add($arFields); } elseif($arAgentInfo["PROFILE_PROPS_VALUE"][$arOrderProperties["ID"]]["VALUE"] != $curVal) { CSaleOrderUserPropsValue::Update($arAgentInfo["PROFILE_PROPS_VALUE"][$arOrderProperties["ID"]]["ID"], $arFields); } } } } } else { $this->strError .= "\n".GetMessage("CC_BSC1_AGENT_PERSON_TYPE_PROBLEM", Array("#ID#" => $arAgentInfo["AGENT"]["ID"])); } } } else { $this->strError .= "\n".GetMessage("CC_BSC1_AGENT_NO_AGENT_ID"); } } }
static function DoSaveUserProfile($userId, $profileId, $profileName, $personTypeId, $orderProps, &$arErrors) { $profileId = intval($profileId); $arIDs = array(); if ($profileId > 0) { $dbProfile = CSaleOrderUserProps::GetList(array(), array("ID" => $profileId), false, false, array("ID", "NAME", "USER_ID", "PERSON_TYPE_ID")); $arProfile = $dbProfile->Fetch(); if (!$arProfile) { $arErrors[] = array("CODE" => "PROFILE_NOT_FOUND", "TEXT" => GetMessage('SKGOUP_PROFILE_NOT_FOUND')); return false; } if ($arProfile["USER_ID"] != $userId || $arProfile["PERSON_TYPE_ID"] != $personTypeId) { $arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGOUP_PARRAMS_ERROR')); return false; } //if (strlen($profileName) > 0 && $profileName != $arProfile["NAME"]) if (strlen($profileName) > 0) { $arFields = array("NAME" => $profileName, "USER_ID" => $userId); CSaleOrderUserProps::Update($profileId, $arFields); } $dbUserPropsValues = CSaleOrderUserPropsValue::GetList(array(), array("USER_PROPS_ID" => $profileId), false, false, array("ID", "ORDER_PROPS_ID")); while ($arUserPropsValue = $dbUserPropsValues->Fetch()) { $arIDs[$arUserPropsValue["ORDER_PROPS_ID"]] = $arUserPropsValue["ID"]; } } if (!is_array($orderProps)) { $dbOrderPropsValues = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => intval($orderProps)), false, false, array("ORDER_PROPS_ID", "VALUE")); $orderProps = array(); while ($arOrderPropsValue = $dbOrderPropsValues->Fetch()) { $orderProps[$arOrderPropsValue["ORDER_PROPS_ID"]] = $arOrderPropsValue["VALUE"]; } } /* TRANSLATION_CUT_OFF else { // map location ID to CODE, if taken from parameters static::TranslateLocationPropertyValues($personTypeId, $orderProps); } */ $utilPropertyList = array(); $dbOrderProperties = CSaleOrderProps::GetList(array(), array("PERSON_TYPE_ID" => $personTypeId, "ACTIVE" => "Y", "USER_PROPS" => "Y"), false, false, array("ID", "TYPE", "NAME", "CODE", "UTIL")); while ($arOrderProperty = $dbOrderProperties->Fetch()) { if ($arOrderProperty['UTIL'] == "Y") { $utilPropertyList[] = $arIDs[$arOrderProperty["ID"]]; continue; } $curVal = $orderProps[$arOrderProperty["ID"]]; if ($arOrderProperty["TYPE"] == "MULTISELECT" && is_array($curVal)) { $curVal = implode(",", $curVal); } if ($arOrderProperty["TYPE"] == "FILE" && is_array($curVal)) { $fileList = array(); foreach ($curVal as $fileDat) { $fileList[] = $fileDat['ID']; } $curVal = serialize($fileList); } if (strlen($curVal) > 0) { if ($profileId <= 0) { if (strlen($profileName) <= 0) { $profileName = GetMessage("SOA_PROFILE") . " " . Date("Y-m-d"); } $arFields = array("NAME" => $profileName, "USER_ID" => $userId, "PERSON_TYPE_ID" => $personTypeId); $profileId = CSaleOrderUserProps::Add($arFields); } if (array_key_exists($arOrderProperty["ID"], $arIDs)) { $arFields = array("NAME" => $arOrderProperty["NAME"], "VALUE" => $curVal); CSaleOrderUserPropsValue::Update($arIDs[$arOrderProperty["ID"]], $arFields); unset($arIDs[$arOrderProperty["ID"]]); } else { $arFields = array("USER_PROPS_ID" => $profileId, "ORDER_PROPS_ID" => $arOrderProperty["ID"], "NAME" => $arOrderProperty["NAME"], "VALUE" => $curVal); CSaleOrderUserPropsValue::Add($arFields); } } } foreach ($arIDs as $id) { if (!empty($utilPropertyList) && in_array($id, $utilPropertyList)) { continue; } CSaleOrderUserPropsValue::Delete($id); } }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } CModule::IncludeModule("sale"); if ($_REQUEST["action"] == "delete" && intval($_REQUEST["id"]) > 0) { CSaleOrderUserProps::Delete(intval($_REQUEST["id"])); } if ($_REQUEST["action"] == "update" && intval($_REQUEST["id"]) > 0) { $profileName = trim($_REQUEST["f_name"] . " " . $_REQUEST["name"] . " " . $_REQUEST["last_name"]); $arFields = array("NAME" => $profileName); CSaleOrderUserProps::Update($_REQUEST["id"], $arFields); if (!empty($_REQUEST["name"])) { CSaleOrderUserPropsValue::Update($_REQUEST["name_id"], array("VALUE" => $_REQUEST["name"])); } if (!empty($_REQUEST["f_name"])) { CSaleOrderUserPropsValue::Update($_REQUEST["f_name_id"], array("VALUE" => $_REQUEST["f_name"])); } if (!empty($_REQUEST["last_name"])) { CSaleOrderUserPropsValue::Update($_REQUEST["last_name_id"], array("VALUE" => $_REQUEST["last_name"])); } if (!empty($_REQUEST["email"])) { CSaleOrderUserPropsValue::Update($_REQUEST["email_id"], array("VALUE" => $_REQUEST["email"])); } if (!empty($_REQUEST["phone"])) { CSaleOrderUserPropsValue::Update($_REQUEST["phone_id"], array("VALUE" => $_REQUEST["phone"])); } if (!empty($_REQUEST["phone"])) { CSaleOrderUserPropsValue::Update($_REQUEST["phone_id"], array("VALUE" => $_REQUEST["phone"])); }