{"id":7827,"date":"2021-05-02T11:29:04","date_gmt":"2021-05-02T11:29:04","guid":{"rendered":"https:\/\/www.bay20.com\/?p=7827"},"modified":"2025-05-21T16:34:55","modified_gmt":"2025-05-21T10:49:55","slug":"einrichtungs-skripte-in-magento-2","status":"publish","type":"post","link":"https:\/\/www.bay20.com\/de\/einrichtungs-skripte-in-magento-2\/","title":{"rendered":"Skripte in Magento 2 einrichten"},"content":{"rendered":"\n<p>Erstellen Sie ein neues Modul mit <strong>CustomScripts_SetupScripts<\/strong><\/p>\n\n\n\n<p><strong>Schritt 1:<\/strong> Erstellen Sie die Datei <strong>module.xml.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomScripts\/SetupScripts\/etc\/module.xml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\"&gt;\n    &lt;module name=\"CustomScripts_SetupScripts\" setup_version=\"1.0.0\" \/&gt;\n&lt;\/config&gt;<\/code><\/pre>\n\n\n\n<p><strong>Schritt 2:<\/strong> Erstellen Sie die Datei <strong>registration.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomScripts\/SetupScripts\/registration.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n\t\\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n\t'CustomScripts_SetupScripts',\n\t__DIR__\n);<\/code><\/pre>\n\n\n\n<p><strong>Schritt 3:<\/strong> Erstellen Sie die Datei <strong>InstallSchema.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomScripts\/SetupScripts\/Setup\/InstallSchema.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace CustomScripts\\SetupScripts\\Setup;\n\nuse Magento\\Framework\\Setup\\InstallSchemaInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\SchemaSetupInterface;\n\nclass InstallSchema implements InstallSchemaInterface\n{\n\n    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $installer = $setup;\n\n        $installer-&gt;startSetup();\n\n        $table = $installer-&gt;getConnection()\n            -&gt;newTable($installer-&gt;getTable('inviqa_example'))\n            -&gt;addColumn(\n                'entity_id',\n                \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_INTEGER,\n                null,\n                &#91;'identity' =&gt; true, 'unsigned' =&gt; true, 'nullable' =&gt; \nfalse, 'primary' =&gt; true],\n                'Entity ID'\n            )\n            -&gt;addColumn(\n                'name',\n                \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_TEXT,\n                255,\n                &#91;'nullable' =&gt; false],\n                'Name'\n            )\n            -&gt;setComment('Inviqa Example');\n        $installer-&gt;getConnection()-&gt;createTable($table);\n\n        $installer-&gt;endSetup();\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Schritt 4:<\/strong> Erstellen Sie die Datei <strong>InstallData.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomScripts\/SetupScripts\/InstallData.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace CustomScripts\\SetupScripts\\Setup;\n\nuse Magento\\Framework\\Setup\\InstallDataInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\ModuleDataSetupInterface;\n\nclass InstallData implements InstallDataInterface\n{\n    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $setup-&gt;getConnection()-&gt;query(\"INSERT INTO inviqa_example SET name = 'Test 1'\");\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Schritt 5:<\/strong> Erstellen Sie die Datei <strong>UpgradeSchema.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomScripts\/SetupScripts\/Setup\/UpgradeSchema.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace CustomScripts\\SetupScripts\\Setup;\n\nuse Magento\\Framework\\Setup\\UpgradeSchemaInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\SchemaSetupInterface;\n\nclass UpgradeSchema implements UpgradeSchemaInterface\n{\n    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $setup-&gt;startSetup();\n\n        if (version_compare($context-&gt;getVersion(), '1.1.0', '&lt;=')) {\n\n            $setup-&gt;getConnection()-&gt;addColumn(\n                $setup-&gt;getTable('inviqa_example'),\n                'email',\n                &#91;\n                    'type' =&gt; \\Magento\\Framework\\DB\\Ddl\\Table::TYPE_TEXT,\n                    'length' =&gt; 255,\n                    'nullable' =&gt; true,\n                    'comment' =&gt; 'Email'\n                ]\n            );\n\n        }\n\n        $setup-&gt;endSetup();\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Schritt 6:<\/strong> Erstellen Sie die Datei <strong>UpgradeData.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomScripts\/SetupScripts\/Setup\/UpgradeData.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace CustomScripts\\SetupScripts\\Setup;\n\nuse Magento\\Framework\\Setup\\UpgradeDataInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\ModuleDataSetupInterface;\n\nclass UpgradeData implements UpgradeDataInterface\n{\n    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $setup-&gt;startSetup();\n\n        if (version_compare($context-&gt;getVersion(), '1.1.0', '&lt;=')) {\n            $setup-&gt;getConnection()-&gt;query(\"INSERT INTO inviqa_example SET name = 'Test 2', email = 'test@inviqa.com'\");\n        }\n\n        $setup-&gt;endSetup();\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Schritt 7:<\/strong> Erstellen Sie die Datei <strong>Recurring.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomScripts\/SetupScripts\/Setup\/Recurring.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace CustomScripts\\SetupScripts\\Setup;\n\nuse Magento\\Framework\\Setup\\InstallSchemaInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\SchemaSetupInterface;\n\nclass Recurring implements InstallSchemaInterface\n{\n    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $setup-&gt;startSetup();\n\n        $setup-&gt;getConnection()-&gt;query(\"INSERT INTO inviqa_example SET name = 'Test 3', email = 'test@inviqa.com'\");\n\n        $setup-&gt;endSetup();\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Schritt 8:<\/strong> Erstellen Sie die Datei <strong>Uninstall.php.<\/strong><\/p>\n\n\n\n<p>app\/code\/CustomScripts\/SetupScripts\/Setup\/Uninstall.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace CustomScripts\\SetupScripts\\Setup;\n\nuse Magento\\Framework\\Setup\\UninstallSchemaInterface;\nuse Magento\\Framework\\Setup\\ModuleContextInterface;\nuse Magento\\Framework\\Setup\\SchemaSetupInterface;\n\nclass Recurring implements UninstallSchemaInterface\n{\n    public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context)\n    {\n        $setup-&gt;startSetup();\n\n        $setup-&gt;getConnection()-&gt;query(\"DROP table inviqa_example\");\n\n        $setup-&gt;endSetup();\n    }\n}<\/code><\/pre>\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,%20I%20contacted%20you%20through%20your%20website.\" target=\"_blank\" rel=\"noreferrer noopener\">+91-8800519180<\/a><\/strong> an, wenn Sie Unterst\u00fctzung f\u00fcr Magento 2 ben\u00f6tigen. Sie k\u00f6nnen auch die <strong><a href=\"https:\/\/www.bay20.com\/de\/magento-entwicklungsunternehmen\/\">Magento2<strong>-Entwicklungsseite<\/strong><\/a><\/strong> besuchen, um die von uns angebotenen Dienstleistungen zu \u00fcberpr\u00fcfen.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create a new module with CustomScripts_SetupScripts<\/p>\n","protected":false},"author":1,"featured_media":8407,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77,79],"tags":[],"class_list":["post-7827","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","category-magento-anleitung"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7827","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/comments?post=7827"}],"version-history":[{"count":6,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7827\/revisions"}],"predecessor-version":[{"id":17297,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/posts\/7827\/revisions\/17297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media\/8407"}],"wp:attachment":[{"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/media?parent=7827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/categories?post=7827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bay20.com\/de\/wp-json\/wp\/v2\/tags?post=7827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}