When using the customer_account_create event, the session model in my class is not able to return the customer ID using $this->customerSession->getId();.

However, for testing purposes, when using the customer_account_edited observer event, the session is returning the correct ID of the customer. I am guessing that the session is not fully initialized when using the account creation event.

How can I get the customer ID in my class when using the customer_account_create observer event. The session model doesn't seem to work.

1 Answer 1


I'm not 100% sure you can get the customer ID using the customer_account_create. I can't even find that event in the Magento 2.4 code (maybe it exists in 2.3).

Check the customer_register_success event. Looking at the class: vendor/magento/module-customer/Controller/Account/CreatePost.php

It seems very possible to get the customer ID from the observer, because this event is executed once the customer has been created:

     $customer = $this->accountManagement
                ->createAccount($customer, $password, $redirectUrl);

            ['account_controller' => $this, 'customer' => $customer]

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.