Notice: You are browsing the documentation for PrestaShop 9, which is currently in development.
You might want to look at the current version, PrestaShop 8. Read the current version of the documentation
Since the beginning of the Symfony migration, we chose CQRS as our base architecture, and their usage for the future API was already anticipated because:
The implementation of the Admin API is based on the API Platform framework, this technical choice was made because of these advantages:
The configuration and definition of the core endpoints are centralized inside API Resource classes that are used as DTOs and configuration thanks to PHP attributes. You can read the API Resources page for more details about these classes.
To integrate our CQRS commands and queries into the API Platform framework, we used the Provider/Processor abstractions (Provider for read operations and Processor for write operations).
We developed three components:
PrestaShopBundle\ApiPlatform\Provider\QueryProvider
: responsible for read (GET) operation accessing a single resource, it executes CQRS queriesPrestaShopBundle\ApiPlatform\Provider\QueryListProvider
: responsible for read (GET) operation accessing a list of resources, it executes Grid data factories used in the BO listing pagesPrestaShopBundle\ApiPlatform\Processor\CommandProcessor
: responsible for write operations (POST, PUT, PATCH, DELETE) on resources, it executes CQRS commandsAll these components have similar behavior. They receive an API Platform resource as input (a DTO with configuration, filled with the input data from the request). They use a DomainSerializer
service to normalize the DTOs into CQRS commands/queries and dispatch them to the command bus.
The result object is then normalized back into the API Platform resource object and returned so the framework follows its execution (mostly serializing the response).
In the following diagrams, you can see the workflow of each component, separated into three different layers:
The second part is optional, depending on the endpoint expected return (empty response, or the update response content), it follows the same workflow as the QueryProvider.