magento-plugins-interceptors

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.

17 stars

Best use case

magento-plugins-interceptors is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

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.

Teams using magento-plugins-interceptors should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/magento-plugins-interceptors/SKILL.md --create-dirs "https://raw.githubusercontent.com/OrcaQubits/agentic-commerce-skills-plugins/main/dist/antigravity/magento2-commerce/.agent/skills/magento-plugins-interceptors/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/magento-plugins-interceptors/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How magento-plugins-interceptors Compares

Feature / Agentmagento-plugins-interceptorsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Magento 2 Plugins (Interceptors)

## Before writing code

**Fetch live docs**: Fetch `https://developer.adobe.com/commerce/php/development/components/plugins/` 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

- Method: `beforeOriginalMethod($subject, $arg1, $arg2, ...)`
- Return: array of modified arguments, or `null` to keep originals
- Executes before the original method

### After Plugin

- Method: `afterOriginalMethod($subject, $result, ...$args)`
- Return: modified result
- Executes after the original method
- Since 2.2: receives original arguments after `$result`

### Around Plugin

- Method: `aroundOriginalMethod($subject, callable $proceed, $arg1, $arg2, ...)`
- Return: whatever the method should return
- Must call `$proceed($arg1, $arg2)` to invoke the original (or skip it)
- **Use sparingly** — most cases are better served by before + after

### Plugin Declaration (di.xml)

Plugins are declared as children of a `<type>` element:
- `name` — unique plugin identifier
- `type` — fully qualified plugin class name
- `sortOrder` — execution priority (lower runs first)
- `disabled` — `true` to disable

### 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

- `final` classes or `final` methods
- `__construct()` (constructor)
- `static` methods
- Non-public methods (`protected`, `private`)
- Virtual types (directly)
- Classes instantiated before the interception framework bootstraps

### Plugin Class Location

Place plugin classes in the `Plugin/` directory of your module:
```
VendorName/ModuleName/Plugin/SomePlugin.php
```

## Best Practices

- Prefer before/after over around — around is harder to debug
- Always call `$proceed` in around plugins unless intentionally skipping
- Use descriptive plugin names to avoid conflicts
- Set appropriate sortOrder when multiple plugins target the same method
- Check if a before or after plugin can achieve the goal before using around
- Test with other modules' plugins to verify sortOrder interactions

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

Related Skills

medusa-plugins

17
from OrcaQubits/agentic-commerce-skills-plugins

Develop and publish Medusa v2 plugins — plugin structure, plugin vs module comparison, npm packaging, and reusable plugin template. Use when building distributable Medusa extensions.

magento-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Write tests for Magento 2 — PHPUnit unit tests, integration tests, MFTF functional tests, and API tests. Use when implementing test coverage for modules, debugging, or setting up CI/CD test pipelines.

magento-setup

17
from OrcaQubits/agentic-commerce-skills-plugins

Set up a Magento 2 Open Source project — installation, Composer setup, system requirements verification, and initial configuration. Use when starting a new Magento project or setting up a development environment.

magento-service-contracts

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement Magento 2 service contracts — repository interfaces, data interfaces, SearchCriteria, and the repository pattern. Use when building module APIs, data access layers, or integrating with Magento's Web API.

magento-security

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement Magento 2 security — CSP, 2FA, CSRF protection, ACL, admin security configuration, input validation, and security best practices. Use when hardening a Magento installation or reviewing security posture.

magento-performance

17
from OrcaQubits/agentic-commerce-skills-plugins

Optimize Magento 2 performance — full page cache (Varnish), Redis, indexer tuning, JavaScript/CSS optimization, database optimization, and profiling. Use when diagnosing slow pages, optimizing load times, or configuring caching.

magento-module-dev

17
from OrcaQubits/agentic-commerce-skills-plugins

Create Magento 2 custom modules — registration, directory structure, models, resource models, collections, declarative schema, and data/schema patches. Use when building new modules or understanding module architecture.

magento-frontend

17
from OrcaQubits/agentic-commerce-skills-plugins

Build Magento 2 frontend — layout XML, blocks, PHTML templates, ViewModels, themes, JavaScript (RequireJS/KnockoutJS), and LESS/CSS. Use when customizing the storefront, building themes, or working with frontend components.

magento-events-cron

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement Magento 2 events, observers, cron jobs, and message queues. Use when building event-driven logic, scheduled tasks, or asynchronous processing.

magento-eav-attributes

17
from OrcaQubits/agentic-commerce-skills-plugins

Work with Magento 2 EAV (Entity-Attribute-Value) system — create custom attributes, attribute sets, manage EAV tables, and understand the EAV data model. Use when adding product/category/customer attributes or working with the attribute system.

magento-di

17
from OrcaQubits/agentic-commerce-skills-plugins

Configure Magento 2 dependency injection — di.xml, types, virtual types, preferences, argument replacement, and Object Manager. Use when wiring dependencies, creating class variations, or configuring module integrations.

magento-deploy

17
from OrcaQubits/agentic-commerce-skills-plugins

Deploy Magento 2 — deployment modes, static content deployment, DI compilation, CLI commands, zero-downtime strategies, and CI/CD pipeline setup. Use when preparing for production deployment or building deployment automation.