Magento 2 — Module — Create Plugin

Plugin is a feature that Magento 2 Has to execute something base on it’s function. It can be beforeMethodName, aroundMethodName, and/or afterMethodName. You can read on the official page of it here :

How to Make it?

1. Create etc/di.xml

Go to etc directory to make this file.


  • Magento\Catalog\Controller\Adminhtml\Product\Save : Path to the Class that we want to intercept.
  • Icube_Training_AssignSaveProduct : Plugin Name.
  • Icube\Training\Plugin\AssignSaveProduct : Path to plugin/interceptor Class.

2. Create Plugin/ClassName.php

Inside the directory of Plugin, make that Class with the name Plugin\AssignSaveProduct :

Don’t forget to execute on command line bin/magento setup:di:compile and bin/magento cache:flush, then run it!

I wrote these tutorials for myself in future when I forget for the next steps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store