function getFUserCode() { global $USER; $arRes = CSaleUser::GetList(array("USER_ID" => IntVal($USER->GetID()))); if (!empty($arRes)) { $_SESSION["SALE_USER_ID"] = $arRes['ID']; $arRes["CODE"] = md5(time() . randString(10)); CSaleUser::_Update($arRes["ID"], array("CODE" => $arRes["CODE"])); CSaleUser::Update($arRes["ID"]); return $arRes["ID"]; } }
function OnUserLogin($new_user_id) { $cookie_name = COption::GetOptionString("main", "cookie_name", "BITRIX_SM"); $ID = IntVal($_SESSION["SALE_USER_ID"]); if ($ID <= 0) { $ID = IntVal($_COOKIE[$cookie_name . "_SALE_UID"]); } $res = CSaleUser::GetList(array("!ID" => IntVal($ID), "USER_ID" => IntVal($new_user_id))); if (!empty($res)) { if ($ID > 0) { if (CSaleBasket::TransferBasket($ID, $res["ID"])) { CSaleUser::Delete($ID); } } $ID = IntVal($res["ID"]); } CSaleUser::Update($ID); $_SESSION["SALE_USER_ID"] = $ID; $_SESSION["SALE_BASKET_NUM_PRODUCTS"] = array(); return true; }