{"id":7695,"date":"2016-01-15T11:21:25","date_gmt":"2016-01-15T08:21:25","guid":{"rendered":"http:\/\/blog.belvg.com\/?p=7695"},"modified":"2019-09-26T16:37:20","modified_gmt":"2019-09-26T14:37:20","slug":"declaring-observers-in-magento-2-0","status":"publish","type":"post","link":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html","title":{"rendered":"Declaring Observers in Magento 2.0 (Updated)"},"content":{"rendered":"\n<p>Registration and creation of observers in Magento 2.x is a bit different from the version 1.x.<!--more--><\/p>\n<ul>\n<li>a separate events.xml file is used for registering observers;<\/li>\n<li>the scope of the observer is defined not by the xml node, but by the location of the events.xml file;<\/li>\n<li>XML syntax is slightly different from the version 1.x.<\/li>\n<\/ul>\n<p align=\"left\">Let&rsquo;s take a closer look at these differences using our module Age Verification Page as an example.<\/p>\n<p align=\"left\">Unlike in Magento 1.x where all events are registered in the common config module, in Magento 2.x all module observers are stored in a separate xml file under the following path:<\/p>\n<p align=\"left\">app\/code\/BelVG\/Verpage\/etc\/events.xml(app\/code\/BelVG\/Verpage\/etc\/adminhtml\/events.xml<\/p>\n<p align=\"left\">or<\/p>\n<p align=\"left\">app\/code\/BelVG\/Verpage\/etc\/frontpage\/events.xml<\/p>\n<p>Let&rsquo;s take a look at the xml file:<\/p>\n<pre class=\"lang:php decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n...\r\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"..\/..\/..\/..\/..\/..\/lib\/internal\/Magento\/Framework\/Event\/etc\/events.xsd\"&gt;\r\n    &lt;event name=\"controller_front_send_response_before\"&gt;\r\n        &lt;observer name=\"belvg_verpage_controller_front_send_response_before\" instance=\"BelVG\\Verpage\\Model\\Observer\" method=\"verificate\" \/&gt;\r\n    &lt;\/event&gt;\r\n&lt;\/config&gt;<\/pre>\n<p>The attribute &lsquo;name&rsquo; in the &lsquo;event&rsquo; node defines the event when the observer should be called.<\/p>\n<div class=\"module_in_content_container\"><a href=\"https:\/\/belvg.com\/magento2-development\" class=\"link_to_module\" target=\"_blank\" rel=\"noopener\"><\/a><div class=\"module_content\"><img src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/08\/magento-development-services.png\" width=\"481\" height=\"480\" alt=\"magento development services\" class=\"module_image\" title=\"Declaring Observers in Magento 2.0 (Updated)\"><div class=\"module_content_part\"><h3 class=\"title\">Magento 2 Development<\/h3><p class=\"module_content_text\">Take your online store to the next level with BelVG Magento 2 Development<\/p><a href=\"https:\/\/belvg.com\/magento2-development\" class=\"link_2_to_module\" target=\"_blank\" style=\"display:inline-block\" rel=\"noopener\"><span class=\"read-more\">Visit the page<\/span><\/a><\/div><\/div><\/div>\n<p>The &ldquo;observer&rdquo; node defines the observer itself and its attributes:<\/p>\n<ul>\n<li>name &ndash; the observer registration name (it is important that the names do not coincide);<\/li>\n<li>instance &ndash; the class, which method will be executed when a specific even occurs;<\/li>\n<li>method &ndash; the method being executed.<\/li>\n<\/ul>\n<p>Let&rsquo;s take a look at the observer (app\/code\/BelVG\/Verpage\/Model\/Observer.php):<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\n...\r\nnamespace BelVG\\Verpage\\Model;\r\nclass Observer\r\n{\r\n    protected $_verpageData;\r\n    protected $_registry = null;\r\n\r\n    public function __construct (\r\n        \\BelVG\\Verpage\\Helper\\Data $verpageData,\r\n        \\Magento\\Framework\\Registry $registry\r\n    ) {\r\n        $this-&gt;_verpageData = $verpageData;\r\n        $this-&gt;_registry = $registry;\r\n    }\r\n\r\n    public function verificate(\\Magento\\Framework\\Event\\Observer $observer)\r\n    {  \r\n        ...\r\n    }\r\n\r\n    ...\r\n}<\/pre>\n<p>As you see, there have been very few changes compared to Magento 1.x except for the class names. In our case the function &lsquo;verificate&rsquo; receives the current observer object as an argument.<\/p>\n<p>In the beginning we also mentioned one more important difference &ndash; the definition of the scope of the observer. Unlike in Magento 1.x:<\/p>\n<p>The file config.xml:<\/p>\n<pre class=\"lang:php decode:true \">&lt;frontend&gt;\r\n    &lt;events&gt;\r\n        &lt;belvg_jquery_dispatch_before&gt;\r\n            &lt;observers&gt;\r\n                &lt;belvg_verpage_jquery_dispatch_before&gt;\r\n                    &lt;type&gt;singleton&lt;\/type&gt;\r\n                    &lt;class&gt;verpage\/observer&lt;\/class&gt;\r\n                    &lt;method&gt;verificate&lt;\/method&gt;\r\n                &lt;\/belvg_verpage_jquery_dispatch_before&gt;\r\n            &lt;\/observers&gt;\r\n        &lt;\/belvg_jquery_dispatch_before&gt;\r\n    &lt;\/events&gt;\r\n&lt;\/frontend&gt;<\/pre>\n<p>In such case Magento 1.x defines the observer only on the frontend.<\/p>\n<p>In Magento 2.x the scope of the observer is defined by the location of the events.xml file in the specific folder.<\/p>\n<p>Frontend location: app\/code\/Namespace\/Modulename\/etc\/frontend\/<br>\nAdmin location: app\/code\/Namespace\/Modulename\/etc\/adminhtml\/<\/p>\n<p>If the observer is required both on the frontend and in the admin panel: app\/code\/Namespace\/Modulename\/etc\/<\/p>\n<div class=\"module_in_content_container\"><a href=\"https:\/\/belvg.com\/magento-webdesign\" class=\"link_to_module\" target=\"_blank\" rel=\"noopener\"><\/a><div class=\"module_content\"><img src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2019\/01\/magento-webdesign-1.png\" width=\"100\" height=\"100\" alt=\"magento webdesign\" class=\"module_image\" title=\"Declaring Observers in Magento 2.0 (Updated)\"><div class=\"module_content_part\"><h3 class=\"title\">Magento Webdesign<\/h3><p class=\"module_content_text\">Take your online store to the next level with BelVG Magento Webdesign<\/p><a href=\"https:\/\/belvg.com\/magento-webdesign\" class=\"link_2_to_module\" target=\"_blank\" style=\"display:inline-block\" rel=\"noopener\"><span class=\"read-more\">Visit the page<\/span><\/a><\/div><\/div><\/div>\n<p><strong>Update<\/strong><\/p>\n<p>In the final version of Magento Community Edition (CE), several changes have been included:<\/p>\n<p>app\/code\/BelVG\/Infscroll\/etc\/frontpage\/events.xml (for example, Infinite Scroll extension)<\/p>\n<pre class=\"lang:php decode:true\">&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Event\/etc\/events.xsd\"&gt;\r\n    &lt;event name=\"layout_render_before\"&gt;\r\n        &lt;observer name=\"belvg_infscroll_layout_render_before\" instance=\"BelVG\\Infscroll\\Observer\\AjaxRenderBefore\" \/&gt;\r\n    &lt;\/event&gt;  \r\n&lt;\/config&gt;\r\n<\/pre>\n<p>The &ldquo;method&rdquo; parameter has been deleted and now observers represent something like a controller (that has an additional &ldquo;execute&rdquo; function).<br>\nAccordingly, the following changes in the observer have been made:<\/p>\n<ol>\n<li>All observers have been moved to the root catalog of the extension<\/li>\n<li>The observers are now made similarly to controllers.<\/li>\n<\/ol>\n<div class=\"content_sales_info\" style=\"background-image: url(https:\/\/belvg.com\/blog\/wp-content\/uploads\/2019\/03\/Sales_background.png\"><img width=\"65\" height=\"65\" src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2019\/03\/Igor-Dragun1.png\" alt=\"Igor Dragun\" title=\"Declaring Observers in Magento 2.0 (Updated)\"><div class=\"content_part\"><h3 class=\"title\">Partner With Us <\/h3><span class=\"sales_content_text\">Let's discuss how to grow your business. Get a Free Quote.<\/span><\/div> <a class=\"call-to-action\" href=\"https:\/\/belvg.com\/contact?utm_source=blog&amp;utm_campaign=sales_block&amp;utm_content=middle\" target=\"_blank\" rel=\"noopener\">Talk to Igor<\/a><\/div>\n<p>Example: app\/code\/BelVG\/Infscroll\/Observer\/AjaxRenderBefore.php<\/p>\n<p>namespace BelVG\\Infscroll\\Observer;<\/p>\n<p>use Magento\\Framework\\Event\\ObserverInterface;<br>\nuse Magento\\Framework\\DataObject as Object;<\/p>\n<pre class=\"lang:php decode:true \">class AjaxRenderBefore implements ObserverInterface\r\n{\r\n    const AJAX_PARAM_NAME = 'infscroll';\r\n    const AJAX_HANDLE_NAME = 'infscroll_ajax_request';\r\n    \r\n    \/**\r\n     * Https request\r\n     *\r\n     * @var \\Zend\\Http\\Request\r\n     *\/\r\n    protected $_request;\r\n    protected $_layout;\r\n    protected $_cache;\r\n    \r\n    \/**\r\n     * @param Item $item\r\n     *\/\r\n    public function __construct(\r\n        \\Magento\\Framework\\View\\Element\\Context $context,\r\n        \\BelVG\\Infscroll\\Helper\\Cache $cache\r\n    ) {\r\n        $this-&gt;_layout = $context-&gt;getLayout();\r\n        $this-&gt;_request = $context-&gt;getRequest();\r\n        $this-&gt;_cache = $cache;\r\n    }\r\n\r\n    \/**\r\n     * @param \\Magento\\Framework\\Event\\Observer $observer\r\n     * @return $this\r\n     *\/\r\n    public function execute(\\Magento\\Framework\\Event\\Observer $observer)\r\n    {\r\n\r\n       \/* function body *\/\r\n\r\n    }\r\n    \r\n}<\/pre>\n\n","protected":false},"excerpt":{"rendered":"Registration and creation of observers in Magento 2.x is a bit different from the version &#8230;","protected":false},"author":30,"featured_media":10040,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[389],"tags":[3,382,408],"class_list":["post-7695","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-magento2-development","tag-magento","tag-magento-2-0","tag-observers","post_format-post-format-image"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Registration and creation of observers in Magento 2.x is a bit different from the version 1.x.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Andrei Danilchyk\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#article\",\"name\":\"Declaring Observers in Magento 2.0 | BelVG Blog\",\"headline\":\"Declaring Observers in Magento 2.0 (Updated)\",\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/06\\\/blog-mage16-06.jpg\",\"width\":682,\"height\":170},\"datePublished\":\"2016-01-15T11:21:25+02:00\",\"dateModified\":\"2019-09-26T16:37:20+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":7,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#webpage\"},\"articleSection\":\"Magento 2 Development, magento, magento 2.0, Observers, Image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento2-development#listItem\",\"name\":\"Magento 2 Development\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento2-development#listItem\",\"position\":2,\"name\":\"Magento 2 Development\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento2-development\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#listItem\",\"name\":\"Declaring Observers in Magento 2.0 (Updated)\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#listItem\",\"position\":3,\"name\":\"Declaring Observers in Magento 2.0 (Updated)\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento2-development#listItem\",\"name\":\"Magento 2 Development\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk\",\"name\":\"Andrei Danilchyk\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/035c7a3d986ac8d09b60f02a1d47ab8822a92657f10160d588ea28f14db1efb7?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Andrei Danilchyk\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#webpage\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html\",\"name\":\"Declaring Observers in Magento 2.0 | BelVG Blog\",\"description\":\"Registration and creation of observers in Magento 2.x is a bit different from the version 1.x.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrei-danilchyk#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/06\\\/blog-mage16-06.jpg\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html\\\/#mainImage\",\"width\":682,\"height\":170},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/declaring-observers-in-magento-2-0.html#mainImage\"},\"datePublished\":\"2016-01-15T11:21:25+02:00\",\"dateModified\":\"2019-09-26T16:37:20+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Declaring Observers in Magento 2.0 | BelVG Blog","description":"Registration and creation of observers in Magento 2.x is a bit different from the version 1.x.","canonical_url":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#article","name":"Declaring Observers in Magento 2.0 | BelVG Blog","headline":"Declaring Observers in Magento 2.0 (Updated)","author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2015\/06\/blog-mage16-06.jpg","width":682,"height":170},"datePublished":"2016-01-15T11:21:25+02:00","dateModified":"2019-09-26T16:37:20+02:00","inLanguage":"en-US","commentCount":7,"mainEntityOfPage":{"@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#webpage"},"isPartOf":{"@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#webpage"},"articleSection":"Magento 2 Development, magento, magento 2.0, Observers, Image"},{"@type":"BreadcrumbList","@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/belvg.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento2-development#listItem","name":"Magento 2 Development"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento2-development#listItem","position":2,"name":"Magento 2 Development","item":"https:\/\/belvg.com\/blog\/category\/magento2-development","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#listItem","name":"Declaring Observers in Magento 2.0 (Updated)"},"previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#listItem","position":3,"name":"Declaring Observers in Magento 2.0 (Updated)","previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento2-development#listItem","name":"Magento 2 Development"}}]},{"@type":"Organization","@id":"https:\/\/belvg.com\/blog\/#organization","name":"BelVG Blog","description":"Magento and Prestashop articles","url":"https:\/\/belvg.com\/blog\/"},{"@type":"Person","@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author","url":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk","name":"Andrei Danilchyk","image":{"@type":"ImageObject","@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/035c7a3d986ac8d09b60f02a1d47ab8822a92657f10160d588ea28f14db1efb7?s=96&d=mm&r=g","width":96,"height":96,"caption":"Andrei Danilchyk"}},{"@type":"WebPage","@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#webpage","url":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html","name":"Declaring Observers in Magento 2.0 | BelVG Blog","description":"Registration and creation of observers in Magento 2.x is a bit different from the version 1.x.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/belvg.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#breadcrumblist"},"author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"creator":{"@id":"https:\/\/belvg.com\/blog\/author\/andrei-danilchyk#author"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2015\/06\/blog-mage16-06.jpg","@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html\/#mainImage","width":682,"height":170},"primaryImageOfPage":{"@id":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html#mainImage"},"datePublished":"2016-01-15T11:21:25+02:00","dateModified":"2019-09-26T16:37:20+02:00"},{"@type":"WebSite","@id":"https:\/\/belvg.com\/blog\/#website","url":"https:\/\/belvg.com\/blog\/","name":"BelVG Blog","description":"Magento and Prestashop articles","inLanguage":"en-US","publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"7695","title":"Declaring Observers in Magento 2.0 | #site_title","description":"Registration and creation of observers in Magento 2.x is a bit different from the version 1.x.","keywords":null,"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-11-03 18:37:54","updated":"2026-11-03 18:37:54"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/category\/magento2-development\" title=\"Magento 2 Development\">Magento 2 Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tDeclaring Observers in Magento 2.0 (Updated)\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/belvg.com\/blog\/"},{"label":"Magento 2 Development","link":"https:\/\/belvg.com\/blog\/category\/magento2-development"},{"label":"Declaring Observers in Magento 2.0 (Updated)","link":"https:\/\/belvg.com\/blog\/declaring-observers-in-magento-2-0.html"}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/7695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/comments?post=7695"}],"version-history":[{"count":-3,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/7695\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media\/10040"}],"wp:attachment":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media?parent=7695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/categories?post=7695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/tags?post=7695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}