博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
magento登陆
阅读量:5931 次
发布时间:2019-06-19

本文共 5178 字,大约阅读时间需要 17 分钟。

magento判断用户登录

 

Magento 登陆之后返回登录之前的页面

magento 在登陆后一般会自动跳转到 My Account 页面

但是经常会有需求 就是登陆自动跳转到 之前的页面里面

工具/原料

  • php+mysql+apache

方法/步骤

  1.  

    只要加代码

     Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_secure'=>true)));或

         Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::helper("core/url")->getCurrentUrl());

    在之前的页面 就可以实现这个功能

  2.  

      <!-- <?php //判断用户是否是登录用户,如果不是登录用户就跳转到登录页面,登录成就进入网站的页面?>-->

              <?php

              Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());  //save requested URL for later redirection

              if(!Mage::getSingleton('customer/session')->isLoggedIn()) {  // if not logged in

                  header("Status: 301");

                //  header('Location: '.Mage::helper('core/url')->getHomeUrl(customer/account/login)) ;  // send to the login page

                 header('Location:'.Mage::getBaseUrl('web').'index.php/customer/account/login/'           ) ;

                  exit;

              }

             

              ?>

     

    magento在购物车中判断用户登录,如果没有登录就跳转到登录页面,红色字体代表新增代码

    首先进入app/code/local/idev/onestepchekcout/controllers/indexcontroller.php文件

    加上一个

     

     

     

    if(Mage::getSingleton( 'customer/session' )->isLoggedIn())

            {判断和

     else

            {       $redirect=Mage::getBaseUrl().'customer/account/create/';

                   Mage::app()->getFrontController()->getResponse()->setRedirect($redirect)->sendResponse();//这个是需要跳转到的登录页面或者是注册页面

            }

    即可

    放的位置代码如下:

     public function indexAction() {

     

            if(Mage::getSingleton( 'customer/session' )->isLoggedIn())

            {

              $quote = $this->getOnepage()->getQuote();

              if (!$quote->hasItems() || $quote->getHasError()) {

                  $this->_redirect('checkout/cart');

                  return;

              }

              if (!$quote->validateMinimumAmount()) {

                  $error = Mage::getStoreConfig('sales/minimum_order/error_message');

                  Mage::getSingleton('checkout/session')->addError($error);

                  $this->_redirect('checkout/cart');

                  return;

              }

              $this->loadLayout();

     

              if(Mage::helper('onestepcheckout')->isEnterprise() && Mage::helper('customer')->isLoggedIn()){

     

                  $customerBalanceBlock = $this->getLayout()->createBlock('enterprise_customerbalance/checkout_onepage_payment_additional', 'customerbalance', array('template'=>'onestepcheckout/customerbalance/payment/additional.phtml'));

                  $customerBalanceBlockScripts = $this->getLayout()->createBlock('enterprise_customerbalance/checkout_onepage_payment_additional', 'customerbalance_scripts', array('template'=>'onestepcheckout/customerbalance/payment/scripts.phtml'));

     

                  $rewardPointsBlock = $this->getLayout()->createBlock('enterprise_reward/checkout_payment_additional', 'reward.points', array('template'=>'onestepcheckout/reward/payment/additional.phtml', 'before' => '-'));

                  $rewardPointsBlockScripts = $this->getLayout()->createBlock('enterprise_reward/checkout_payment_additional', 'reward.scripts', array('template'=>'onestepcheckout/reward/payment/scripts.phtml', 'after' => '-'));

     

                  $this->getLayout()->getBlock('choose-payment-method')

                  ->append($customerBalanceBlock)

                  ->append($customerBalanceBlockScripts)

                  ->append($rewardPointsBlock)

                  ->append($rewardPointsBlockScripts)

                  ;

              }

     

              $this->renderLayout();

            }

            else

            {       $redirect=Mage::getBaseUrl().'customer/account/create/';

                   Mage::app()->getFrontController()->getResponse()->setRedirect($redirect)->sendResponse();

            }

        }

  3.  

    判断用户是否从结算页面当中进入的,如果是从结算页面当中进入登录的或者是注册的那么需要进入下一步操作

      首先在form表单中加个<input name="xxx" value="xxxx" type="hidden"/>代码如下:

    <form id="login-form" action="http://www.wellsupplier.com/index.php/customer/account/loginPost/" method="post">

                  <input type="hidden" value="check-out" name="cart-name"/>

    或者跳转到进入登录注册页面前一页

     

      <?php echo $currlink=substr($_SERVER['HTTP_REFERER'],27); ?>

           <input type="hidden" value="<?php echo $currlink;?>" name="cart-name"/>

     

    然后去loginPostAction方法中进行判断,代码路径D:\Program Files\wamp\www\focalpriced\app\code\core\Mage\Customer\controllers\accountcontrollers.php文件

    然后找到public function loginPostAction()方法 ;

     

     public function loginPostAction()

        {            

        $chac=$this->getRequest()->getParam("cart-name");  //获取表单的传过来的值

       

            if ($this->_getSession()->isLoggedIn()) {

                $this->_redirect('*/*/');

                return;

            }

            $session = $this->_getSession();

     

            if ($this->getRequest()->isPost()) {

                $login = $this->getRequest()->getPost('login');

                if (!empty($login['username']) && !empty($login['password'])) {

                    try {

                        $session->login($login['username'], $login['password']);

                        if ($session->getCustomer()->getIsJustConfirmed()) {

                            $this->_welcomeCustomer($session->getCustomer(), true);

                        }

                    } catch (Mage_Core_Exception $e) {

                        switch ($e->getCode()) {

                            case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:

                                $value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']);

                                $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);

                                break;

                            case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:

                                $message = $e->getMessage();

                                break;

                            default:

                                $message = $e->getMessage();

                        }

                        $session->addError($message);

                        $session->setUsername($login['username']);

                    } catch (Exception $e) {

                        // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password

                    }

                } else {

                    $session->addError($this->__('Login and password are required.'));

                }

            }

            if(isset($chac)){      //判断表单的值进行跳转

       

            $redirect=Mage::getBaseUrl().$chac;

             Mage::app()->getFrontController()->getResponse()->setRedirect($redirect)->sendResponse();

     

            } else  {

            $this->_loginPostRedirect();

            }

        }

转载地址:http://sfutx.baihongyu.com/

你可能感兴趣的文章
有序的双链表
查看>>
项目管理学习笔记之二.工作分解
查看>>
Linux系统启动流程详解
查看>>
测试人员必学的软件快速测试方法(二)
查看>>
程序员全国不同地区,微信(面试 招聘)群。
查看>>
【干货】界面控件DevExtreme视频教程大汇总!
查看>>
闭包 !if(){}.call()
查看>>
python MySQLdb安装和使用
查看>>
Java小细节
查看>>
poj - 1860 Currency Exchange
查看>>
chgrp命令
查看>>
Java集合框架GS Collections具体解释
查看>>
洛谷 P2486 BZOJ 2243 [SDOI2011]染色
查看>>
linux 笔记本的温度提示
查看>>
数值积分中的辛普森方法及其误差估计
查看>>
Web service (一) 原理和项目开发实战
查看>>
跑带宽度多少合适_跑步机选购跑带要多宽,你的身体早就告诉你了
查看>>
广平县北方计算机第一届PS设计大赛
查看>>
深入理解Java的接口和抽象类
查看>>
java与xml
查看>>