OpenCart 中的 Javascript 警报和重定向

标签 javascript redirect opencart alert

我正在网站上工作 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
        }
    }
?>

谁能告诉我如何获取消息、注销和重定向客户。如果我不注销他们,他们将无法尝试重新登录,除非他们清除浏览器。

最佳答案

<?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>;" } } ?>

希望这对你有用,但我还没有调试它。

关于OpenCart 中的 Javascript 警报和重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26921040/

相关文章:

javascript - D3 无法渲染简单的线条

javascript - 让div覆盖整行

.htaccess - htaccess 重定向百分号

jquery - 如何设置 Jquery 菜单的缓存?

php - Opencart:如何获取运输方式的代码

JavaScript GTM

c# - 在 JavaScript 中获取元素

java - 验证后 Spring 返回

linux - 将硬编码程序输出重定向到标准输出?

php - Opencart 3 产品不获取数据 mysql 查询不显示产品