{"id":253251,"date":"2022-11-22T08:33:32","date_gmt":"2022-11-22T08:33:32","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=253251"},"modified":"2022-11-22T08:33:39","modified_gmt":"2022-11-22T08:33:39","slug":"how-to-subscribed-event-in-shopware6","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/","title":{"rendered":"How to Subscribed Event in Shopware 6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>In this blog, we learn about the subscribed events in Shopware 6 at the storefront and pass custom data on this page. So let&#8217;s begin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>While creating a module, we need to subscribe event for Shopware 6  and how to pass data on this page. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Page Overriding<\/h2>\n\n\n\n<p>We take an example for the subscribed event, so we start to override the order page of the storefront. Suppose we want to override the order item list for adding custom order history for ordered items. <\/p>\n\n\n\n<p>First of all, we inspect the override area of HTML and copied any HTML content for searching in the core file. We reached the main content file and find the block of content which you want to override. <\/p>\n\n\n\n<p>You need to make some directories of the core files in your module under Resources\/views. Like order item list exist in the storefront\/page\/account\/order-history\/order-detail-list-item.html.twig. <\/p>\n\n\n\n<p>Then the same directory we should create in our module. After creating order-detail-list-item.html.twig file in the same directory as the main storefront file we need to extend the core storefront file. <\/p>\n\n\n\n<p>For overriding the core block, we need to copy and paste of needed block under the block. Call the parent method for existing content or core content as below.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">{% sw_extends &#039;@Storefront\/storefront\/page\/account\/order-history\/order-detail-list-item.html.twig&#039; %}\n\n{% block page_account_order_item_detail_variants %}\n    {{parent()}}\n    Here you can write your custom content\n{% endblock %}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Passing data<\/h2>\n\n\n\n<p>If you want to pass your own data to order page then you need to subscribed orderPageLoadedEvent. Create a subscriber file in subscribers folder name of folder and file choose anything. But you need to register this in service.xml file under Resources\/config folder.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;service id=&quot;Webkul\\MultiVendor\\EventSubscriber\\ShopwareSubscriber&quot;&gt;\n   &lt;tag name=&quot;kernel.event_subscriber&quot; \/&gt;\n   &lt;argument type=&quot;service&quot; id=&quot;service_container&quot; \/&gt;\n&lt;\/service&gt;<\/pre>\n\n\n\n<p>You can pass arguments in service file from between service tag. Once you register subscriber in service xml file now subscriber working in module. Let&#8217;s subscribed AccountOrderPageLoadedEvent::class within getSubscribedEvents() function. <\/p>\n\n\n\n<p>After subscribed event we create a new function on event orderPageLoadedEvent() function like the below.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">public static function getSubscribedEvents()\n    {\n        return &#091;\n            AccountOrderPageLoadedEvent::class =&gt; &#039;orderPageLoadedEvent&#039;\n        ];\n    }<\/pre>\n\n\n\n<p>After creating a function we perform action for storing data into variable and pass through event object with addExtension method.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\"> public function orderPageLoadedEvent(AccountOrderPageLoadedEvent $event)\n    {\n        $marketplaceOrderRepository = $this-&gt;container-&gt;get(&#039;marketplace_order.repository&#039;);\n       $marketplaceOrderLineItem = $marketplaceOrderRepository-&gt;search((new Criteria()), Context::createDefaultContext())-&gt;getElements();\n        \n       $shopwareOrder = $event-&gt;getPage()-&gt;getOrders()-&gt;getElements();\n        foreach($shopwareOrder as $order) {\n            foreach($order-&gt;getLineItems() as $lineItem) {\n                foreach($marketplaceOrderLineItem as $mpOrder) {\n                    \n                    if ($lineItem-&gt;getId() === $mpOrder-&gt;get(&#039;orderLineItemId&#039;)) {\n                        $lineItem-&gt;addExtension(&#039;itemStatus&#039;, new IdStruct($mpOrder-&gt;get(&#039;state_machine_state&#039;)-&gt;getName()) );\n                    }\n                }\n               \n            }\n        }\n        \n    }<\/pre>\n\n\n\n<p>I hope it will help you. Thanks for reading. Happy Coding \ud83d\ude42<\/p>\n\n\n\n<p>Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this blog, we learn about the subscribed events in Shopware 6 at the storefront and pass custom data on this page. So let&#8217;s begin. Overview While creating a module, we need to subscribe event for Shopware 6 and how to pass data on this page. Page Overriding We take an example for the <a href=\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":325,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-253251","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Subscribe Event in Shopware 6 | Subscribed Events<\/title>\n<meta name=\"description\" content=\"In this dev docs, you learn how to create subscribed events in Shopware 6 at the storefront and pass custom data on this page.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Subscribe Event in Shopware 6 | Subscribed Events\" \/>\n<meta property=\"og:description\" content=\"In this dev docs, you learn how to create subscribed events in Shopware 6 at the storefront and pass custom data on this page.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-22T08:33:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-22T08:33:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prince Gupta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prince Gupta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/\"},\"author\":{\"name\":\"Prince Gupta\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd\"},\"headline\":\"How to Subscribed Event in Shopware 6\",\"datePublished\":\"2022-11-22T08:33:32+00:00\",\"dateModified\":\"2022-11-22T08:33:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/\"},\"wordCount\":345,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/\",\"name\":\"How to Subscribe Event in Shopware 6 | Subscribed Events\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2022-11-22T08:33:32+00:00\",\"dateModified\":\"2022-11-22T08:33:39+00:00\",\"description\":\"In this dev docs, you learn how to create subscribed events in Shopware 6 at the storefront and pass custom data on this page.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Subscribed Event in Shopware 6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd\",\"name\":\"Prince Gupta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Prince Gupta\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/princegupta-wp031\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Subscribe Event in Shopware 6 | Subscribed Events","description":"In this dev docs, you learn how to create subscribed events in Shopware 6 at the storefront and pass custom data on this page.","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:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/","og_locale":"en_US","og_type":"article","og_title":"How to Subscribe Event in Shopware 6 | Subscribed Events","og_description":"In this dev docs, you learn how to create subscribed events in Shopware 6 at the storefront and pass custom data on this page.","og_url":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2022-11-22T08:33:32+00:00","article_modified_time":"2022-11-22T08:33:39+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Prince Gupta","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Prince Gupta","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/"},"author":{"name":"Prince Gupta","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd"},"headline":"How to Subscribed Event in Shopware 6","datePublished":"2022-11-22T08:33:32+00:00","dateModified":"2022-11-22T08:33:39+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/"},"wordCount":345,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/","url":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/","name":"How to Subscribe Event in Shopware 6 | Subscribed Events","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2022-11-22T08:33:32+00:00","dateModified":"2022-11-22T08:33:39+00:00","description":"In this dev docs, you learn how to create subscribed events in Shopware 6 at the storefront and pass custom data on this page.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-subscribed-event-in-shopware6\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Subscribed Event in Shopware 6"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd","name":"Prince Gupta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Prince Gupta"},"url":"https:\/\/webkul.com\/blog\/author\/princegupta-wp031\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/253251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/325"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=253251"}],"version-history":[{"count":5,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/253251\/revisions"}],"predecessor-version":[{"id":358166,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/253251\/revisions\/358166"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=253251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=253251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=253251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}