I want to add aftersave
and beforesave
method of Magento 2 in my model.
How can I do this and which model I have to called ?
I want to add aftersave
and beforesave
method of Magento 2 in my model.
How can I do this and which model I have to called ?
you can used _beforeSave
and _afterSave
in your ResourceModel
<?php
namespace Spacename\Modulename\Model\ResourceModel;
class Test extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb {
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
// do your logic here
}
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
//do your logic here
}
}