0
function custom_user_login($edit, $account) {

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

  umask(0);
  Mage::App('default');
  $session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
  try {
    $session->login('[email protected]', 'cec123');

    $session->setCustomerAsLoggedIn($session->getCustomer());
  } catch (Exception $e) {
    print_r($e);
    exit;
  }

i am using this set of code from my D7 installation to log-in to magento.But it is not loggin into either D7 or magento.

But when i run this code from a seperate simple php file outside it logs in to magento successfully. what could be the problem.

3
  • can anybody suggest how to view the session and cookie info after a user is logged in
    – zamil
    Commented Dec 24, 2012 at 12:56
  • You've closed the try block with curly brace }, also the catch block; but you didn't close the function.
    – AjitS
    Commented Dec 24, 2012 at 13:13
  • @indrock: it was mistake when i copied it here. in code it is properly closed
    – zamil
    Commented Dec 27, 2012 at 7:13

2 Answers 2

0

The function signature is not right, which may be the reason for the code not executing. See the docs for hook_user_login function.

The parameter $edit is passed by reference and not directly by value. So, the correct definition your function should be,

function custom_user_login(&$edit, $account) {

  // rest of the code goes here (not duplicating).

}

Also make sure, your modules name is custom and it has files custom.info and custom.module in the module directory. And offcourse, enable the module ;-)

Also, to suggest you to look into the session and cookie info (based on your comment), you can put an echo '<pre>';print_r($_COOKIE); echo </pre> inside your theme's template.php file. Or simply install the Devel module, and enter dpm($_COOKIE); inside your template.php, to see a nicely formatted result. You'll need to clear the cache to again load the fresh template files. Similarly, you can print the $_SESSION superglobal to see the session information.

2
  • I made the $edit pass by reference, but still the output is same. not loggin into both D7 or magento. but am sure its loggin into D7 since it is entering the hook_user_login.I believe it is loggin out at some point. any insights from anybody
    – zamil
    Commented Dec 27, 2012 at 7:11
  • i tried to print the $_SESSION before and after login as u mentioned. but it returns an empty array.Cookie array i have added to your answer. plz see it.
    – zamil
    Commented Dec 27, 2012 at 9:04
0

I used Rules module to set a rule and redirect after that event occurs.

Its not fully error proof. But it works. It logs into both Drupal and Magento

I will update this if i find some errors once i dig deep.

For the time being its fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.