What is the best way to identify a new customer when using an afterSave Plugin?

Or should I use a different approach to do something with new customers?


Whenever a customer registered through the frontend form Magento trigger the customer_register_success event:

File: vendor/magento/module-customer/Controller/Account/CreatePost.php

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

Or either you can find the newly created customers by comparing the saved customer and previous customer data by observing customer_save_after_data_object event.

File: vendor\magento\module-customer\Model\ResourceModel\CustomerRepository.php

        'customer_data_object' => $savedCustomer,
        'orig_customer_data_object' => $prevCustomerData,
        'delegate_data' => $delegatedNewOperation
            ? $delegatedNewOperation->getAdditionalData() : []
  • Thanks MageAj. The customer_save_after_data_object was exactly what I was looking for. Now I just created an observer for it and added $isNewCustomer = $observer->getData('orig_customer_data_object') === null; – Ricardo Martins Mar 1 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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