简体   繁体   English

opencart中的javascript登录弹出窗口

[英]javascript login popup in opencart

Friends I am having a strange issue with no idea what went wrong. 朋友,我遇到一个奇怪的问题,不知道出了什么问题。

my company asked me to show a opopup with login options in opencart ie user cant browse products unless he/she register or login. 我的公司要求我在opencart中显示带有登录选项的opopup,即,除非他/她注册或登录,否则用户无法浏览产品。

i used the following script to do that 我用下面的脚本来做到这一点

ISSUE it works fine once or twice after that the popup shows blank. 问题 ,弹出窗口显示为空白后,它可以正常工作一两次。

Codes 代码

<script type="text/javascript">

$(document).ready(function(){
$("#logpop").append('<div id="loginbox" class="loginbox"></div>');var a=$("#welcome a").first().html();
$("#welcome a").first().html('<span class="login"></span>');$("#welcome a .login").html(a);-1!=$("#welcome a[href]").first().attr("href").indexOf("register")?($("#loginbox").load("index.php?route=account/login .right form"), $("#loginbox").css("right","50px")):
($("#loginbox").load("index.php?route=account/account #content"),$("#loginbox").css("right","40px"));
$("#welcome > a .login").live("hover",function(){$("#welcome").addClass("active");$("#loginbox .breadcrumb").remove();$("#loginbox h1").remove();});
});

$(document).ready(function(){
-1==$(location).attr("href").indexOf("account/logout")&&$.cookie("url",$(location).attr("href"));$("#welcome a").first().removeAttr("href");$("#logpop").first().css("display","none");$("#login_dimming").first().css("display","none");   
});
</script>

friends can you please help me fix this problem 朋友,你能帮我解决这个问题吗

Instead of doing this via JS I'd suggest implementing a preAction that will check whether the user is logged-in and if not, it will redirect to the login/register screen. 建议不要实现通过JS执行此操作 ,该操作将检查用户是否已登录,如果未登录,则将重定向到登录/注册屏幕。

How to implement a preAction : look into index.php where a preAction for maintenance mode is registered: 如何实现preAction :查看index.php ,其中注册了用于维护模式的preAction:

// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));

You can add a new one: 您可以添加一个新的:

// Logged-in user required
$controller->addPreAction(new Action('common/login'));

and then of course look into the catalog/controller/common/maintenance.php to see how it is done. 然后当然要查看一下catalog/controller/common/maintenance.php以了解它是如何完成的。 You can implement something similar in Your new catalog/controller/common/login.php : 您可以在您的新catalog/controller/common/login.php实现类似的操作:

<?php
class ControllerCommonLogin extends Controller {
    public function index() {
        if (!$this->customer->isLogged()) {
            return $this->forward('account/login');
        }
    }
}

This is much easier, more MVC and better way of checking whether user is logged-in before he can start shopping. 这是更容易,更MVC的方法,并且是在开始购物之前检查用户是否已登录的更好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM