You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1. Magento Architecture and Customization Techniques/6. Configure event observers and scheduled jobs.md
+82-18Lines changed: 82 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,86 @@
1
1
# Configure event observers and scheduled jobs
2
2
3
+
## Observers
4
+
5
+
Events are dispatched by modules when certain actions are triggered.
6
+
In addition to its own events, Magento allows you to create your own events that can be dispatched in your code.
7
+
When an event is dispatched, it can pass data to any observers configured to watch that event.
8
+
9
+
Best practices:
10
+
- Make your observer efficient
11
+
- Do not include business logic
12
+
- Declare observer in the appropriate scope
13
+
- Avoid cyclical event loops
14
+
- Do not rely on invocation order
15
+
16
+
>
17
+
> `14. Events`
18
+
>
19
+
> 14.1. All values (including objects) passed to an event MUST NOT be modified in the event observer. Instead, plugins SHOULD BE used for modifying the input or output of a function.
- before sortOrder=10, before sortOrder=20, before sortOrder=30 ...
9
-
- before and around (first half) called together for same plugin!
10
-
- around (second half) and after called together for same plugin!
67
+
Events dispatch by [Magento\Framework\Event\Manager](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Event/Manager.php) class
68
+
that implement [Magento\Framework\Event\ManagerInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Event/ManagerInterface.php) interface:
- pluginB.aroundMethod second half, pluginB.afterMethod
22
-
- pluginA.aroundMethod second half, pluginA.afterMethod
74
+
###### Links
75
+
-[Magento DevDocs - Events and observers](https://devdocs.magento.com/guides/v2.2/extension-dev-guide/events-and-observers.html)
76
+
-[Magento DevDocs - Observers Best Practices](https://devdocs.magento.com/guides/v2.2/ext-best-practices/extension-coding/observers-bp.html)
77
+
78
+
79
+
## Scheduled jobs
23
80
24
81
### Demonstrate how to configure a scheduled job
25
82
26
-
cron_groups.xml - store view scope:
83
+
`cron_groups.xml` - store view scope:
27
84
28
85
- default (no separate process)
29
86
- index - mview, targetrule
@@ -88,10 +145,14 @@ TODO: find out
88
145
what is setup:cron:run?
89
146
TODO: find out
90
147
148
+
###### Links
149
+
-[Magento DevDocs - Configure a custom cron job and cron group (tutorial)](https://devdocs.magento.com/guides/v2.2/config-guide/cron/custom-cron-tut.html)
150
+
-[Magento DevDocs - Custom cron job and cron group reference](https://devdocs.magento.com/guides/v2.2/config-guide/cron/custom-cron-ref.html)
151
+
91
152
92
153
### Identify the function and proper use of automatically available events
93
154
94
-
Model events \Magento\Framework\Model\AbstractModel:
155
+
Model events [\Magento\Framework\Model\AbstractModel](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Model/AbstractModel.php):
0 commit comments