Magento service contracts

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

Magento service contracts is an AI agent skill from the GitHub repository 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.

How to use this skill

Skill file

Magento 2 Service Contracts & Repositories

Before writing code

Fetch live docs:

  1. Fetch https://developer.adobe.com/commerce/webapi/rest/ for service contract guide
  2. Fetch https://developer.adobe.com/commerce/php/development/components/ 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)
  1. Data Interfaces (Api/Data/SomeInterface.php)
  1. SearchResults Interface (Api/Data/SomeSearchResultsInterface.php)

SearchCriteria Pattern

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

Filter Logic

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:

Best Practices

Fetch the service contracts and searching-with-repositories docs for exact interface signatures, exception classes, and CollectionProcessor usage 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.