I tried to execute this code from hook_user_login

require_once $_SERVER['DOCUMENT_ROOT'] . "/mage1/app/Mage.php";
  

  umask(0);
  Mage::App('default');
  $session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
  try {
    $session->login('alvaro@test.com', 'cec123');
   
    $session->setCustomerAsLoggedIn($session->getCustomer());

header('Location: http://'.$_SERVER[SERVER_NAME].'/mage1/customer/account/?SID='.$session->getSessionId()); 
    
  } catch (Exception $e) {
    print_r($e);
    exit;
  }

But not able to log-in to magento and it automatically logs out of Drupal.

But if i run this code separately in a simple php page it logs into magento

I user D7 and Mage 1.7

Comments

devendra modi’s picture

Hello ,

Have you got any solution on above ?

RoloDMonkey’s picture

Are you executing this code inside a module? What hooks are you implementing?

Have you looked for existing solutions?

https://www.drupal.org/project/magento_integration

--

Read more at iRolo.net