Magento plugins interceptors

From OrcaQubits/agentic-commerce-skills-plugins · View interactive version

Magento plugins interceptors is an AI agent skill from the GitHub repository OrcaQubits/agentic-commerce-skills-plugins. Implement Magento 2 plugins (interceptors) — before, after, and around methods for modifying class behavior without inheritance. Use when extending core or third-party module functionality.

How to use this skill

Skill file

Magento 2 Plugins (Interceptors)

Before writing code

Fetch live docs: Fetch https://developer.adobe.com/commerce/php/development/components/ for the official plugins guide with exact method signatures and limitations.

Conceptual Architecture

What Plugins Do

Plugins intercept public method calls on any non-final class, allowing you to modify arguments, return values, or wrap entire method execution — without modifying the original class or using inheritance.

Three Plugin Types

| Type | Method Prefix | Purpose | Receives |

|------|-------------|---------|----------|

| Before | before<MethodName> | Modify input arguments | Subject + original args |

| After | after<MethodName> | Modify return value | Subject + result (+ original args) |

| Around | around<MethodName> | Wrap entire execution | Subject + $proceed callable + original args |

Before Plugin

After Plugin

Around Plugin

Plugin Declaration (di.xml)

Plugins are declared as children of a <type> element:

Execution Order

  1. Before plugins execute in sortOrder (ascending)
  2. Around plugin's pre-$proceed code
  3. Original method (via $proceed)
  4. Around plugin's post-$proceed code
  5. After plugins execute in sortOrder (ascending)

Limitations — Cannot Intercept

Plugin Class Location

Place plugin classes in the Plugin/ directory of your module:

VendorName/ModuleName/Plugin/SomePlugin.php

Best Practices

Fetch the plugins documentation for exact method signatures, the latest limitations list, and any changes in recent Magento versions before implementing.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.