When user login in store(magento site) it will be automatically login in website(wordpress site). If the user is registered both site with same user name and password. And also user is logout in store it will be automatically logout from website.
Please see below steps:
Add this code in index.php file which is located in root folder of store files.
<?php
if ( strpos($_SERVER['REQUEST_URI'], 'index.php/admin') === FALSE )
{
define('WP_USE_THEMES', false);
require_once('/wp-load.php'); // Add Absolute path of wp-load.php
}
if (!function_exists('__')) {
function __() {
return Mage::app()->getTranslator()->translate(func_get_args());
}
}
?>
Then after go to /app/code/core/Mage/Core/functions.php and find
<?php
function __()
{
return Mage::app()->getTranslator()->translate(func_get_args());
}
?>
And replace this
<?php
if (!function_exists('__')) {
function __()
{
return Mage::app()->getTranslator()->translate(func_get_args());
}
}
?>
Then after add this function in website theme's functions.php
wp-content/themes/themefolder/functions.php
<?php
function login_with_email_address($username) {
$user = get_user_by_email($username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
add_action('wp_authenticate','login_with_email_address');
?>
Then after copy this file /app/code/core/Mage/Customer/controllers/AccountController.php and put in /app/code/local/Mage/Customer/controllers/AccountController.php find loginPostAction and replace with below code.
<?php
/**
* Login post action
*/
public function loginPostAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session = $this->_getSession();
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
if (!empty($login['username']) && !empty($login['password'])) {
try {
$session->login($login['username'], $login['password']);
$user = login_with_email_address($login['username']);
$creds = array();
$creds['user_login'] = $login['username'];
$creds['user_password'] = $login['password'];
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) :
echo $user->get_error_message();
endif;
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID);
if ($session->getCustomer()->getIsJustConfirmed()) {
$this->_welcomeCustomer($session->getCustomer(), true);
}
} catch (Mage_Core_Exception $e) {
switch ($e->getCode()) {
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
$value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']);
$message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
break;
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
$message = $e->getMessage();
break;
default:
$message = $e->getMessage();
}
$session->addError($message);
$session->setUsername($login['username']);
} catch (Exception $e) {
// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
}
} else {
$session->addError($this->__('Login and password are required.'));
}
}
$this->_loginPostRedirect();
}
?>
Then after find logoutAction replace with below code.
<?php
public function logoutAction()
{
$this->_getSession()->logout()
->setBeforeAuthUrl(Mage::getUrl());
wp_logout();
$this->_redirect('*/*/logoutSuccess');
}
?>
Now you can sucessfully login with store to automatically login with website.
Please see below steps:
- Install extension http://www.magentocommerce.com/magento-connect/magento-wordpress-integration.html in your store using connect manager.
- Setup your website and connect with Store.
- Now you will be able automatically login with store admin panel to website admin panel.
- For merge customer and user login you have to changes in code like.
Add this code in index.php file which is located in root folder of store files.
<?php
if ( strpos($_SERVER['REQUEST_URI'], 'index.php/admin') === FALSE )
{
define('WP_USE_THEMES', false);
require_once('/wp-load.php'); // Add Absolute path of wp-load.php
}
if (!function_exists('__')) {
function __() {
return Mage::app()->getTranslator()->translate(func_get_args());
}
}
?>
Then after go to /app/code/core/Mage/Core/functions.php and find
<?php
function __()
{
return Mage::app()->getTranslator()->translate(func_get_args());
}
?>
And replace this
<?php
if (!function_exists('__')) {
function __()
{
return Mage::app()->getTranslator()->translate(func_get_args());
}
}
?>
Then after add this function in website theme's functions.php
wp-content/themes/themefolder/functions.php
<?php
function login_with_email_address($username) {
$user = get_user_by_email($username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
add_action('wp_authenticate','login_with_email_address');
?>
Then after copy this file /app/code/core/Mage/Customer/controllers/AccountController.php and put in /app/code/local/Mage/Customer/controllers/AccountController.php find loginPostAction and replace with below code.
<?php
/**
* Login post action
*/
public function loginPostAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session = $this->_getSession();
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
if (!empty($login['username']) && !empty($login['password'])) {
try {
$session->login($login['username'], $login['password']);
$user = login_with_email_address($login['username']);
$creds = array();
$creds['user_login'] = $login['username'];
$creds['user_password'] = $login['password'];
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) :
echo $user->get_error_message();
endif;
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID);
if ($session->getCustomer()->getIsJustConfirmed()) {
$this->_welcomeCustomer($session->getCustomer(), true);
}
} catch (Mage_Core_Exception $e) {
switch ($e->getCode()) {
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
$value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']);
$message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
break;
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
$message = $e->getMessage();
break;
default:
$message = $e->getMessage();
}
$session->addError($message);
$session->setUsername($login['username']);
} catch (Exception $e) {
// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
}
} else {
$session->addError($this->__('Login and password are required.'));
}
}
$this->_loginPostRedirect();
}
?>
Then after find logoutAction replace with below code.
<?php
public function logoutAction()
{
$this->_getSession()->logout()
->setBeforeAuthUrl(Mage::getUrl());
wp_logout();
$this->_redirect('*/*/logoutSuccess');
}
?>
Now you can sucessfully login with store to automatically login with website.
No comments:
Post a Comment
Thanks for visit blog.