I need to extend creditmemo save action:
- Update post data before action method call
- Update database after creditmemo save.
Which method is better Plugin or preference and if Plugin then how can I update post object?
I need to extend creditmemo save action:
Which method is better Plugin or preference and if Plugin then how can I update post object?
You should try with Plugin. The code below will work:
etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Api\CreditmemoRepositoryInterface">
<plugin name="add_data_custom"
type="Vendor\Module\Model\Plugin\CreditmemoAddData"/>
</type>
</config>
In your Plugin:
public function beforeSave(
\Magento\Sales\Api\CreditmemoRepositoryInterface $subject,
\Magento\Sales\Api\Data\CreditmemoInterface $entity
)
{
//Your code here
}
public function afterSave(
\Magento\Sales\Api\CreditmemoRepositoryInterface $subject,
$result
) {
//Your code here
return $result;
}