在Magento和Symfony之间共享用户会话变量

时间:2010-06-17 10:06:06

标签: session variables symfony1 magento

我们网站的一部分将使用 Symfony 其他 Magento 构建。我想知道是否可以在其中两个之间共享用户会话变量。

谢谢!

1 个答案:

答案 0 :(得分:2)

经过多次试验和错误后,我创建了以下工作。这是基于登录由Magento以外的平台管理的情况。

我无法找到与Magento之外的Magento分享会话的方法。相反,我创建了一个简单的Magento扩展,它挂钩到事件观察者'http_response_send_before'。

现在,只要Magento加载页面,模块就会检查用户是否登录到其他系统。如果是,它将检索该用户的电子邮件,并使用电子邮件地址作为标识符将用户登录到Magento,并为该客户设置会话。显然,客户必须已经存在于Magento中才能登录工作。

以下是文件和其中包含的代码。随意修改以使用您的系统。

/app/code/local/Verve/Session/etc/config.xml

<config>
<modules>
    <Verve_Session>
        <version>0.5.1</version>
    </Verve_Session>
</modules>
<frontend>
    <events> 
        <http_response_send_before>
            <observers>
                <session_login>
                    <type>model</type> 
                    <class>Verve_Session_Helper_Login</class> 
                    <method>loginEvent</method>
                </session_login> 
            </observers>
        </http_response_send_before>
    </events> 
</frontend>

/app/code/local/Verve/Session/Helper/Login.php

 class Verve_Session_Helper_Login extends Mage_Core_Helper_Abstract 
 { 

static function loginEvent($observer) { 

    $session = Mage::getSingleton('customer/session');

    if (!$session->isLoggedIn()) {


        YOUR CODE HERE, FIND EMAIL OF LOGGED IN USER


        if(@$email){

            $customer   = Mage::getModel('customer/customer'); 
            $customer->loadByEmail($email); 
            $session    = Mage::getSingleton('customer/session'); 
            $session->start();
            $session->setCustomer($customer);
            $url        = $_SERVER['REQUEST_URI'];
            Mage::app()->getFrontController()->getResponse()->setRedirect($url);

        }


    }   

}

 }

/app/etc/modules/Verve_Session.xml

<config>
<modules>
    <Verve_Session>
        <active>true</active>
        <codePool>local</codePool>
    </Verve_Session>
</modules>
</config>
相关问题