

runs through the defined callbacks and calls the appropriate functions.executes the commit function (by default this is the Mysql PDO implementation).If ($this->getConnection()->getTransactionLevel() = 0) \Magento\Framework\Model\ResourceModel\AbstractResource::commit '_save_commit_after', $this->_getEventData()) Īnd the final bit to complete this is the commit function. $this->_eventManager->dispatch($this->_eventPrefix. Here is how the callback is added: $this->addCommitCallback()->commit() \Magento\Framework\Model\ResourceModel\Db\AbstractDb::saveĪnd here is how the event callback is defined.

The save_commit_after event is dispatched just a few lines after the save_after event however the difference is that the event is not dispatched right away but is executed as a callback. The save operation happens using a database transaction and this event does not wait for the transaction to be committed. The event is dispatched in \Magento\Framework\Model\ResourceModel\Db\AbstractDb::save after the save action has been executed. Which means that after saving the event the event will be eav_entity_attribute_save_after. '_save_after', $this->_getEventData()) įor example EAV entity model class extends the abst \Magento\Eav\Model\Entity\Attribute defines the eventPrefix as eav_entity_attribute. The first event occurs in afterSave function and dispatches the event with the event prefix which usually is enough to identify exact entity. The magic happens in the abstract model class \Magento\Framework\Model\AbstractModel however in order to fully understand the difference we will have to go deeper. Given this information we already know that we need to look into how the events are dispatched.
#Magento 2 devdocs install attribute code#
Using events and observers, you can run your custom code in response to a specific event. According to Magento devdocs: The events and observers are based on the publish-subscribe pattern. In this article we will explore and show the difference between 2 native events.
