How to get user ID from customer_register_success event in Magento?

How to get user ID from customer_register_success event in Magento?

August 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get user ID from customer_register_success event in Magento?

Retrieving User ID from Customer Register Success Event in Magento

When working with Magento’s customer registration process, it is common to need access to both the session ID and user ID of the newly registered account. In this article, we’ll guide you through retrieving these critical pieces of information using an event observer for the customer_register_success event.

Understanding Your Current Approach

You’re on the right track with your current implementation:

public function getUserReg($observer){
    $session = Mage::getSingleton('core/session');
    $session_id = $session->getEncryptedSessionId();

    $customer_data = Mage::getSingleton('customer/session')->getCustomer();
    $user_id = $customer_data->entity_id;

    Mage::log("User Registration SESSION: " . $session_id, null, 't.log');
    Mage::log("User Registration USER: " . $user_id, null, 't.log');
}

You’ve correctly used the Mage::getSingleton('core/session') to retrieve the encrypted session ID. However, there are a couple of adjustments needed regarding the user ID retrieval.

Retrieving User ID Correctly

The issue with your current approach is that you’re using Mage::getSingleton('customer/session')->getCustomer() to get customer data after registration has completed. By this point, the session may not have been updated with the new customer information yet.

To ensure you are getting the most recent user ID, we recommend a slight refactoring:

public function getUserReg($observer){
    $session = Mage::getSingleton('core/session');
    $session_id = $session->getEncryptedSessionId();

    // Use event data to directly access the new customer object
    $customer_data = $observer->getEvent()->getCustomer();
    $user_id = $customer_data->getEntityId();

    Mage::log("User Registration SESSION: " . $session_id, null, 't.log');
    Mage::log("User Registration USER: " . $user_id, null, 't.log');
}

In this updated version, we are directly accessing the new customer object from the event data. This ensures that you are working with the freshest customer information available immediately after registration.

Conclusion

Retrieving both session ID and user ID during a customer_register_success event is crucial for many customizations in Magento. By using the event observer’s data, you can reliably access the most recent user information, ensuring your application behaves as expected when new customers register accounts.

Remember to always test these changes thoroughly and monitor logs for any unexpected behavior. If you need more advanced or complex solutions, consider checking out the advanced Magento tutorials at Laravel Company.

Happy coding, and let us know if you have any other questions about managing user data in Magento!

Extensions Customers Errors

Our network