set_id($msgID);
$order->offsetUnset('SignUp');
$email = $order['Email'];
$reg_data = array();
$auth_settings = $nc_core->get_settings('', 'auth', false, isset($catalogue_id) ? $catalogue_id : null);
if (!isset($_SESSION['user_hash'])) {
$_SESSION['user_hash'] = md5((mt_rand(1, 1000) * mt_rand(1, 100) + mt_rand(1, 10000)) / mt_rand(1, 10));
}
$order->set('user_hash', $_SESSION['user_hash']);
if (!$AUTH_USER_ID) {
$user_id = 0;
// если пользоватьель не авторизован и есть пользователь с таким же email как в заказе, то присваиваем заказу id этого пользователя
$user_id = $db->get_var("SELECT `User_ID` FROM `User` WHERE `Email` = '" . $db->escape($email) . "'");
if($user_id) {
$order->set('User_ID', $user_id);
}elseif ($nc_core->input->fetch_post('f_SignUp')) {
if ($nc_core->user->check_login($email) == NC_AUTH_LOGIN_OK) {
$alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
$length = strlen($alphabet);
$password = '';
for ($i = 0; $i < 8; $i++) {
$password .= $alphabet[mt_rand(0, $length - 1)];
}
$registration_code = $auth_settings['confirm'] ? md5(uniqid('', true)) : '';
try {
$user = array(
'Email' => $email,
//'Login' => $email,
'Name' => $order['ContactName'],
);
$user_id = $nc_core->user->add($user, 2, $password, array(
'Checked' => $auth_settings['confirm'] ? 0 : 1,
), $registration_code);
} catch (Exception $e) {
}
}
if ($user_id) {
$order->set('User_ID', $user_id);
$reg_data = array('user_id' => $user_id, 'password' => $password);
if ($auth_settings['autoauthorize']) {
$nc_core->user->authorize_by_id($user_id);
}
}
}
}
setcookie('Order_ContactName', $order['ContactName'], time() + 31536000, '/');
setcookie('Order_Email', $order['Email'], time() + 31536000, '/');
setcookie('Order_City', $order['City'], time() + 31536000, '/');
setcookie('Order_Phone', $order['Phone'], time() + 31536000, '/');
setcookie('Order_Address', $order['Address'], time() + 31536000, '/');
setcookie('Order_Zip', $order['Zip'], time() + 31536000, '/');
$netshop->place_order($order, $reg_data);
$payment_method = new nc_netshop_payment_method($order['PaymentMethod']);
$payment_system_id = $payment_method['handler_id'];
$invoice = null;
if ($payment_system_id && nc_module_check_by_keyword('payment', false)) {
$invoice = new nc_payment_invoice(array(
"payment_system_id" => $payment_system_id,
"amount" => $order->get_totals(),
"description" => "Оплата заказа $msgID",
"currency" => $netshop->get_currency_code(),
"customer_id" => $AUTH_USER_ID,
"customer_name" => (string)$f_ContactName,
"customer_email" => (string)$f_Email,
"customer_phone" => (string)$f_Phone,
"order_source" => 'netshop',
"order_id" => $msgID,
));
$invoice->save();
}
while (ob_end_clean()) {
;
}
} catch (Exception $e) {
echo $e->getMessage();
}
if (!empty($isNaked)) {
echo 'OK';
} elseif($current_catalogue['Netshop_Order_Success_Sub_ID']) {
// Переадресация
$finish_url = $nc_core->subdivision->get_by_id( $current_catalogue['Netshop_Order_Success_Sub_ID'], 'Hidden_URL' );
header("Location: " . $finish_url . "?hash=" . $order['user_hash'] . '&order_id=' . $msgID . ($invoice ? ("&invoice_id=" . $invoice->get('id')) : ""));
}else{
echo ($IsChecked ? NETCAT_MODERATION_MSG_OBJADD : NETCAT_MODERATION_MSG_OBJADDMOD);
echo "
".$goBack;
}
exit;