ArivuAjay
ArivuAjay

Reputation: 135

Magento 2 Observer Manual Dispatch/Trigger Observer

I already developed a Magento 1.* extension. The extension contains observer methods. For ex., When I save the customer, call the observer & send the customer data to some API to save the data.

$customer = Mage::getModel('customer/customer')->load($postData['id']);
$customer->setFirstname($customer->firstname);
$customer->save();

But Magento 2.* won't execute the customer observer. If I save the customer data in the controller, Observer is not executed.

Thanks in advance.

Upvotes: 0

Views: 686

Answers (1)

ArivuAjay
ArivuAjay

Reputation: 135

Sorry friends.. Got it.

$customer = $this->_objectManager->create('Magento\Customer\Model\Customer')->load((int) $postData['id']);
$this->_eventManager->dispatch('customer_save_before',['customer' => $customer]);

Upvotes: 0

Related Questions