I made an observer for the catalog_product_save_after
event.
I need to do some changes to the "brother" products.
To do this, I get the parent product id and then all his childens.
For each children (except the product where the event was triggered) I do my mods and then I call the save()
method of \Magento\Catalog\Model\ProductFactory
.
When the save()
method is called, another event catalog_product_save_after
is triggered, so I'm in a loop.
I want to observe the event when the form is submitted from the admin panel only, and not when I save the product programmatically.
What i thought i would do is to pass a parameter when I call the save()
method, so next time the event is triggered, if my parameter exists I quit my observer.
I tried setting a session parameter like:
$this->_session->start();
if( $this->_session->getMyParam() !== null ){
return false;
}
$this->_session->setMyParam('true');
...
$this->_session->unsMyParam();
but doesn't work. It seems the MyParam is always set, so my function return false every time.
Please any suggestion will be appreciated.
Thanks