magento-service-contracts

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.

17 stars

Best use case

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

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.

Teams using magento-service-contracts 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-service-contracts/SKILL.md --create-dirs "https://raw.githubusercontent.com/OrcaQubits/agentic-commerce-skills-plugins/main/dist/antigravity/magento2-commerce/.agent/skills/magento-service-contracts/SKILL.md"

Manual Installation

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

How magento-service-contracts Compares

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

Frequently Asked Questions

What does this skill do?

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.

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 Service Contracts & Repositories

## Before writing code

**Fetch live docs**:
1. Fetch `https://developer.adobe.com/commerce/php/development/components/web-api/services/` for service contract guide
2. Fetch `https://developer.adobe.com/commerce/php/development/components/searching-with-repositories/` for SearchCriteria patterns
3. Web-search `site:developer.adobe.com commerce php development components service-contracts` for additional reference

## Conceptual Architecture

### What Service Contracts Are

Service contracts are **PHP interfaces** that define a module's public API. They guarantee backward compatibility — implementations can change across versions without breaking consumers.

### Three Interface Categories

1. **Repository Interfaces** (`Api/SomeRepositoryInterface.php`)
   - `getById($id)` — retrieve single entity
   - `save(SomeInterface $entity)` — create or update
   - `delete(SomeInterface $entity)` — remove
   - `getList(SearchCriteriaInterface $criteria)` — filtered/sorted/paginated results

2. **Data Interfaces** (`Api/Data/SomeInterface.php`)
   - Define getters and setters for entity fields
   - `getId()`, `setId($id)`, `getName()`, `setName($name)`, etc.
   - Constants for field names: `const NAME = 'name';`

3. **SearchResults Interface** (`Api/Data/SomeSearchResultsInterface.php`)
   - Extends `Magento\Framework\Api\SearchResultsInterface`
   - Wraps `getItems()` / `setItems()` with typed returns

### SearchCriteria Pattern

Used for querying repositories with filters, sorting, and pagination:

- **SearchCriteriaBuilder** — fluent builder for criteria
- **FilterBuilder** — builds individual filter conditions
- **FilterGroupBuilder** — groups filters with AND/OR logic
- **SortOrderBuilder** — defines sort order
- **CollectionProcessorInterface** — applies criteria to collections

### Filter Logic

- Filters within a **FilterGroup** are OR'd together
- **FilterGroups** are AND'd together
- Condition types: `eq`, `neq`, `gt`, `gteq`, `lt`, `lteq`, `like`, `in`, `nin`, `notnull`, `null`, `from`, `to`

### Repository Implementation Pattern

The concrete repository class:
1. Injects: Model Factory, Resource Model, Collection Factory, SearchResultsFactory, CollectionProcessor
2. `getById()` — creates model via factory, loads via resource model
3. `save()` — calls resource model `save()`, handles exceptions
4. `delete()` — calls resource model `delete()`
5. `getList()` — creates collection, applies criteria via CollectionProcessor, wraps in SearchResults

### Service Contracts as Web API

When you define a service contract interface and map it in `webapi.xml`, the same code serves:
- REST API endpoints
- SOAP API endpoints
- Internal PHP calls

### Best Practices

- Always define data interfaces — don't expose models directly
- Use typed return types and parameter types on all interface methods
- Add `@api` annotation to indicate public API stability
- Use `SearchCriteriaBuilder` instead of raw collection filtering in service layer
- Throw specific exceptions: `NoSuchEntityException`, `CouldNotSaveException`, `CouldNotDeleteException`
- Map service contracts in `webapi.xml` for automatic REST/SOAP exposure

Fetch the service contracts and searching-with-repositories docs for exact interface signatures, exception classes, and CollectionProcessor usage before implementing.

Related Skills

mpp-service-discovery

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement MPP service discovery — OpenAPI documents with x-payment-info extensions, x-service-info metadata, and llms.txt for autonomous agent discovery. Use when publishing paid API metadata for AI agents to find and pay for your services.

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-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-plugins-interceptors

17
from 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.

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.