zencart会员登陆保存登陆状态
2012-07-26 20:27 来源:www.chinab4c.com 作者:zencart专家
zencart会员登陆保存登陆状态,这个功能是非常重要的,也是必要的。我们在zencart会员登陆前台的时候,当我们勾选了记得我。那么我们就可以直接在关闭浏览器的情况下。直接实现zencart自动登陆状态。为了实现这个功能,我们必须对zencart进行二次开发。
1:首先在zen cart模板增加以下代码。includes/templates/template_default/templates/tpl_login_default.php
<label class="inputLabel" for="login-password">记得我</label>
<?php echo zen_draw_checkbox_field('remember', '1', false, 'id="remember"');?>
2:其次在includes/application_top.php里面增加以下代码。
if(!$_SESSION['customer_id']){
if(isset($_COOKIE['zc']['email']) && isset($_COOKIE['zc']['pwd'])){
// Check if email exists
$check_customer_query = "SELECT customers_id, customers_firstname, customers_lastname, customers_password,
customers_email_address, customers_default_address_id,
customers_authorization, customers_referral
FROM " . TABLE_CUSTOMERS . "
WHERE customers_email_address = :emailAddress";
$check_customer_query =$db->bindVars($check_customer_query, ':emailAddress', $_COOKIE['zc']['email'], 'string');
$check_customer = $db->Execute($check_customer_query);
if (!$check_customer->RecordCount()) {
} elseif ($check_customer->fields['customers_authorization'] == '4') {
} else {
// Check that password is good
if (!zen_validate_password($_COOKIE['zc']['pwd'], $check_customer->fields['customers_password'])) {
} else {
if (SESSION_RECREATE == 'True') {
zen_session_recreate();
}
$check_country_query = "SELECT entry_country_id, entry_zone_id
FROM " . TABLE_ADDRESS_BOOK . "
WHERE customers_id = :customersID
AND address_book_id = :addressBookID";
$check_country_query = $db->bindVars($check_country_query, ':customersID', $check_customer->fields['customers_id'], 'integer');
$check_country_query = $db->bindVars($check_country_query, ':addressBookID', $check_customer->fields['customers_default_address_id'], 'integer');
$check_country = $db->Execute($check_country_query);
$_SESSION['customer_id'] = $check_customer->fields['customers_id'];
$_SESSION['customer_default_address_id'] = $check_customer->fields['customers_default_address_id'];
$_SESSION['customers_authorization'] = $check_customer->fields['customers_authorization'];
$_SESSION['customer_first_name'] = $check_customer->fields['customers_firstname'];
$_SESSION['customer_last_name'] = $check_customer->fields['customers_lastname'];
$_SESSION['customer_country_id'] = $check_country->fields['entry_country_id'];
$_SESSION['customer_zone_id'] = $check_country->fields['entry_zone_id'];
$sql = "UPDATE " . TABLE_CUSTOMERS_INFO . "
SET customers_info_date_of_last_logon = now(),
customers_info_number_of_logons = customers_info_number_of_logons+1
WHERE customers_info_id = :customersID";
$sql = $db->bindVars($sql, ':customersID', $_SESSION['customer_id'], 'integer');
$db->Execute($sql);
$zco_notifier->notify('NOTIFY_LOGIN_SUCCESS');
// bof: contents merge notice
// save current cart contents count if required
if (SHOW_SHOPPING_CART_COMBINED > 0) {
$zc_check_basket_before = $_SESSION['cart']->count_contents();
}
// bof: not require part of contents merge notice
// restore cart contents
$_SESSION['cart']->restore_contents();
// eof: not require part of contents merge notice
// check current cart contents count if required
if (SHOW_SHOPPING_CART_COMBINED > 0 && $zc_check_basket_before > 0) {
$zc_check_basket_after = $_SESSION['cart']->count_contents();
if (($zc_check_basket_before != $zc_check_basket_after) && $_SESSION['cart']->count_contents() > 0 && SHOW_SHOPPING_CART_COMBINED > 0) {
if (SHOW_SHOPPING_CART_COMBINED == 2) {
// warning only do not send to cart
$messageStack->add_session('header', WARNING_SHOPPING_CART_COMBINED, 'caution');
}
if (SHOW_SHOPPING_CART_COMBINED == 1) {
// show warning and send to shopping cart for review
$messageStack->add_session('shopping_cart', WARNING_SHOPPING_CART_COMBINED, 'caution');
}
}
}
// eof: contents merge notice
if (sizeof($_SESSION['navigation']->snapshot) > 0) {
// $back = sizeof($_SESSION['navigation']->path)-2;
//if (isset($_SESSION['navigation']->path[$back]['page'])) {
// if (sizeof($_SESSION['navigation']->path)-2 > 0) {
$origin_href = zen_href_link($_SESSION['navigation']->snapshot['page'], zen_array_to_string($_SESSION['navigation']->snapshot['get'], array(zen_session_name())), $_SESSION['navigation']->snapshot['mode']);
// $origin_href = zen_back_link_only(true);
$_SESSION['navigation']->clear_snapshot();
} else {
}
}
}
}
}
通过这次的zencart二次开发,我们实现了zencart会员登陆保存登陆状态。
来源:http://www.chinab4c.com
最近更新
常用插件
- ecshop红包修改成满多少减
我们在长期使用ecshop的时候,我们可以发现。ecshop的红包是一个非常强...
- ecshop分类树中统计商品数
最近忙于开发其他项目,在不少朋友不断要求和催促的情况下,做出了该小...
- ecshop降价通知登记插件
ecshop降价通知登记插件,主要是为了方便某些客户,对商品价格要求比...
- ecshop通用红包编码
很多时候,为了结合促销,必须扩展一下ecshop的红包功能。ecshop的红包...
- ecshop购物车功能改进[插件
ecshop购物车功能改进[插件套餐]主要是我们最近开发工作和开发项目中。...