Skip to content

Commit

Permalink
[create-pull-request] automated change (#1217)
Browse files Browse the repository at this point in the history
Co-authored-by: shopwareBot <[email protected]>
  • Loading branch information
github-actions[bot] and shopwareBot authored Dec 5, 2023
1 parent 6af55a0 commit 5fffa4c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions resources/guidelines/code/core/extendability.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ We often use this pattern to realize **functional extensibility** and **function
The best-known example is the [`checkout.order.placed`](https://github.com/shopware/shopware/blob/v6.4.12.0/src/Core/Checkout/Cart/Event/CheckoutOrderPlacedEvent.php) event. This event is [dispatched](https://github.com/shopware/shopware/blob/v6.4.12.0/src/Core/Checkout/Cart/SalesChannel/CartOrderRoute.php#L151) as soon as an order is created in the system. However, over time, it has been shown that it is best practice not to pass objects or entities around in events, but only a corresponding primary key so that the connected listeners can determine the data for themselves. Furthermore, possible asynchronous processing of the underlying processes is easier to realize this way. An optimized variant of this event would not contain the `private OrderEntity $order;` but only the primary key for the order `private string $orderId;`.

#### Hooks

Hooks are another good example of the observer pattern. Hooks are entry points for apps in which the so-called [**App scripts**](../../../../guides/plugins/apps/app-scripts/index.md) is enabled. Since apps do not have the permission to execute code on the server directly, hooks are a way to execute more complex business logic within the request without having to address the own app server via HTTP. Hooks are the equivalent of **events**.
Hooks are another good example of the observer pattern. Hooks are entry points for apps in which the so-called [**App scripts**](/docs/guides/plugins/apps/app-scripts/) is enabled. Since apps do not have the permission to execute code on the server directly, hooks are a way to execute more complex business logic within the request without having to address the own app server via HTTP. Hooks are the equivalent of **events**.

One of the best-known hooks is the [`product page loaded hook`](https://github.com/shopware/shopware/blob/v6.4.12.0/src/Storefront/Page/Product/ProductPageLoadedHook.php). This hook allows apps to load additional data on the product detail page. The hook is instantiated and dispatched [at controller level](https://github.com/shopware/shopware/blob/v6.4.12.0/src/Storefront/Controller/ProductController.php#L100). Each app script, which is registered to the hook, is executed.

Expand Down

0 comments on commit 5fffa4c

Please sign in to comment.