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?


You should try with Plugin. The code below will work:


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    <type name="Magento\Sales\Api\CreditmemoRepositoryInterface">
        <plugin name="add_data_custom"


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,
) {

    //Your code here

    return $result;
  • it's not working Feb 24 '17 at 11:16
  • Did you try to clear Magento Cache and try again. It will work in case: saving Creditmemo. I'm using Magento 2.13 version. Feb 24 '17 at 11:18
  • I'm pretty sure it will work. I checked and tested. Feb 24 '17 at 11:39
  • Ok let me try it again Feb 26 '17 at 16:57
  • Yes It's Working Thanx @KhoaTruongDinh Jan 3 '20 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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