I want to save a custom attribute value in my custom table after saving a customer from the admin panel, with an observer event, I only need the name of the event
-
1When you want this observer at time of customer creation or customer save? – Amit Naraniwal Feb 8 '19 at 9:12
You may use customer_save_after
and eventually check if the action comes from admin if that's required
If you have tried to find out the event during customer creation at Magento, then you can use adminhtml_customer_save_after
event.
$this->_eventManager->dispatch( 'adminhtml_customer_save_after', ['customer' => $customer, 'request' => $this->getRequest()] );
That this event, you get custom field data using $observer->getRequest()->getPostValue();
if you will add any custom field admin customer create and edit page.
Observer look Like:
<?php
namespace {VendorName}\{ModuelName}\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class SaveFromBackend implements ObserverInterface
{
/**
* Save A customer Annual Purchase Limit
*
* @param Observer $observer
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function execute(Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
$request = $observer->getEvent()->getRequest();
$postData = $request->getPostValue();
if (isset($postData['custom_field']))
) {
$customfield = $postData['custom_field'];
// Save data here
}
}
}
You can use customer_save_commit_after
event as this is triggered after the transaction is committed.