Implement cqrs handlers

From PrestaShop/PrestaShop · View interactive version

Implement cqrs handlers is an AI agent skill from the GitHub repository PrestaShop/PrestaShop. Implement all command and query handlers in the Adapter layer. Each handler delegates to the repository for persistence — no direct SQL or ObjectModel access. Handlers use #[AsCommandHandler] / #[AsQueryHandler] attributes for auto-registration. Trigger: "implement handlers for {Domain}".

How to use this skill

Skill file

implement-cqrs-handlers

Handlers live in src/Adapter/{Domain}/CommandHandler/ and QueryHandler/. See CQRS/CONTEXT.md for conventions (#[AsCommandHandler]/#[AsQueryHandler] attributes, no cross-handler calls, return types).

1. Add handler

Add{Domain}Handler.php implementing Add{Domain}HandlerInterface:

Reference: src/Adapter/Tax/CommandHandler/AddTaxHandler.php (simple), src/Adapter/Manufacturer/CommandHandler/AddManufacturerHandler.php (with image)

2. Edit handler (partial-update)

Edit{Domain}Handler.php implementing Edit{Domain}HandlerInterface:

Reference: src/Adapter/Tax/CommandHandler/EditTaxHandler.php (simple), src/Adapter/Carrier/CommandHandler/EditCarrierHandler.php (many fields)

3. Delete handler

Delete{Domain}Handler.php implementing Delete{Domain}HandlerInterface:

4. Toggle status handler

Toggle{Domain}StatusHandler.php:

5. Sub-resource handler (if sub-resources exist)

Set{Domain}{SubResource}sHandler.php:

Two strategies depending on complexity:

Strategy A: Atomic replace (simpler, quicker)

Used when sub-resources have no identity of their own or when maintaining existing rows isn't important:

Reference: src/Adapter/Carrier/CommandHandler/SetCarrierRangesHandler.php

Strategy B: Incremental update (cleaner, preserves existing sub-resources)

Preferred when sub-resources have their own identity or when preserving existing rows matters (e.g., to keep audit trails, auto-increment IDs, or related data):

Choose Strategy B when possible for cleaner data management. Use Strategy A when sub-resources are simple value-like collections without individual identity.

6. Get-for-editing handler

Get{Domain}ForEditingHandler.php in QueryHandler/:

Reference: src/Adapter/Tax/QueryHandler/GetTaxForEditingHandler.php (simple)

7. List query handler (if explicit query exists)

Most domains use the grid QueryBuilder pattern — no handler needed. Only create if the domain

uses an explicit Get{Domain}sForListing query class.

Rules

Conventions (attributes, no SQL, no cross-handler calls, return types) are in CQRS/CONTEXT.md. Skill-specific reminders:

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.