Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contribute/contribution-guidelines/pull-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Remember, this is only needed for the Pull Request form, not for your commit mes
{{% notice note %}}
**Why is this important?**

We use type & category to group changes in the [changelog](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/docs/CHANGELOG.txt).
We use type & category to group changes in the [changelog](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/docs/CHANGELOG.txt).
{{% /notice %}}

### BC breaks
Expand Down
36 changes: 18 additions & 18 deletions development/architecture/domain/domain-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@ Here are some principles for implementing a Domain Service:
2. If it uses any legacy service or object model, then it MUST be placed in the `Adapter` namespace.
3. If it needs to perform a sql query and related `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`.
{{% notice %}}
Some reusable methods are present in [AbstractObjectModelRepository](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Core/Repository/AbstractObjectModelRepository.php).
Some reusable methods are present in [AbstractObjectModelRepository](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Core/Repository/AbstractObjectModelRepository.php).
{{% /notice %}}
4. If `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](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/classes/exception/PrestaShopException.php) is not bubbling up and each validation error can be identified by a dedicated exception or exception code.
4. If `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](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/classes/exception/PrestaShopException.php) is not bubbling up and each validation error can be identified by a dedicated exception or exception code.
{{% notice %}}
Some reusable methods are present in [AbstractObjectModelValidator](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/AbstractObjectModelValidator.php).
Some reusable methods are present in [AbstractObjectModelValidator](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/AbstractObjectModelValidator.php).
{{% /notice %}}

# Code examples

## `ObjectModel` repositories

1. [ProductRepository](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/Product/Repository/ProductRepository.php)
2. [ProductSupplierRepository](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/Product/Repository/ProductSupplierRepository.php)
3. [VirtualProductFileRepository](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/Product/VirtualProduct/Repository/VirtualProductFileRepository.php)
4. [SpecificPriceRepository](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/Product/SpecificPrice/Repository/SpecificPriceRepository.php)
1. [ProductRepository](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/Repository/ProductRepository.php)
2. [ProductSupplierRepository](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/Repository/ProductSupplierRepository.php)
3. [VirtualProductFileRepository](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/VirtualProduct/Repository/VirtualProductFileRepository.php)
4. [SpecificPriceRepository](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/SpecificPrice/Repository/SpecificPriceRepository.php)

## `ObjectModel` validators

1. [ProductValidator](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/Product/Validate/ProductValidator.php)
2. [ProductSupplierValidator](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/Product/Validate/ProductSupplierValidator.php)
2. [VirtualProductFileValidator](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/Product/VirtualProduct/Validate/VirtualProductFileValidator.php)
3. [SpecificPriceValidator](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Adapter/Product/SpecificPrice/Validate/SpecificPriceValidator.php)
1. [ProductValidator](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/Validate/ProductValidator.php)
2. [ProductSupplierValidator](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/Validate/ProductSupplierValidator.php)
3. [VirtualProductFileValidator](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/VirtualProduct/Validate/VirtualProductFileValidator.php)
4. [SpecificPriceValidator](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/SpecificPrice/Validate/SpecificPriceValidator.php)

## Product domain services

1. [Product update services](https://github.com/PrestaShop/PrestaShop/tree/9.0.x/src/Adapter/Product/Update)
2. [Virtual product update services](https://github.com/PrestaShop/PrestaShop/tree/9.0.x/src/Adapter/Product/VirtualProduct/Update)
2. [Combination update services](https://github.com/PrestaShop/PrestaShop/tree/9.0.x/src/Adapter/Product/Combination/Update)
2. [Combination create services](https://github.com/PrestaShop/PrestaShop/tree/9.0.x/src/Adapter/Product/Combination/Create)
1. [Product update services](https://github.com/PrestaShop/PrestaShop/tree/9.1.x/src/Adapter/Product/Update)
2. [Virtual product update services](https://github.com/PrestaShop/PrestaShop/tree/9.1.x/src/Adapter/Product/VirtualProduct/Update)
3. [Combination update services](https://github.com/PrestaShop/PrestaShop/tree/9.1.x/src/Adapter/Product/Combination/Update)
4. [Combination create services](https://github.com/PrestaShop/PrestaShop/tree/9.1.x/src/Adapter/Product/Combination/Create)

## Service usage in `CommandHandler` examples

1. [Combination command handlers](https://github.com/PrestaShop/PrestaShop/tree/9.0.x/src/Adapter/Product/Combination/CommandHandler)
2. [Virtual product command handlers](https://github.com/PrestaShop/PrestaShop/tree/9.0.x/src/Adapter/Product/VirtualProduct/CommandHandler)
2. [Product stock command handlers](https://github.com/PrestaShop/PrestaShop/tree/9.0.x/src/Adapter/Product/Stock/CommandHandler)
1. [Combination command handlers](https://github.com/PrestaShop/PrestaShop/tree/9.1.x/src/Adapter/Product/Combination/CommandHandler)
2. [Virtual product command handlers](https://github.com/PrestaShop/PrestaShop/tree/9.1.x/src/Adapter/Product/VirtualProduct/CommandHandler)
3. [Product stock command handlers](https://github.com/PrestaShop/PrestaShop/tree/9.1.x/src/Adapter/Product/Stock/CommandHandler)
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ Controllers are responsible for performing "Actions". Actions are methods of Con
5. **Try to avoid creating helper methods in your controller.** If you find yourself needing them, that might mean the Controller is becoming too complex. This can be solved by extracting the code into dedicated services.

{{% notice %}}
You can take a look at [PerformanceController](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/PrestaShopBundle/Controller/Admin/Configure/AdvancedParameters/PerformanceController.php) for an example of good implementation, and [ProductController](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/PrestaShopBundle/Controller/Admin/ProductController.php) for something you should avoid at all costs.
You can take a look at [PerformanceController](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/PrestaShopBundle/Controller/Admin/Configure/AdvancedParameters/PerformanceController.php) for an example of good implementation, and [ProductController](https://github.com/PrestaShop/PrestaShop/blob/8.2.x/src/PrestaShopBundle/Controller/Admin/ProductController.php) for something you should avoid at all costs.
{{% /notice %}}
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ and

The core actually uses CQRS to handle data persistence, which raises a `DomainException` in case of a constraint error (for example, if the identifiable object you are trying to edit doesn't exist). This is handled in the controller by wrapping the code in a try-catch block, then flashing an error message accordingly.

For more details, check out the [ContactsController source code on GitHub](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/PrestaShopBundle/Controller/Admin/Configure/ShopParameters/ContactsController.php).
For more details, check out the [ContactsController source code on GitHub](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/PrestaShopBundle/Controller/Admin/Configure/ShopParameters/ContactsController.php).
{{% /notice %}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Let's look at the arguments one by one:

## Form request handling in Controllers

In modern pages, Controllers have or should have only one responsibility: handle the User request and return a response. This is why in modern pages, controllers should be as thin as possible and rely on specific classes (services) to manage the data. As always, check out the existing implementations, like in the [PerformanceController](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/PrestaShopBundle/Controller/Admin/Configure/AdvancedParameters/PerformanceController.php).
In modern pages, Controllers have or should have only one responsibility: handle the User request and return a response. This is why in modern pages, controllers should be as thin as possible and rely on specific classes (services) to manage the data. As always, check out the existing implementations, like in the [PerformanceController](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/PrestaShopBundle/Controller/Admin/Configure/AdvancedParameters/PerformanceController.php).

This is how we manage a form submit inside a Controller:

Expand Down Expand Up @@ -163,7 +163,7 @@ stateDiagram-v2

## Render the form using Twig

The rendering of forms in Twig is already described by the [Symfony documentation](https://symfony.com/doc/4.4/form/rendering.html). PrestaShop uses its own [Form theme](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/PrestaShopBundle/Resources/views/Admin/TwigTemplateForm/prestashop_ui_kit.html.twig) that contains specific markup for the PrestaShop UI Kit. You can see it as a customized version of Symfony's Bootstrap 4 form theme, even though it's not directly based on it.
The rendering of forms in Twig is already described by the [Symfony documentation](https://symfony.com/doc/4.4/form/rendering.html). PrestaShop uses its own [Form theme](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/PrestaShopBundle/Resources/views/Admin/TwigTemplateForm/prestashop_ui_kit.html.twig) that contains specific markup for the PrestaShop UI Kit. You can see it as a customized version of Symfony's Bootstrap 4 form theme, even though it's not directly based on it.

To sum up how it works, the controller sends an instance of `FormView` to Twig and Twig uses form helpers to render the right markup for every field type (the Form theme defines a specific markup for each Form Type).

Expand Down
4 changes: 2 additions & 2 deletions development/architecture/migration-guide/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Getting the list of available Hooks in modern pages is really easy. Thanks to th

Use this trick to find out which hooks are called on a legacy page.

In ``classes/Hook``, find the [exec() function](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/classes/Hook.php#L906) and add the following code:
In ``classes/Hook``, find the [exec() function](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/classes/Hook.php#L872) and add the following code:

```php
<?php
Expand Down Expand Up @@ -46,7 +46,7 @@ $this->dispatchHook('actionAdminPerformanceControllerPostProcessBefore', array('

## Dispatching hooks using the Hook dispatcher

If you need to dispatch a hook from a non-controller class, you'll need to inject the [HookDispatcher](https://github.com/PrestaShop/PrestaShop/blob/9.0.x/src/Core/Hook/HookDispatcher.php) class.
If you need to dispatch a hook from a non-controller class, you'll need to inject the [HookDispatcher](https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Core/Hook/HookDispatcher.php) class.

If your class is defined as a Symfony service, the HookDispatcher is available as a service called `prestashop.core.hook.dispatcher`.

Expand Down
Loading
Loading