Hi,
the documentation best practice talks about avoiding the cyclic event loop.
https://devdocs.magento.com/guides/v2.3/ext-best-practices/extension-coding/observers-bp.html
Can someone please help how to solve the below problem:
I am synchronising customer information in Magento (M2) with an external system (let's say X). The flows that should be in place are:
M2 => X (by implementing the event observers on save and delete on customer, and, then call the rest server on X to send the data)
X => M2 (system X calls existing REST API for Magento)
How do I solution so that the save event is not triggered back to X for an update coming from X (via the rest API)?
Example scenario is:
In M2 - I have 2 observers that will listen to customer
Solved! Go to Solution.
If the same event is used for both directions of data flow, in that case in your plugin or observer you can have small logic to check controller, action, router etc.
For outgoing data flow, you can have some identifier or special parameter in the payload which distinguishes incoming and outgoing requests.
class Index { public function __construct( \Magento\Framework\App\Action\Context $context ){ } public function execute() { $moduleName = $this->request->getModuleName(); $controller = $this->request->getControllerName(); $action = $this->request->getActionName(); $route = $this->request->getRouteName(); echo $moduleName."<br/>"; echo $controller."<br/>"; echo $action."<br/>"; echo $route."<br/>"; } }
If the same event is used for both directions of data flow, in that case in your plugin or observer you can have small logic to check controller, action, router etc.
For outgoing data flow, you can have some identifier or special parameter in the payload which distinguishes incoming and outgoing requests.
class Index { public function __construct( \Magento\Framework\App\Action\Context $context ){ } public function execute() { $moduleName = $this->request->getModuleName(); $controller = $this->request->getControllerName(); $action = $this->request->getActionName(); $route = $this->request->getRouteName(); echo $moduleName."<br/>"; echo $controller."<br/>"; echo $action."<br/>"; echo $route."<br/>"; } }