我正在使用网站https://wholesale.garrysun.com(使用opencart 1.5.4)并尝试添加一些代码,如果他们未以批发客户身份登录,则会首先将其重定向到登录页面。如果他们然后尝试登录并且没有注册为批发客户,它会告诉他们他们在错误的商店,将其注销并发送回常规网站。
除了消息部分,我已经完成了所有工作。我试图使用以下代码,但我只是在消息出现之前重定向。
<?php
if($this->config->get('config_store_id') == 1) { /*Check if wholesale store*/
if (!$logged) { /*Check if user is logged in, not = redirect to login page*/
$this->redirect('https://wholesale.garrysun.com/index.php?route=account/login');
} else if ( $this->customer->getCustomerGroupId() == '1' ) { /* Check if user is wholesale user */
/***************This Works - logs out client and redirects correctly*************/
/*$this->customer->logout();
$this->redirect("https://garrysun.com/");*/
?>
/*******This does NOT Work- gives alert and redirects but the client is not logged out ********/
<script language="javascript">
alert("This site is for Wholesale clients only. You will be redirected to our regular site.")
window.location.href = "https://garrysun.com/";
</script>
<?php
}
}
?>
任何人都可以告诉我如何获取消息,注销并重定向客户。如果我没有注销,除非他们清除浏览器,否则他们无法重新登录。
答案 0 :(得分:1)
<?php
if($this->config->get('config_store_id') == 1) {
if (!$logged) {
$this->redirect('https://wholesale.garrysun.com/index.php?route=account/login');
} else if ( $this->customer->getCustomerGroupId() == '1' ) { ?>
<script src="Where Javascript goes"> // or just use the <script> tag
function alertUser() {
if (window.confirm(‘put stuff here’)) {
window.location.href=‘put link here’;
}
}
</script>
<?php
$this->customer->logout();
echo "<script>alertUser();</script>;" } } ?>
希望这对你有用,但是我没有对它进行过修改。