0

我正在尝试在顶部菜单中实现“登录/注销”链接,但在 magento 之外的页面上。到目前为止,我尝试过以下操作:我使用此脚本加载 Mage,然后根据是否登录的客户显示链接,而不是简单的“登录”链接。

<?php
    require_once('tmg/app/Mage.php'); //Path to Magento
    umask(0);
    Mage::app();
?>
<?php if (Mage::getSingleton('customer/session')->isLoggedIn()==0): ?>
<a href="<?php echo $this->getUrl('customer/account/login') ?>"><?php echo $this- >__('Log In') ?></a>
<?php else: ?>
    <a href="<?php echo $this->getUrl('customer/account/logout') ?>"><?php echo $this->__('Log Out') ?></a>
<?php endif ?>

浏览器中显示的是此代码之前的页面,之后绝对没有。我还尝试将它自己放入一个测试文件并运行它,但它也会导致一个空的浏览器窗口,没有源代码或任何可见的东西。我究竟做错了什么?

4

3 回答 3

2

尝试这个..

require_once('tmg/app/Mage.php');

    umask(0);
    Mage::app();
//GET SESSION DATA
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));

$customer_data = Mage::getModel('customer/customer')->$session->id;

//CHECK IF LOGGED IN
if($session->isLoggedIn()){
?>
<a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>customer/account/logout"><?php echo "Log Out"; ?></a>

<?php 
} else {
?>
<a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>customer/account/login"><?php echo "Log in"; ?></a>
<?php 
exit;
}
于 2013-10-18T16:38:36.930 回答
1

请检查这是否有帮助!

require_once 'app/Mage.php';


umask(0);

Mage::app('default');

Mage::getSingleton('core/session', array('name' => 'frontend'));

$sessionCustomer = Mage::getSingleton("customer/session");

if($sessionCustomer->isLoggedIn()) {
  echo "Logged";
} else {
   echo "Not Logged";
}

有关更多详细信息,请在此处查看Magento 客户登录

于 2014-06-27T17:36:46.173 回答
0

The above solutions worked for me in Firefox, but not Chrome. I had to add

Mage::getSingleton('customer/session')->start();

after the line

Mage::app('default');

Then it appears to work fine. (magento 1.9)

于 2014-09-01T09:13:00.497 回答