0

How can i catch customer_save_after_data_object after saving account information in frontend?

1

3 Answers 3

0

To get customer information after account register, you can used this event.

customer_register_success

The implementation are diffrent based on magento version.

0

There are two options available: 1. Plugin & 2. Observer

Example : 1. Getting customer object after saving using plugin

step i. Create di.xml in etc/frontend

[Project_DIR]/app/code/[Vendor_Name]/[Module_Name]/etc/frontend/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\Model\ResourceModel\CustomerRepository">
        <plugin name="[Your_Plugin_Name]" type="[Vendor_Name]\[Module_Name]\Plugin\CustomerAfterSave" sortOrder="10" disabled="false"/>
    </type>
</config>

step ii. Define the plugin class in Plugin/[Plugin_Class_Name].php

[Project_DIR]/app/code/[Vendor_Name]/[Module_Name]/Plugin/CustomerAfterSave.php

<?php
namespace [Vendor_Name]\[Module_Name]\Plugin;

use Magento\Customer\Model\ResourceModel\CustomerRepository;

/**
 * Class CustomerAfterSave
 * @package [Vendor_Name]\[Module_Name]\Plugin
 */
class CustomerAfterSave
{  
    /**
     * @param CustomerRepository $subject
     * @param $savedCustomer
     * @return mixed
     */
    public function afterSave(
        CustomerRepository $subject,
        $savedCustomer
    ) {
        /**
         * $savedCustomer is your saved customer object.
         */
        $customerId = $savedCustomer->getId();
        $customerFirstName = $savedCustomer->getFirstName();

        /**
         * For the list of available methods
         * Refer : Magento\Customer\Api\Data\CustomerInterface
         * 
         * If you want to use getData method then you need to load customer model using the
         * $customerId 
         */
        return $savedCustomer;
    }
}

If you want to use observer let me know I will post the process.

0

To get data with observer You can do like I described here: https://magento.stackexchange.com/a/299114/77243

Just simply change event name in events.xml file.

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.