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:


if( $this->_session->getMyParam() !== null ){
    return false;




but doesn't work. It seems the MyParam is always set, so my function return false every time.

Please any suggestion will be appreciated.


1 Answer 1


You can use the "normal" php Session.




 $value = isset($_SESSION['PARAMETER_NAME']) ? $_SESSION['PARAMETER_NAME'] : null;

I use this cache prices from an external webservices and it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.