function Delete($ID) { global $DB; $ID = IntVal($ID); $db_orderProps = CSaleOrderProps::GetList($by = "PROPS_GROUP_ID", $order = "ASC", array("PROPS_GROUP_ID" => $ID)); while ($arOrderProps = $db_orderProps->Fetch()) { $DB->Query("DELETE FROM b_sale_order_props_variant WHERE ORDER_PROPS_ID = " . $arOrderProps["ID"] . "", true); $DB->Query("UPDATE b_sale_order_props_value SET ORDER_PROPS_ID = NULL WHERE ORDER_PROPS_ID = " . $arOrderProps["ID"] . "", true); $DB->Query("DELETE FROM b_sale_user_props_value WHERE ORDER_PROPS_ID = " . $arOrderProps["ID"] . "", true); } $DB->Query("DELETE FROM b_sale_order_props WHERE PROPS_GROUP_ID = " . $ID . "", true); CSaleOrderUserProps::ClearEmpty(); return $DB->Query("DELETE FROM b_sale_order_props_group WHERE ID = " . $ID . "", true); }
function OnAfterUserUpdateHandler(&$arFields) { CModule::IncludeModule('sale'); global $USER; $profile = CSaleOrderUserProps::GetList(array("DATE_UPDATE" => "DESC"), array("USER_ID" => $arFields['ID']))->Fetch(); $PROFILE_ID = $profile['ID']; //если профиль создан if ($PROFILE_ID) { //формируем массив свойств $props = array( $PROFILE_ID => array( "USER_PROPS_ID" => $PROFILE_ID, "NAME" => "Адрес доставки", "VALUE" => $arFields['PERSONAL_STREET'] ) ); //добавляем значения свойств к созданному ранее профилю foreach ($props as $propId => $prop) { $x = CSaleOrderUserPropsValue::Update($propId, $prop); } } }
function Delete($ID) { global $DB; $ID = IntVal($ID); $DB->Query("DELETE FROM b_sale_order_props_variant WHERE ORDER_PROPS_ID = " . $ID . "", true); $DB->Query("UPDATE b_sale_order_props_value SET ORDER_PROPS_ID = NULL WHERE ORDER_PROPS_ID = " . $ID . "", true); $DB->Query("DELETE FROM b_sale_user_props_value WHERE ORDER_PROPS_ID = " . $ID . "", true); CSaleOrderUserProps::ClearEmpty(); return $DB->Query("DELETE FROM b_sale_order_props WHERE ID = " . $ID . "", true); }
/** * <p>Функция удаляет свойство с кодом ID заказа. Существующие в базе значения этого свойства отвязываются от удаляемого свойства. Удаляются связанные значения из профиля покупателя. </p> * * * * * @param int $ID Код удаляемого свойства. * * * * @return bool <p>Возвращается <i>true</i> в случае успешного удаления и <i>false</i> - в * случае ошибки.</p> <a name="examples"></a> * * * <h4>Example</h4> * <pre> * <? * if (!CSaleOrderProps::Delete(12)) * echo "Ошибка удаления свойства"; * ?> * </pre> * * * @static * @link http://dev.1c-bitrix.ru/api_help/sale/classes/csaleorderprops/csaleorderprops__delete.75442e5e.php * @author Bitrix */ public static function Delete($ID) { global $DB; $ID = intval($ID); if ($ID <= 0) { return false; } foreach (GetModuleEvents("sale", "OnBeforeOrderPropsDelete", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { return false; } } $DB->Query("DELETE FROM b_sale_order_props_variant WHERE ORDER_PROPS_ID = " . $ID, true); $DB->Query("UPDATE b_sale_order_props_value SET ORDER_PROPS_ID = NULL WHERE ORDER_PROPS_ID = " . $ID, true); $DB->Query("DELETE FROM b_sale_user_props_value WHERE ORDER_PROPS_ID = " . $ID, true); $DB->Query("DELETE FROM b_sale_order_props_relation WHERE PROPERTY_ID = " . $ID, true); CSaleOrderUserProps::ClearEmpty(); foreach (GetModuleEvents("sale", "OnOrderPropsDelete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ID)); } return $DB->Query("DELETE FROM b_sale_order_props WHERE ID = " . $ID, true); }
public static function saveProfileData($profileId, Order $order, array $formData) { $result = new Result(); $errors = array(); if (!($profileName = $order->getPropertyCollection()->getProfileName())) { $result->addError(new EntityError(Loc::getMessage("SALE_ORDEREDIT_PROFILE_ERROR_NAME"))); return $result; } $res = \CSaleOrderUserProps::DoSaveUserProfile($order->getUserId(), $profileId, $profileName->getValue(), $order->getPersonTypeId(), $propCollection = $formData["PROPERTIES"], $errors); if ($res === false) { if (!empty($errors)) { foreach ($errors as $error) { $result->addError(new EntityError($error . "<br>\n")); } } else { $result->addError(new EntityError(Loc::getMessage("SALE_ORDEREDIT_PROFILE_ERROR_SAVE"))); } } return $result; }
if (strlen($errorMessage) > 0) $bInitVars = True; if (strlen($_POST["save"]) > 0 && strlen($errorMessage) <= 0) LocalRedirect($arParams["PATH_TO_LIST"]); elseif(strlen($_POST["apply"]) > 0 && strlen($errorMessage) <= 0) LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_DETAIL"], Array("ID" => $ID))); } $arResult["ORDER_PROPS"] = Array(); $dbUserProps = CSaleOrderUserProps::GetList( array("DATE_UPDATE" => "DESC"), array( "ID" => $ID, "USER_ID" => IntVal($GLOBALS["USER"]->GetID()) ), false, false, array("ID", "NAME", "USER_ID", "PERSON_TYPE_ID", "DATE_UPDATE") ); if ($arUserProps = $dbUserProps->GetNext()) { if(!$bInitVars) $arResult = $arUserProps; else { foreach($_POST as $k => $v) { $arResult[$k] = htmlspecialcharsbx($v); $arResult['~'.$k] = $v; }
CRMModeOutput($result); } /* * profile autocomplete script */ if (isset($userId) AND isset($buyerType) AND isset($profileDefault)) { $userId = intval($userId); $buyerType = intval($buyerType); $profileDefault = intval($profileDefault); $arPropValuesTmp = array(); $userProfile = array(); $userProfile = CSaleOrderUserProps::DoLoadProfiles($userId, $buyerType); if ($profileDefault != "" AND $profileDefault != "0") $arPropValuesTmp = $userProfile[$profileDefault]["VALUES"]; $dbVariants = CSaleOrderProps::GetList( array("SORT" => "ASC"), array( "PERSON_TYPE_ID" => $buyerType, "USER_PROPS" => "Y", "ACTIVE" => "Y", "RELATED" => false ) ); while ($arVariants = $dbVariants->Fetch()) { if (isset($arPropValuesTmp[$arVariants["ID"]]))
function fUserProfile($USER_ID, $BUYER_TYPE = '', $default = '') { $userProfileSelect = "<select name=\"user_profile\" id=\"user_profile\" onChange=\"fChangeProfile(this);\">"; $userProfileSelect .= "<option value=\"0\">".GetMessage("NEWO_BUYER_PROFILE_NEW")."</option>"; $userProfile = CSaleOrderUserProps::DoLoadProfiles($USER_ID, $BUYER_TYPE); $i = ""; if (!empty($userProfile) && is_array($userProfile)) { foreach($userProfile as $key => $val) { if ($default == "" AND $i == "") { $userProfileSelect .= "<option selected value=\"".$key."\">".$val["NAME"]."</option>"; $i = $key; } elseif ($default == $key) $userProfileSelect .= "<option selected value=\"".$key."\">".$val["NAME"]."</option>"; else $userProfileSelect .= "<option value=\"".$key."\">".$val["NAME"]."</option>"; } } $userProfileSelect .= "</select>"; return $userProfileSelect; }
if ($psPreAction && $psPreAction->IsAction()) { $psPreAction->orderId = $arResult["ORDER_ID"]; $psPreAction->orderAmount = $orderTotalSum; $psPreAction->deliveryAmount = $arResult["DELIVERY_PRICE"]; $psPreAction->taxAmount = $arResult["TAX_PRICE"]; $orderData = array(); $dbBasketItems = CSaleBasket::GetList(array("ID" => "ASC"), array("FUSER_ID" => CSaleBasket::GetBasketUserID(), "LID" => SITE_ID, "ORDER_ID" => $arResult["ORDER_ID"]), false, false, array("ID", "QUANTITY", "PRICE", "WEIGHT", "NAME", "CURRENCY", "PRODUCT_ID", "DETAIL_PAGE_URL")); while ($arItem = $dbBasketItems->Fetch()) { $orderData['BASKET_ITEMS'][] = $arItem; } $psPreAction->payOrder($orderData); } } } if (empty($arResult["ERROR"])) { CSaleOrderUserProps::DoSaveUserProfile($USER->GetID(), $arUserResult["PROFILE_ID"], $arUserResult["PROFILE_NAME"], $arUserResult["PERSON_TYPE_ID"], $arUserResult["ORDER_PROP"], $arResult["ERROR"]); } // mail message if (empty($arResult["ERROR"])) { $i = 0; $strOrderList = ""; $arBasketList = array(); $dbBasketItems = CSaleBasket::GetList(array("ID" => "ASC"), array("ORDER_ID" => $arResult["ORDER_ID"]), false, false, array("ID", "PRODUCT_ID", "NAME", "QUANTITY", "PRICE", "CURRENCY", "TYPE", "SET_PARENT_ID")); while ($arItem = $dbBasketItems->Fetch()) { if (CSaleBasketHelper::isSetItem($arItem)) { continue; } $arFilter = array("ID" => IntVal($arItem['PRODUCT_ID'])); $res = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID", "IBLOCK_ID", "PREVIEW_PICTURE", 'DETAIL_PICTURE')); while ($ar_fields = $res->GetNext()) { if ($ar_fields['PREVIEW_PICTURE']) {
if (is_array($arProductsInBasket)) { foreach ($arProductsInBasket as $ar_prod) { $event3 .= $ar_prod["PRODUCT_ID"] . ", "; } } $e = $event1 . "/" . $event2 . "/" . $event3; if (!is_array($_SESSION["ORDER_EVENTS"]) || is_array($_SESSION["ORDER_EVENTS"]) && !in_array($e, $_SESSION["ORDER_EVENTS"])) { CStatistic::Set_Event($event1, $event2, $event3); $_SESSION["ORDER_EVENTS"][] = $e; } } } elseif ($arResult["CurrentStep"] == 2) { $arResult["USER_PROFILES"] = array(); $bFillProfileFields = False; $bFirstProfile = True; $dbUserProfiles = CSaleOrderUserProps::GetList(array("DATE_UPDATE" => "DESC"), array("PERSON_TYPE_ID" => $arResult["PERSON_TYPE"], "USER_ID" => IntVal($USER->GetID()))); if ($arUserProfiles = $dbUserProfiles->GetNext()) { $bFillProfileFields = True; do { if (IntVal($arResult["PROFILE_ID"]) == IntVal($arUserProfiles["ID"]) || !isset($arResult["PROFILE_ID"]) && $bFirstProfile) { $arUserProfiles["CHECKED"] = "Y"; } $bFirstProfile = False; $arUserProfiles["USER_PROPS_VALUES"] = array(); $dbUserPropsValues = CSaleOrderUserPropsValue::GetList(array("SORT" => "ASC"), array("USER_PROPS_ID" => $arUserProfiles["ID"]), false, false, array("VALUE", "PROP_TYPE", "VARIANT_NAME", "SORT", "ORDER_PROPS_ID")); while ($arUserPropsValues = $dbUserPropsValues->GetNext()) { $valueTmp = ""; if ($arUserPropsValues["PROP_TYPE"] == "SELECT" || $arUserPropsValues["PROP_TYPE"] == "MULTISELECT" || $arUserPropsValues["PROP_TYPE"] == "RADIO") { $arUserPropsValues["VALUE_FORMATED"] = $arUserPropsValues["VARIANT_NAME"]; } elseif ($arUserPropsValues["PROP_TYPE"] == "LOCATION") { if ($arLocation = CSaleLocation::GetByID($arUserPropsValues["VALUE"], LANGUAGE_ID)) {
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; if (isset($hrpd->MerchantInternalPaymentId)) { if ($hrpd->ErrorCode == 0) { if (CModule::IncludeModule('sale')) { $order_id = intval($hrpd->MerchantInternalPaymentId); if ($arOrder = CSaleOrder::GetByID(IntVal($order_id))) { CSalePaySystemAction::InitParamArrays($arOrder, $arOrder["ID"]); $urlGetMerchantInfo = 'http://payment.kaznachey.net/api/PaymentInterface/CreatePayment'; $urlGetClientMerchantInfo = 'http://payment.kaznachey.net/api/PaymentInterface/GetMerchatInformation'; $merchantGuid = CSalePaySystemAction::GetParamValue("MerchantId"); $merchnatSecretKey = CSalePaySystemAction::GetParamValue("SecretKey"); $order_id = IntVal($GLOBALS["SALE_INPUT_PARAMS"]["ORDER"]["ID"]); $selectedPaySystemId = 1; $quantitys = 0; $order_info = CSaleOrder::GetByID($order_id); $user_info = CSaleOrderUserProps::GetByID($order_info['USER_ID']); $user_fullinfo = CSaleOrderUserPropsValue::GetByID($order_info['USER_ID']); $user_email = $USER->GetParam("EMAIL"); $user_id = $order_info['USER_ID']; $amount = number_format($order_info['PRICE'], 2, '.', ''); $dbBasketItems = CSaleBasket::GetList(array(), array("ORDER_ID" => $order_id)); while ($arItems = $dbBasketItems->Fetch()) { $quantitys += $arItems['QUANTITY']; } if ($order_info['PRICE_DELIVERY'] > 0) { $quantitys += 1; } $quantitys = number_format($quantitys, 2, '.', ''); $signature_u = md5(md5($merchantGuid . $merchnatSecretKey . "{$amount}" . "{$quantitys}" . $order_id)); if ($hrpd->CustomMerchantInfo == $signature_u) { $arFields = array("PS_STATUS" => "Y", "PS_STATUS_CODE" => "-", "PS_STATUS_DESCRIPTION" => $strPS_STATUS_DESCRIPTION, "PS_STATUS_MESSAGE" => $strPS_STATUS_MESSAGE, "PS_SUM" => $out_summ, "PS_CURRENCY" => "", "PS_RESPONSE_DATE" => Date(CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL", LANG))), "USER_ID" => $arOrder["USER_ID"]);
public static function getBuyerProfilesList($userId, $personTypeId = null) { $result = array(0 => Loc::getMessage("SALE_ORDER_BUYER_CREATE_NEW")); if (intval($userId) > 0) { $profiles = \CSaleOrderUserProps::DoLoadProfiles($userId); if (is_array($profiles)) { foreach ($profiles as $types) { foreach ($types as $key => $value) { $result[$key] = htmlspecialcharsback($value["NAME"]); } } } } return $result; }
//END MAIN INFO //BUYERS PROFILE $sTableID_tab2 = "tbl_sale_buyers_profile_tab2"; $oSort_tab2 = new CAdminSorting($sTableID_tab2); $lAdmin_tab2 = new CAdminList($sTableID_tab2, $oSort_tab2); $arPErsonTypes = array(); $db_ptype = CSalePersonType::GetList($by1 = "SORT", $order1 = "ASC"); while ($ptype = $db_ptype->Fetch()) { $arPErsonTypes[$ptype["ID"]] = $ptype; } if (!isset($_REQUEST["by"])) { $arProfSort = array("PERSON_TYPE_ID" => "ASC", "DATE_UPDATE" => "DESC"); } else { $arProfSort[$by] = $order; } $dbProfileList = CSaleOrderUserProps::GetList($arProfSort, array("USER_ID" => $ID), false, false, array("ID", "NAME", "PERSON_TYPE_ID", "DATE_UPDATE")); $dbProfileList = new CAdminResult($dbProfileList, $sTableID_tab2); $dbProfileList->NavStart(); $lAdmin_tab2->NavText($dbProfileList->GetNavPrint(GetMessage('BUYER_PERSON_LIST'))); $personHeader = array(array("id" => "NAME", "content" => GetMessage("BUYER_P_NAME"), "sort" => "NAME", "default" => true), array("id" => "PERSON_TYPE_ID", "content" => GetMessage("BUYER_P_PERSONTYPE"), "sort" => "PERSON_TYPE_ID", "default" => true), array("id" => "DATE_UPDATE", "content" => GetMessage("BUYER_P_DATE_UPDATE"), "sort" => "DATE_UPDATE", "default" => true)); $lAdmin_tab2->AddHeaders($personHeader); while ($arProfList = $dbProfileList->GetNext()) { $row =& $lAdmin_tab2->AddRow($arProfList["ID"], $arProfList, "sale_buyers_profile_edit.php?id=" . $arProfList["ID"] . "&lang=" . LANG, GetMessage("BUYER_P_PROFILE_EDIT")); $row->AddField("NAME", "[" . $arProfList["ID"] . "] <a href=\"/bitrix/admin/sale_buyers_profile_edit.php?id=" . $arProfList["ID"] . "&lang=" . LANG . "\">" . $arProfList["NAME"] . "</a>"); $row->AddField("PERSON_TYPE_ID", htmlspecialcharsbx($arPErsonTypes[$arProfList["PERSON_TYPE_ID"]]["NAME"])); if (count($arSites) > 1) { $row->AddField("LID", "[" . $arProfList["LID"] . "] " . htmlspecialcharsbx($arSites[$arProfList["LID"]]["NAME"]) . ""); } } if ($_REQUEST["table_id"] == $sTableID_tab2) { $lAdmin_tab2->CheckListMode();
$event1 = "eStore"; $event2 = "order_confirm"; $event3 = $arResult["ORDER_ID"]; $e = $event1 . "/" . $event2 . "/" . $event3; if (!is_array($_SESSION["ORDER_EVENTS"]) || is_array($_SESSION["ORDER_EVENTS"]) && !in_array($e, $_SESSION["ORDER_EVENTS"])) { CStatistic::Set_Event($event1, $event2, $event3); $_SESSION["ORDER_EVENTS"][] = $e; } } $urlError = ""; if ($PAYSYSTEM_ID == "account") { if (!CSaleUserAccount::DoPayOrderFromAccount($USER->GetID(), $arBasketItems["CURRENCY"], $ORDER_ID, $arBasketItems["PRICE"], array(), $arErrors)) { $urlError = "&erraccount=y"; } } CSaleOrderUserProps::DoSaveUserProfile($USER->GetID(), $PROFILE_ID, $profileName, $PERSON_TYPE, $arPropValues, $arErrors); LocalRedirect($APPLICATION->GetCurPageParam("ORDER_ID=" . $ORDER_ID . $urlError, array("ORDER_ID", "action", "id"))); } elseif (count($arErrors) > 0) { foreach ($arErrors as $val) { $errorMessage .= $val . "<br>"; } } } } else { if (!isset($_POST["BasketOrder"])) { $errorMessage = ""; } } /*********************************************************/ /******************** take basket ************************/ /*********************************************************/
if(!CSaleOrderUserProps::Update($ID, $arFields)) $lAdmin->AddGroupError(GetMessage("ws.saleuserprofiles_save_error").$cData->LAST_ERROR, $ID); } else $lAdmin->AddGroupError(GetMessage("ws.saleuserprofiles_save_error")." ".GetMessage("ws.saleuserprofiles_no_profile"), $ID); break;*/ } } } // ******************************************************************** // // ВЫБОРКА ЭЛЕМЕНТОВ СПИСКА // // ******************************************************************** // // выберем список профилей пользователей $rsData = CSaleOrderUserProps::GetList(array($by=>$order), $arFilter); //$arData = array(); //while ($arRes = $rsData->Fetch()) { // $arData[] = $arRes; //} // преобразуем список в экземпляр класса CAdminResult //$rsData = new CDBResult; $rsData = new CAdminResult($rsData, $sTableID); //$rsData->InitFromArray($arData); // аналогично CDBResult инициализируем постраничную навигацию. $rsData->NavStart();
public static function OnUserDelete($ID) { $ID = IntVal($ID); $db_res = CSaleOrderUserProps::GetList($b = "ID", $o = "ASC", array("USER_ID" => $ID)); while ($ar_res = $db_res->Fetch()) { CSaleOrderUserProps::Delete(IntVal($ar_res["ID"])); } return True; }
static function Add($arFields) { $result = new WS_SaleUserProfilesErrorsContainer(); $fields = array( "NAME" => $arFields["NAME"], "PERSON_TYPE_ID" => $arFields["PERSON_TYPE_ID"], "USER_ID" => $arFields["USER_ID"], "DATE_UPDATE" => $arFields["DATE_UPDATE"] ); if (empty($fields["USER_ID"])) { $result->addErrorString(GetMessage("ws.saleuserprofiles_save_error_required_field") . "\"код пользователя, которому принадлежит профиль\""); } // сохраняем поля if (!$result->getErrorsAsString() && !empty($arFields)) { $id = CSaleOrderUserProps::Add($arFields); if ($id) { return $id; } } return $result; }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } CModule::IncludeModule("sale"); // Выберем все профили покупателя для текущего пользователя, // упорядочив результат по дате последнего изменения $db_sales = CSaleOrderUserProps::GetList(array("DATE_UPDATE" => "DESC"), array("USER_ID" => $USER->GetID())); while ($ar_sales = $db_sales->Fetch()) { $props = array(); $db_propVals = CSaleOrderUserPropsValue::GetList(array("ID" => "ASC"), array("USER_PROPS_ID" => $ar_sales["ID"])); while ($arPropVals = $db_propVals->Fetch()) { if ($arPropVals["PROP_TYPE"] == "LOCATION") { $arPropVals["~VALUE"] = $arPropVals["VALUE"]; $loc = CSaleLocation::GetByID($arPropVals["VALUE"]); $arPropVals["VALUE"] = $loc["CITY_NAME"] ?: $loc["REGION_NAME"] ?: $loc["COUNTRY_NAME"]; } $props[] = $arPropVals; } $ar_sales["PROPS"] = $props; $arResult["DELIVERY_ADDR"][] = $ar_sales; }
//TAB EDIT PROFILE $tabControl->BeginNextFormTab(); if (!empty($arProfile) && !empty($arUser)) { $dbPersonType = CSalePersonType::GetList(array(), array("ACTIVE" => "Y", "ID" => $PERSON_TYPE)); $arPersonType = $dbPersonType->GetNext(); $LID = $arPersonType["LID"]; $arFilterProps = array("PERSON_TYPE_ID" => $PERSON_TYPE, "ACTIVE" => "Y"); if ($saleModulePermissions >= "U" && $saleModulePermissions < "W") { $arFilterProps["USER_PROPS"] = "Y"; $arFilterProps["UTIL"] = "N"; } $tabControl->AddViewField("CODE_USER", GetMessage("BUYER_PE_USER") . ":", "[<a href=\"/bitrix/admin/user_edit.php?ID=" . $arUser["ID"] . "&lang=" . LANGUAGE_ID . "\">" . $arUser["ID"] . "</a>] (" . $arUser["LOGIN"] . ") " . $userFIO); $tabControl->AddEditField("CODE_PROFILE_NAME", GetMessage("BUYER_PE_PROFILE_NAME") . ":", false, array("size" => 30, "maxlength" => 255), htmlspecialcharsEx($profileName)); $propertyGroupID = ""; $dbProperties = CSaleOrderProps::GetList(array("GROUP_SORT" => "ASC", "PROPS_GROUP_ID" => "ASC", "SORT" => "ASC", "NAME" => "ASC"), $arFilterProps, false, false, array("*")); $userProfile = CSaleOrderUserProps::DoLoadProfiles($USER_ID, $PERSON_TYPE); $curVal = ""; while ($arProperties = $dbProperties->Fetch()) { $curVal = $userProfile[$ID]["VALUES"][IntVal($arProperties["ID"])]; $fieldValue = $curVal != "" ? $curVal : $arProperties["DEFAULT_VALUE"]; if (IntVal($arProperties["PROPS_GROUP_ID"]) != $propertyGroupID) { $tabControl->AddSection("SECTION_" . $arProperties["PROPS_GROUP_ID"], $arProperties["GROUP_NAME"]); } $shure = false; if ($arProperties["REQUIED"] == "Y" || $arProperties["IS_PROFILE_NAME"] == "Y" || $arProperties["IS_LOCATION"] == "Y" || $arProperties["IS_LOCATION4TAX"] == "Y" || $arProperties["IS_PAYER"] == "Y" || $arProperties["IS_ZIP"] == "Y") { $shure = true; } /*fields*/ if ($arProperties["TYPE"] == "TEXT") { $tabControl->AddEditField("CODE_" . IntVal($arProperties["ID"]), $arProperties["NAME"] . ":", $shure, array("size" => 30, "maxlength" => 255), $fieldValue); } elseif ($arProperties["TYPE"] == "CHECKBOX") {
"CODE" => $arOrderProperties["CODE"], "VALUE" => $curVal ); CSaleOrderPropsValue::Add($arFields); if ( $arOrderProperties["USER_PROPS"] == "Y" && IntVal($arUserResult["PROFILE_ID"])<=0 && IntVal($arUserResult["PROFILE_ID_new"])<=0) { if (strlen($arUserResult["PROFILE_NAME"]) <= 0) $arUserResult["PROFILE_NAME"] = GetMessage("SOA_PROFILE")." ".Date("Y-m-d"); $arFields = array( "NAME" => $arUserResult["PROFILE_NAME"], "USER_ID" => IntVal($USER->GetID()), "PERSON_TYPE_ID" => $arUserResult["PERSON_TYPE_ID"] ); $arUserResult["PROFILE_ID_new"] = CSaleOrderUserProps::Add($arFields); $arUserResult["PROFILE_ID_new"] = IntVal($arUserResult["PROFILE_ID_new"]); } if ($arOrderProperties["USER_PROPS"] == "Y" && IntVal($arUserResult["PROFILE_ID_new"]) > 0) { $arFields = array( "USER_PROPS_ID" => $arUserResult["PROFILE_ID_new"], "ORDER_PROPS_ID" => $arOrderProperties["ID"], "NAME" => $arOrderProperties["NAME"], "VALUE" => $curVal ); CSaleOrderUserPropsValue::Add($arFields); } if ($arOrderProperties["USER_PROPS"] == "Y" && IntVal($arUserResult["PROFILE_ID"]) > 0)
$event1 = "eStore"; $event2 = "order_confirm"; $event3 = $arResult["ORDER_ID"]; $e = $event1 . "/" . $event2 . "/" . $event3; if (!is_array($_SESSION["ORDER_EVENTS"]) || is_array($_SESSION["ORDER_EVENTS"]) && !in_array($e, $_SESSION["ORDER_EVENTS"])) { CStatistic::Set_Event($event1, $event2, $event3); $_SESSION["ORDER_EVENTS"][] = $e; } } $urlError = ""; if ($PAYSYSTEM_ID == "account") { if (!CSaleUserAccount::DoPayOrderFromAccount($currentUserId, $arBasketItems["CURRENCY"], $ORDER_ID, $arBasketItems["PRICE"], array(), $arErrors)) { $urlError = "&erraccount=y"; } } CSaleOrderUserProps::DoSaveUserProfile($currentUserId, $PROFILE_ID, $profileName, $PERSON_TYPE, $arPropValues, $arErrors); LocalRedirect($APPLICATION->GetCurPageParam("ORDER_ID=" . $ORDER_ID . $urlError, array("ORDER_ID", "action", "id"))); } elseif (!empty($arErrors)) { foreach ($arErrors as $val) { $errorMessage .= $val . "<br>"; } } } } else { if (!isset($_POST["BasketOrder"])) { $errorMessage = ""; } } /*********************************************************/ /******************** take basket ************************/ /*********************************************************/
/** * Sends product subscription letter * * @param integer $ID - code product * @param string $MODULE - module product * @return bool */ function ProductSubscribe($ID, $MODULE) { $ID = (int) $ID; $MODULE = trim($MODULE); if ($ID <= 0 || $MODULE == '') { return false; } $arSubscribeProd = array(); $subscribeProd = COption::GetOptionString("sale", "subscribe_prod", ""); if ($subscribeProd != '') { $arSubscribeProd = unserialize($subscribeProd); } $rsItemsBasket = CSaleBasket::GetList(array("USER_ID" => "DESC", "LID" => "ASC"), array("PRODUCT_ID" => $ID, "SUBSCRIBE" => "Y", "CAN_BUY" => "N", "ORDER_ID" => "NULL", ">USER_ID" => "0", "MODULE" => $MODULE), false, false, array('ID', 'FUSER_ID', 'USER_ID', 'MODULE', 'PRODUCT_ID', 'CURRENCY', 'DATE_INSERT', 'QUANTITY', 'LID', 'DELAY', 'CALLBACK_FUNC', 'SUBSCRIBE', 'PRODUCT_PROVIDER_CLASS')); while ($arItemsBasket = $rsItemsBasket->Fetch()) { $LID = $arItemsBasket["LID"]; if (isset($arSubscribeProd[$LID]) && $arSubscribeProd[$LID]["use"] == "Y") { $sendEmailList = array(); $USER_ID = $arItemsBasket['USER_ID']; $arMailProp = array(); $arPayerProp = array(); // select person type $dbPersonType = CSalePersonType::GetList(array("SORT" => "ASC"), array("LID" => $LID), false, false, array('ID')); while ($arPersonType = $dbPersonType->Fetch()) { // select ID props is mail $dbProperties = CSaleOrderProps::GetList(array(), array("PERSON_TYPE_ID" => $arPersonType["ID"], "IS_EMAIL" => "Y", "ACTIVE" => "Y"), false, false, array('ID', 'PERSON_TYPE_ID')); while ($arProperties = $dbProperties->Fetch()) { $arMailProp[$arProperties["PERSON_TYPE_ID"]] = $arProperties["ID"]; } // select ID props is name $arPayerProp = array(); $dbProperties = CSaleOrderProps::GetList(array(), array("PERSON_TYPE_ID" => $arPersonType["ID"], "IS_PAYER" => "Y", "ACTIVE" => "Y"), false, false, array('ID', 'PERSON_TYPE_ID')); while ($arProperties = $dbProperties->Fetch()) { $arPayerProp[$arProperties["PERSON_TYPE_ID"]] = $arProperties["ID"]; } } //end while // load user profiles $arUserProfiles = CSaleOrderUserProps::DoLoadProfiles($USER_ID); $rsUser = CUser::GetByID($USER_ID); $arUser = $rsUser->Fetch(); $userName = $arUser["LAST_NAME"]; if ($userName != '') { $userName .= " "; } $userName .= $arUser["NAME"]; // select of user name to be sent $arUserSendName = array(); if (!empty($arUserProfiles) && !empty($arPayerProp)) { foreach ($arPayerProp as $personType => $namePropID) { if (isset($arUserProfiles[$personType])) { foreach ($arUserProfiles[$personType] as $profiles) { if (isset($profiles["VALUES"][$namePropID]) && $profiles["VALUES"][$namePropID] != '') { $arUserSendName[$personType] = trim($profiles["VALUES"][$namePropID]); break; } } } } } else { $arUserSendName[] = $userName; } // select of e-mail to be sent $arUserSendMail = array(); if (!empty($arUserProfiles) && !empty($arMailProp)) { foreach ($arMailProp as $personType => $mailPropID) { if (isset($arUserProfiles[$personType])) { foreach ($arUserProfiles[$personType] as $profiles) { if (isset($profiles["VALUES"][$mailPropID]) && $profiles["VALUES"][$mailPropID] != '') { $arUserSendMail[$personType] = trim($profiles["VALUES"][$mailPropID]); break; } } } else { $arUserSendMail[$personType] = $arUser["EMAIL"]; } } } else { $arUserSendMail[] = $arUser["EMAIL"]; } /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arItemsBasket)) { $arCallback = $productProvider::GetProductData(array("PRODUCT_ID" => $ID, "QUANTITY" => 1, "RENEWAL" => "N", "USER_ID" => $USER_ID, "SITE_ID" => $LID, "BASKET_ID" => $arItemsBasket["ID"])); } elseif (isset($arItemsBasket["CALLBACK_FUNC"]) && !empty($arItemsBasket["CALLBACK_FUNC"])) { $arCallback = CSaleBasket::ExecuteCallbackFunction(trim($arItemsBasket["CALLBACK_FUNC"]), $MODULE, $ID, 1, "N", $USER_ID, $LID); } if (!empty($arCallback)) { $arCallback["QUANTITY"] = 1; $arCallback["DELAY"] = "N"; $arCallback["SUBSCRIBE"] = "N"; CSaleBasket::Update($arItemsBasket["ID"], $arCallback); } //send mail if (!empty($arUserSendMail) && !empty($arCallback)) { $eventName = "SALE_SUBSCRIBE_PRODUCT"; $event = new CEvent(); foreach ($arUserSendMail as $personType => $mail) { $checkMail = strtolower($mail); if (isset($sendEmailList[$checkMail])) { continue; } $sendName = $userName; if (isset($arUserSendName[$personType]) && $arUserSendName[$personType] != '') { $sendName = $arUserSendName[$personType]; } $arFields = array("EMAIL" => $mail, "USER_NAME" => $sendName, "NAME" => $arCallback["NAME"], "PAGE_URL" => CHTTP::URN2URI($arCallback["DETAIL_PAGE_URL"]), "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@" . $_SERVER["SERVER_NAME"])); $event->Send($eventName, $LID, $arFields, "N"); $sendEmailList[$checkMail] = true; } } } // end if bSend } // end while $arItemsBasket return true; }
function Add($arFields) { global $DB; if (!CSaleOrderUserProps::CheckFields("ADD", $arFields)) { return false; } $arInsert = $DB->PrepareInsert("b_sale_user_props", $arFields); $strSql = "INSERT INTO b_sale_user_props(" . $arInsert[0] . ", DATE_UPDATE) " . "VALUES(" . $arInsert[1] . ", " . $DB->GetNowFunction() . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ID = IntVal($DB->LastID()); return $ID; }
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"); } } }
/** * <p>Функция удаляет тип плательщика с кодом ID. Так же удаляются все связанные данные. Если есть заказы, привязанные к этому типу плательщика, то тип плательщика не может быть удален. </p> * * * * * @param int $ID Код типа плательщика. * * * * @return bool <p>Возвращается <i>true</i> в случае успешного удаления и <i>false</i> - в * противном случае.</p><br><br> * * @static * @link http://dev.1c-bitrix.ru/api_help/sale/classes/csalepersontype/csalepersontype__delete.c2566ed3.php * @author Bitrix */ public static function Delete($ID) { global $DB; $ID = IntVal($ID); $db_orders = CSaleOrder::GetList( array("DATE_UPDATE" => "DESC"), array("PERSON_TYPE_ID" => $ID), false, array("nTopCount" => 1), array("ID") ); if ($db_orders->Fetch()) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGP_ERROR_PERSON_HAS_ORDER").$ID, "ERROR_PERSON_HAS_ORDER"); return False; } $db_events = GetModuleEvents("sale", "OnBeforePersonTypeDelete"); while ($arEvent = $db_events->Fetch()) if (ExecuteModuleEventEx($arEvent, Array($ID))===false) return false; $events = GetModuleEvents("sale", "OnPersonTypeDelete"); while ($arEvent = $events->Fetch()) ExecuteModuleEventEx($arEvent, Array($ID)); $DB->Query("DELETE FROM b_sale_pay_system_action WHERE PERSON_TYPE_ID = ".$ID."", true); $db_orderProps = CSaleOrderProps::GetList( array("PROPS_GROUP_ID" => "ASC"), array("PERSON_TYPE_ID" => $ID) ); while ($arOrderProps = $db_orderProps->Fetch()) { $DB->Query("DELETE FROM b_sale_order_props_variant WHERE ORDER_PROPS_ID = ".$arOrderProps["ID"]."", true); $DB->Query("DELETE FROM b_sale_order_props_value WHERE ORDER_PROPS_ID = ".$arOrderProps["ID"]."", true); $DB->Query("DELETE FROM b_sale_user_props_value WHERE ORDER_PROPS_ID = ".$arOrderProps["ID"]."", true); } $DB->Query("DELETE FROM b_sale_order_props WHERE PERSON_TYPE_ID = ".$ID."", true); $db_orderUserProps = CSaleOrderUserProps::GetList( array("NAME" => "ASC"), array("PERSON_TYPE_ID" => $ID) ); while ($arOrderUserProps = $db_orderUserProps->Fetch()) { $DB->Query("DELETE FROM b_sale_user_props_value WHERE USER_PROPS_ID = ".$arOrderUserProps["ID"]."", true); } $DB->Query("DELETE FROM b_sale_user_props WHERE PERSON_TYPE_ID = ".$ID."", true); $DB->Query("DELETE FROM b_sale_order_props_group WHERE PERSON_TYPE_ID = ".$ID."", true); $DB->Query("DELETE FROM b_sale_person_type_site WHERE PERSON_TYPE_ID=".$ID, true); unset($GLOBALS["SALE_PERSON_TYPE_LIST_CACHE"]); return $DB->Query("DELETE FROM b_sale_person_type WHERE ID = ".$ID."", true); }
} if (strlen($errorMessage) > 0) { LocalRedirect($APPLICATION->GetCurPageParam("del_id=" . $del_id, array("del_id", "sessid"))); } else { LocalRedirect($APPLICATION->GetCurPageParam("success_del_id=" . $del_id, array("del_id", "sessid"))); } } if (IntVal($_REQUEST["del_id"]) > 0) { $errorMessage = GetMessage("SALE_DEL_PROFILE", array("#ID#" => IntVal($_REQUEST["del_id"]))); } elseif (IntVal($_REQUEST["success_del_id"]) > 0) { $errorMessage = GetMessage("SALE_DEL_PROFILE_SUC", array("#ID#" => IntVal($_REQUEST["success_del_id"]))); } if (strLen($errorMessage) >= 0) { $arResult["ERROR_MESSAGE"] = $errorMessage; } $by = strlen($_REQUEST["by"]) > 0 ? $_REQUEST["by"] : "DATE_UPDATE"; $order = strlen($_REQUEST["order"]) > 0 ? $_REQUEST["order"] : "DESC"; $dbUserProps = CSaleOrderUserProps::GetList(array($by => $order), array("USER_ID" => IntVal($GLOBALS["USER"]->GetID()))); $dbUserProps->NavStart($arParams["PER_PAGE"]); $arResult["NAV_STRING"] = $dbUserProps->GetPageNavString(GetMessage("SPPL_PAGES")); $arResult["PROFILES"] = array(); while ($arUserProps = $dbUserProps->GetNext()) { $arResultTmp = array(); $arResultTmp = $arUserProps; $arResultTmp["PERSON_TYPE"] = CSalePersonType::GetByID($arUserProps["PERSON_TYPE_ID"]); $arResultTmp["PERSON_TYPE"]["NAME"] = htmlspecialcharsEx($arResultTmp["PERSON_TYPE"]["NAME"]); $arResultTmp["URL_TO_DETAIL"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_DETAIL"], array("ID" => $arUserProps["ID"])); $arResultTmp["URL_TO_DETELE"] = htmlspecialcharsbx($APPLICATION->GetCurPage() . "?del_id=" . $arUserProps["ID"] . "&" . bitrix_sessid_get()); $arResult["PROFILES"][] = $arResultTmp; } $this->IncludeComponentTemplate();