{"id":627,"date":"2026-06-17T06:59:07","date_gmt":"2026-06-17T06:59:07","guid":{"rendered":"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/"},"modified":"2026-07-26T14:45:58","modified_gmt":"2026-07-26T12:45:58","password":"","slug":"cum-creez-un-eveniment-in-magento-2","status":"publish","type":"docs","link":"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/","title":{"rendered":"Cum creez \u0219i declan\u0219ez un eveniment personalizat \u00een Magento 2?"},"content":{"rendered":"<p>Evenimentele permit modulelor s\u0103 reac\u021bioneze la ac\u021biuni f\u0103r\u0103 a modifica codul de baz\u0103. \u00cen Magento 2, declan\u0219ezi un eveniment cu <code>dispatch()<\/code>, apoi \u00eel ascul\u021bi printr-un observer.<\/p>\n<blockquote>\n<p><strong>Bun\u0103 practic\u0103:<\/strong> nu folosi <code>ObjectManager::getInstance()<\/code> direct \u2014 este un anti-pattern. Injecteaz\u0103 <code>MagentoFrameworkEventManagerInterface<\/code> prin constructor (dependency injection).<\/p>\n<\/blockquote>\n<h3>1. Declan\u0219area evenimentului<\/h3>\n<pre><code>use Magento\\Framework\\Event\\ManagerInterface;\n\nclass MyService\n{\n    private $eventManager;\n\n    public function __construct(ManagerInterface $eventManager)\n    {\n        $this->eventManager = $eventManager;\n    }\n\n    public function doSomething()\n    {\n        $this->eventManager->dispatch('my_custom_event', ['cid' =&gt; 123]);\n    }\n}<\/code><\/pre>\n<p>Primul argument este numele evenimentului, al doilea este tabloul de date transmis observatorilor.<\/p>\n<h3>2. Ascultarea evenimentului (observer)<\/h3>\n<p>Declar\u0103 observer-ul \u00een <code>etc\/events.xml<\/code>:<\/p>\n<pre><code>&lt;event name=\"my_custom_event\"&gt;\n    &lt;observer name=\"my_observer\" instance=\"Vendor\\Module\\Observer\\MyObserver\"\/&gt;\n&lt;\/event&gt;<\/code><\/pre>\n<p>Apoi creeaz\u0103 clasa <code>Vendor\\Module\\Observer\\MyObserver<\/code> care implementeaz\u0103 <code>Magento\\Framework\\Event\\ObserverInterface<\/code> \u0219i metoda <code>execute(Observer $observer)<\/code>, unde cite\u0219ti datele cu <code>$observer->getData('cid')<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Evenimentele permit modulelor s\u0103 reac\u021bioneze la ac\u021biuni f\u0103r\u0103 a modifica codul de baz\u0103. \u00cen Magento 2, declan\u0219ezi un eveniment cu dispatch(), apoi \u00eel ascul\u021bi printr-un observer. Bun\u0103 practic\u0103: nu folosi ObjectManager::getInstance() direct \u2014 este un anti-pattern. Injecteaz\u0103 MagentoFrameworkEventManagerInterface prin constructor (dependency injection). 1. Declan\u0219area evenimentului use Magento\\Framework\\Event\\ManagerInterface; class MyService { private $eventManager; public function __construct(ManagerInterface &#8230; <a title=\"Cum creez \u0219i declan\u0219ez un eveniment personalizat \u00een Magento 2?\" class=\"read-more\" href=\"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/\" aria-label=\"Cite\u0219te mai multe despre Cum creez \u0219i declan\u0219ez un eveniment personalizat \u00een Magento 2?\">Cite\u0219te mai mult<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"whmcs_kb_id":1895,"footnotes":""},"doc_category":[160],"doc_tag":[225],"class_list":["post-627","docs","type-docs","status-publish","hentry","doc_category-magento-programare-aplicatii","doc_tag-magento-2"],"year_month":"2026-11","word_count":146,"total_views":"16","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"Adrian Firican","author_nicename":"techeditor1","author_url":"https:\/\/www.hostx.ro\/kb\/author\/techeditor1\/"},"doc_category_info":[{"term_name":"Magento","term_url":"https:\/\/www.hostx.ro\/kb\/docs-category\/magento-programare-aplicatii\/"}],"doc_tag_info":[{"term_name":"Magento 2","term_url":"https:\/\/www.hostx.ro\/kb\/docs-tag\/magento-2\/"}],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Cum creez eveniment personalizat \u00een Magento 2 - Centrul de suport HostX<\/title>\n<meta name=\"description\" content=\"\u00cenva\u021b\u0103 cum s\u0103 creezi \u0219i declan\u0219ezi evenimente personalizate \u00een Magento 2 folosind dependency injection \u0219i observers pentru a extinde func\u021bionalit\u0103\u021bi f\u0103r\u0103 a modifica codul de baz\u0103.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"ro_RO\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Cum creez eveniment personalizat \u00een Magento 2 - Centrul de suport HostX\" \/>\n<meta property=\"og:description\" content=\"\u00cenva\u021b\u0103 cum s\u0103 creezi \u0219i declan\u0219ezi evenimente personalizate \u00een Magento 2 folosind dependency injection \u0219i observers pentru a extinde func\u021bionalit\u0103\u021bi f\u0103r\u0103 a modifica codul de baz\u0103.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Centrul de suport HostX\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-26T12:45:58+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Timp estimat pentru citire\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minut\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-creez-un-eveniment-in-magento-2\\\/\",\"url\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-creez-un-eveniment-in-magento-2\\\/\",\"name\":\"Cum creez eveniment personalizat \u00een Magento 2 - Centrul de suport HostX\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/#website\"},\"datePublished\":\"2026-06-17T06:59:07+00:00\",\"dateModified\":\"2026-07-26T12:45:58+00:00\",\"description\":\"\u00cenva\u021b\u0103 cum s\u0103 creezi \u0219i declan\u0219ezi evenimente personalizate \u00een Magento 2 folosind dependency injection \u0219i observers pentru a extinde func\u021bionalit\u0103\u021bi f\u0103r\u0103 a modifica codul de baz\u0103.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-creez-un-eveniment-in-magento-2\\\/#breadcrumb\"},\"inLanguage\":\"ro-RO\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-creez-un-eveniment-in-magento-2\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-creez-un-eveniment-in-magento-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Prima pagin\u0103\",\"item\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"InfoCentru\",\"item\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/docs\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Cum creez \u0219i declan\u0219ez un eveniment personalizat \u00een Magento 2?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/\",\"name\":\"Centrul de suport HostX\",\"description\":\"tutoriale gazduire web, domenii web \u0219i servere\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ro-RO\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Cum creez eveniment personalizat \u00een Magento 2 - Centrul de suport HostX","description":"\u00cenva\u021b\u0103 cum s\u0103 creezi \u0219i declan\u0219ezi evenimente personalizate \u00een Magento 2 folosind dependency injection \u0219i observers pentru a extinde func\u021bionalit\u0103\u021bi f\u0103r\u0103 a modifica codul de baz\u0103.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/","og_locale":"ro_RO","og_type":"article","og_title":"Cum creez eveniment personalizat \u00een Magento 2 - Centrul de suport HostX","og_description":"\u00cenva\u021b\u0103 cum s\u0103 creezi \u0219i declan\u0219ezi evenimente personalizate \u00een Magento 2 folosind dependency injection \u0219i observers pentru a extinde func\u021bionalit\u0103\u021bi f\u0103r\u0103 a modifica codul de baz\u0103.","og_url":"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/","og_site_name":"Centrul de suport HostX","article_modified_time":"2026-07-26T12:45:58+00:00","twitter_card":"summary_large_image","twitter_misc":{"Timp estimat pentru citire":"1 minut"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/","url":"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/","name":"Cum creez eveniment personalizat \u00een Magento 2 - Centrul de suport HostX","isPartOf":{"@id":"https:\/\/www.hostx.ro\/kb\/#website"},"datePublished":"2026-06-17T06:59:07+00:00","dateModified":"2026-07-26T12:45:58+00:00","description":"\u00cenva\u021b\u0103 cum s\u0103 creezi \u0219i declan\u0219ezi evenimente personalizate \u00een Magento 2 folosind dependency injection \u0219i observers pentru a extinde func\u021bionalit\u0103\u021bi f\u0103r\u0103 a modifica codul de baz\u0103.","breadcrumb":{"@id":"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/#breadcrumb"},"inLanguage":"ro-RO","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hostx.ro\/kb\/cum-creez-un-eveniment-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Prima pagin\u0103","item":"https:\/\/www.hostx.ro\/kb\/"},{"@type":"ListItem","position":2,"name":"InfoCentru","item":"https:\/\/www.hostx.ro\/kb\/docs\/"},{"@type":"ListItem","position":3,"name":"Cum creez \u0219i declan\u0219ez un eveniment personalizat \u00een Magento 2?"}]},{"@type":"WebSite","@id":"https:\/\/www.hostx.ro\/kb\/#website","url":"https:\/\/www.hostx.ro\/kb\/","name":"Centrul de suport HostX","description":"tutoriale gazduire web, domenii web \u0219i servere","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hostx.ro\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ro-RO"}]}},"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/docs\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/comments?post=627"}],"version-history":[{"count":2,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/docs\/627\/revisions"}],"predecessor-version":[{"id":5893,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/docs\/627\/revisions\/5893"}],"wp:attachment":[{"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/media?parent=627"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/doc_category?post=627"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/doc_tag?post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}