当前位置: 动力学知识库 > 问答 > 编程问答 >

php - programmatically log customers into specific websites

问题描述:

Scenario :

  1. Magento Enterprise 1.12.0.2
  2. Multiple Websites setup and working
  3. Website Restrictions Enabled
  4. Registration has been heavily modified with custom registration modules.
  5. Customers are eventually created pro-grammatically, and assigned to websites (id) depending on some logic that surrounds which country they registered with. This all works great. If i navigate login from specific websites, (accounts are set to Global) then the customer is redirected to the homepage of the website that are logging into. no problems so far.

At this point I would like to change the functionality of the magento customer login actions. So with Native magento, a customer is redirected to a website, based on what website they are logging in on, eg :

  • customer arrives at /cn/landing and logs into the chinese website.
  • customer arrives at /uk/landing and logs into the UK website.
  • customer arrives at /us/landing and logs into the US website.

etc

I would like to customize magento in the following way :

No matter from where (/uk or /cn or /us) i would like to force the customer to be logged into a specific website (based on the country they specified during registration). The website is essentially arbitrary for this question.

*How can I pro-grammatically log the customer into a specific website, and then ensure they are redirected back to that website's homepage? *

So far I have I overridden the Mage_Customer_AccountController properly and have been looking at changing the loginPostAction and _loginPostRedirect methods.

So far I have the

$this->_redirectUrl($session->getBeforeAuthUrl(true));

working correctly, but on redirect, it kicks me back to the landing page, as the customer is being logged into the site they are using, not the website that depends on the customers country code.

If you look at the loginPostAction, you will see :

try {

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

Can I specify what website to login here?

If i look at the session login action it calls :

public function login($username, $password)

{

/** @var $customer Mage_Customer_Model_Customer */

$customer = Mage::getModel('customer/customer')

->setWebsiteId(Mage::app()->getStore()->getWebsiteId());

/*I thought setting the website here would change where

*the customer is logged into, but as far i can tell, thats not the case.*/

if ($customer->authenticate($username, $password)) {

$this->setCustomerAsLoggedIn($customer);

$this->renewSession();

return true;

}

return false;

}

I have followed the authenticate, setCustomerAsLoggedIn and renewSession function calls and so far my attempts have been fruitless. I cannot force a customer to login to a different website (different to where they are coming from).

Any suggestions before I start eating my keyboard?

分享给朋友:
您可能感兴趣的文章:
随机阅读: