Overview
Contracts are interfaces that define extension points throughout Unleash Commerce. They allow you to swap implementations, add custom logic, and extend functionality without modifying core code.What are Contracts?
Contracts are PHP interfaces located in thesrc/Contracts directory. They define the API for a particular feature, allowing you to create your own implementations.
Naming Convention
Always alias contracts with aContract suffix for clarity:
Binding Contracts
Once you’ve created an implementation, bind it in a service provider:Response Contracts
Controllers must return response contracts defined insrc/Contracts/Http/Responses. Each distinct response type has its own interface and implementation pair.
Benefits
- Flexibility: Swap implementations without changing code
- Testability: Mock contracts in your tests
- Extensibility: Add custom behavior by implementing contracts
- Maintainability: Clear contracts define expected behavior