在外部页面上检查Magento登录 [英] Checking for Magento login on external page

查看:91
本文介绍了在外部页面上检查Magento登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试访问外部页面(同一服务器,相同域等)上的Magento项目时碰到了墙.我想看看用户是否登录到Magento,然后再在网站上显示他们的某些部分.

I'm hitting a wall here while trying to access items from Magento on an external page (same server, same domain, etc, etc). I want to see if the user is logged into Magento before showing them certain parts on the site.

请记住,此代码存在于Magento之外.

Keep in mind that this code exists outside of Magento.


Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));

if (empty($session)) 
{
  $session = Mage::getSingleton("customer/session");
}

if($session->isLoggedIn()) 
  echo "hi";

$cart = Mage::helper('checkout/cart')->getCart()->getItemsCount();
echo $cart;

$ cart返回0,我的购物车中肯定有产品. isLoggedIn()也返回false.我在这里做错了什么? Magento中是否有一个我需要打开或关闭的选项才能访问Magento之外的信息?

$cart returns 0, where I definitely have products in my cart. isLoggedIn() also returns false. What am I doing wrong here? Is there an option in Magento that I need to turn on or off to be able to access this information outside of Magento?

推荐答案

使用上面的代码,我在Magento文件夹中创建了一个php文件.从那里,添加购物车中的物品数量以及是否登录到数组并将其编码为json.我在外部页面上使用了一些jquery来抓取文件并提取所需的数据.

Using the code above, I created a php file in the Magento folder. From there, added the number of items in the cart and whether you were logged in or not to an array and encoded it as json. I used some jquery on my external page to grab the file and pull the data I needed.

不太理想的情况,但是现在可以使用.

Not quite the ideal situation, but it works for now.

这篇关于在外部页面上检查Magento登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆