I have used this event "customer_save_after_data_object"
used this code in events.xml file
<event name="customer_save_after_data_object">
<observer name="customer_save_after_observer" instance="Vendor\Sales\Observer\CustomereditPost" />
</event>
And this is the observer file
<?php
namespace Vendor\Module\Observer;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
class CustomereditPost implements ObserverInterface
{
protected $_request;
protected $_layout;
protected $_objectManager = null;
protected $_customerGroup;
private $logger;
protected $_customerRepositoryInterface;
/**
* @param \Magento\Framework\ObjectManagerInterface $objectManager
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Framework\ObjectManagerInterface $objectManager,
\Psr\Log\LoggerInterface $logger,
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface
){
$this->_layout = $context->getLayout();
$this->_request = $context->getRequest();
$this->_objectManager = $objectManager;
$this->logger = $logger;
$this->_customerRepositoryInterface = $customerRepositoryInterface;
}
/**
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(EventObserver $observer)
{
$this->logger->info(' --jafar123-- ');
$event = $observer->getEvent();
$customer = $observer->getCustomerDataObject();
$customer->getId();
$customer->getFirstName();
$customerId = $customer->getId();
$customerData = $this->_customerRepositoryInterface->getById($customerId);
$customerData->setFirstName('jaf');
$customerData->save();
return $this;
}
}
On saving customer from admin panel, I need to trigger this file.
Just setting the customer first name from this event. But the name is not changed.
The observer file is loading. Can anybody help me on this please?