{"id":12104,"date":"2022-12-21T07:39:10","date_gmt":"2022-12-21T07:39:10","guid":{"rendered":"https:\/\/www.bay20.com\/?p=12104"},"modified":"2025-05-14T18:36:59","modified_gmt":"2025-05-14T12:51:59","slug":"anleitung-zum-erstellen-eines-benutzerdefinierten-storefront-controllers-in-shopware-6","status":"publish","type":"post","link":"https:\/\/www.bay20.com\/de\/anleitung-zum-erstellen-eines-benutzerdefinierten-storefront-controllers-in-shopware-6\/","title":{"rendered":"Wie erstellt man einen benutzerdefinierten Schaufenster-Controller in Shopware 6?"},"content":{"rendered":"\n<p>In diesem Blogbeitrag erfahren Sie, wie Sie einen benutzerdefinierten Schaufenster-Controller in Shopware 6 erstellen k\u00f6nnen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Voraussetzungen<\/h2>\n\n\n\n<p>Zun\u00e4chst m\u00fcssen Sie Ihr eigenes benutzerdefiniertes Plugin als Grundlage erstellen. Dazu k\u00f6nnen Sie dieses Tutorial zur <a href=\"https:\/\/www.bay20.com\/de\/wie-erstelle-ich-ein-plugin-mit-befehl-in-shopware-6\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"plugin base\">Plugin-Basis<\/a> befolgen.<\/p>\n\n\n\n<p>Erstellen Sie in Ihrem Plugin-Verzeichnis custom\/plugins\/( <strong>YOUR_PLUGIN <\/strong>) die Datei routes.xml in folgendem Pfad: src\/Resources\/config\/routes.xml und f\u00fcgen Sie den folgenden Code hinzu.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?&gt;\n&lt;routes xmlns=\"http:\/\/symfony.com\/schema\/routing\"\n        xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:schemaLocation=\"http:\/\/symfony.com\/schema\/routing\n        https:\/\/symfony.com\/schema\/routing\/routing-1.0.xsd\"&gt;\n\n   &lt;import resource=\"..\/..\/Storefront\/Controller\/**\/*Controller.php\" type=\"annotation\" \/&gt;\n\n&lt;\/routes&gt;\n<\/code><\/pre>\n\n\n\n<p>Lassen Sie uns nun den Container in den Controller einbinden. Erstellen Sie die Datei services.xml in diesem Verzeichnis: src\/Resources\/config\/services.xml und f\u00fcgen Sie den folgenden Code hinzu.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" ?&gt;\n&lt;container xmlns=\"http:\/\/symfony.com\/schema\/dic\/services\"\n           xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n           xsi:schemaLocation=\"http:\/\/symfony.com\/schema\/dic\/services http:\/\/symfony.com\/schema\/dic\/services\/services-1.0.xsd\"&gt;\n\n    &lt;services&gt;\n\n        &lt;service id=\"SwagBasicExample\\Storefront\\Controller\\ExampleController\" public=\"true\"&gt;\n            &lt;call method=\"setContainer\"&gt;\n                &lt;argument type=\"service\" id=\"service_container\" \/&gt;\n            &lt;\/call&gt;\n        &lt;\/service&gt;\n\n    &lt;\/services&gt;\n\n&lt;\/container&gt;<\/code><\/pre>\n\n\n\n<p>Jetzt m\u00fcssen wir nur noch die Controller-Datei unter dem Pfad: src\/Storefront\/Controller\/ExampleController.php erstellen und den folgenden Code hinzuf\u00fcgen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php declare(strict_types=1);\n\nnamespace SwagBasicExample\\Storefront\\Controller;\n\nuse Shopware\\Core\\Framework\\Routing\\Annotation\\RouteScope;\nuse Shopware\\Core\\Framework\\Routing\\Annotation\\Since;\nuse Shopware\\Storefront\\Controller\\StorefrontController;\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Symfony\\Component\\Routing\\Annotation\\Route;\n\n\/**\n * @RouteScope(scopes={\"storefront\"})\n *\/\nclass ExampleController extends StorefrontController\n{\n    \/**\n     * @Route(\"\/hello-world\", name=\"frontend.helloworld\", methods={\"GET\"})\n     *\/\n    public function helloworld()\n    {\n        echo 'This is the first storefront controller which we just created!';\n        exit;\n}\n<\/code><\/pre>\n\n\n\n<p>Jetzt haben wir einen Controller, der in Shopware 6 funktioniert! Besuchen Sie Ihre Website: example.com\/hellow-world. Sie k\u00f6nnen die Ausgabe im folgenden Screenshot sehen.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"272\" src=\"https:\/\/www.bay20.com\/wp-content\/uploads\/2022\/12\/image-980x272.png\" alt=\"\" class=\"wp-image-12121\" srcset=\"https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2022\/12\/image-980x272.png 980w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2022\/12\/image-300x83.png 300w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2022\/12\/image-800x222.png 800w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2022\/12\/image-768x213.png 768w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2022\/12\/image-1000x278.png 1000w, https:\/\/www.bay20.com\/de\/wp-content\/uploads\/2022\/12\/image.png 1037w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/figure>\n\n\n\n<p><strong>Bitte kontaktieren Sie uns unter <strong><a href=\"mailto:manish@bay20.com\">manish@bay20.com<\/a><\/strong> oder rufen Sie uns unter <strong><a href=\"https:\/\/api.whatsapp.com\/send?phone=+918800519180&amp;text=Hi, I contacted you through your website.\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"+91-8800519180\">+91-8800519180<\/a><\/strong> an, wenn Sie Unterst\u00fctzung im Zusammenhang mit Shopware ben\u00f6tigen. Sie k\u00f6nnen auch die <strong><a href=\"https:\/\/www.bay20.com\/de\/shopware-entwicklungsunternehmen\/\" title=\"Shopware development\">Shopware<strong>-Entwicklungsseite<\/strong><\/a><\/strong> besuchen, um die von uns angebotenen Dienstleistungen zu pr\u00fcfen.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To create a custom storefront controller in Shopware 6, you must first create a controller file in the Controllers directory of your Shopware 6 project. This file should contain the logic and code that will be executed when the controller is called. <\/p>\n","protected":false},"author":30,"featured_media":12114,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78,115,91],"tags":[],"class_list":["post-12104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shopware","category-shopware-6","category-shopware-6-anleitungen"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/12104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/comments?post=12104"}],"version-history":[{"count":18,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/12104\/revisions"}],"predecessor-version":[{"id":17125,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/12104\/revisions\/17125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media\/12114"}],"wp:attachment":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media?parent=12104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/categories?post=12104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/tags?post=12104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}