Magento设置商店ID - 客户登录 - 但仍然注销

时间:2014-06-05 09:23:07

标签: magento login web store

我有一个被覆盖的AccountController,其中我将当前商店设置为当前正在运行的另一个(例如:客户在网站默认和存储默认,进入登录页面,单击登录,我的loginPostAction将商店设置为id “2”(在网站2上),然后执行父代码loginPostAction。当然,商店已设置,但在登录并重定向到主页后,客户不再登录...

客户 - > sendlogindata-> myaccountcontroller设置store->原始帐户控制器登录而不会出错(导致$ session customer设置) - >重定向到home->客户不再登录...

我用Mage :: app() - > setCurrentStore($ id)设置商店; 。并且在index.php中,我有一个额外的地方,商店也被设置为正确的id(2),这可行...但客户不再登录..会话的问题导致不同的网站?

我不想全球共享客户..每个网站都有自己的客户,但每个客户必须能够通过在登录前设置正确的商店ID登录默认商店

AccountController.php覆盖:

public $Website_Ids = array(
    array("code" => "gerstore", "id" => "3", "website" => "ger"),
    array("code" => "ukstore", "id" => "2", "website" => "uk"),
    array("code" => "esstore", "id" => "4", "website" => "es"),
    array("code" => "frstore", "id" => "5", "website" => "fr")
);

public function loginPostAction()
{
    $login = $this->getRequest()->get('login');
    if(isset($login['username']))
    {
        $found = null;
        foreach($this->Website_Ids as $WebsiteId)
        {
            $customer = Mage::getModel('customer/customer');
            $customer->setWebsiteId($WebsiteId['id']);
            $customer->loadByEmail($login['username']);
            if(count($customer->getData()) > 0)
            {
                $found = $WebsiteId;
            }
        }
        if($found != null && Mage::app()->getStore()->getId() != $found['id'])
        { /* found, so set currentstore to id */
            Mage::app()->setCurrentStore($found['id']);
            $_SESSION['current_store_b2b'] = $found;
        } /* not found, doesn't matter cause mage login exception handling */
    }
    parent::loginPostAction();
}

Index.php:

session_start();
$session = $_SESSION['current_store_b2b'];

if($session != null || $session != "")
{
    Mage::app()->setCurrentStore($session['id']);
    Mage::run($session['code'], 'store');
}
else
{
    /* Store or website code */
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

    /* Run store or run website */
    $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
    Mage::run($mageRunCode, $mageRunType);
}

是什么事?

编辑:网站也发生了变化我通过Mage :: app()检查了 - > getWebsite() - > getName();

感谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

的index.php:

session_start();
$session = $_SESSION['current_store_b2b'];

$mageRunType = 'store';

if($session != null || $session != "") {
    $mageRunCode = $session['code']);    
} else {
    $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
}

Mage::run($mageRunCode, $mageRunType);