Add a plugin (interceptor)
add-pluginGenerates before, after, or around plugin classes and di.xml declarations to modify core or third-party method behavior without rewriting the class.
Instructions
Generate a before, after or around plugin class and its di.xml declaration for a public method of a class or interface, adapted from the official plugins docs. Returns the files for the caller to write. Use it to change the behavior of a core or third-party method without rewriting the class.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| area | No | di.xml area: global (etc/di.xml) or an area folder (default global) | |
| type | Yes | Plugin type. The docs advise after over around unless the chain must be stopped. | |
| method | Yes | Public method to intercept (e.g. "getName", "save") | |
| module | Yes | Module name as Vendor_Module (e.g. "Acme_Reviews"), as registered in registration.php | |
| basePath | No | Module directory relative to the Commerce root (default "app/code/<Vendor>/<Module>") | |
| sortOrder | No | sortOrder attribute in di.xml | |
| pluginName | No | Plugin name in di.xml (default "<vendor>_<module>_<target>_<method>") | |
| pluginClass | No | Plugin class name inside <Module>\Plugin (default "<TargetShortName>Plugin") | |
| targetClass | Yes | Class or interface whose public method is intercepted (e.g. "Magento\Catalog\Model\Product") |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | Files to write. The server never writes to disk. | |
| notes | Yes | Next steps and caveats |