Warning: You are browsing the documentation for PrestaShop 1.7, which is outdated.
You might want to read an updated version of this page for the current version, PrestaShop 8. Read the updated version of this page
As mentioned in CQRS principles, a Command
is a representation of a single domain use case. To prevent Command Handlers
from duplicating code and depending on each other, it is usually best to avoid implementing the actual logic in the Command Handler
itself, and delegate it to Domain Services
instead. These services are responsible for logic such as:
Here are some principles for implementing a Domain Service:
ObjectModel
for writes, as long as such class exists.Adapter
namespace.ObjectModel
exists, then this query MUST be delegated to the appropriate repository class which must ensure that no legacy exceptions are thrown. If the related ObjectModel
already implements such method, then the repository must delegate its implementation to the ObjectModel
.
ObjectModel
contains fields validation, it MUST be validated by a dedicated validator class before persisting to database (e.g. when using add
/update
/save
methods). It ensures that legacy PrestashopException is not bubbling up and each validation error can be identified by a dedicated exception or exception code.
ObjectModel
repositoriesObjectModel
validatorsCommandHandler
examples