Shopware 5.2 Pluginstruktur

Ab Shopware 5.2 gibt es ein neues Plugin-System. Plugins liegen ab dieser Version im Verzeichnis /custom/plugins/. Die Pluginstruktur besteht bei einem Plugin mit technischem Namen „LenzTest“ aus folgenden Dateien:

/custom/plugin/LenzTest (Ordner)
/custom/plugin/LenzTest/LenzTest.php
/custom/plugin/LenzTest/plugin.xml
/custom/plugin/LenzTest/schema/config.xml

Bootstrap-Datei (LenzTest.php)

Die Datei LenzTest.php ist das, was früher die Bootstrap.php war. Dort liegen alle wichtigen Programmcodes.

<?php
namespace LenzAttributeHeredity;

use Shopware\Bundle\AttributeBundle\Service\DataLoader;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\DeactivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
use Shopware\Components\Plugin\Context\UninstallContext;

class LenzAttributeHeredity extends \Shopware\Components\Plugin {
        public static function getSubscribedEvents() {
                return [
                        'Enlight_Controller_Action_PostDispatch_Frontend_Detail' => 'onPostDispatchDetail'
                ];
        }

	public function install(InstallContext $context) {
		return true;
	}

	public function update(UpdateContext $context) {
		return true;
	}

	public function activate(ActivateContext $context) {
		return true;
	}

	public function deactivate(DeactivateContext $context) {
		return true;
	}

	public function uninstall(UninstallContext $context) {
		return true;
	}

        public function onPostDispatchDetail(Enlight_Event_EventArgs $args) {
                // Implementation...
        }
}

Diese minimale Datei ist der Ausgangspunkt für ein neues Plugin. Es erweitert das Event „Enlight_Controller_Action_PostDispatch_Frontend_Detail“ in der Methode „onPostDispatchDetail“.

plugin.xml

Die Datei „plugin.xml“ enthält alle Metadaten des Plugins. Die wichtigsten sind hier am Beispiel des Plugins „Freitextfeldervererbung“ beschrieben:

<?xml version="1.0" encoding="UTF-8" ?>
<plugin>
<label>Freitextfeldervererbung</label>
<version>1.1.0</version>
<copyright>Shopdoktor.com</copyright>
<license>proprietary</license>
<link>https://www.shopdoktor.com/</link>
<author>Sebastian Lenz</author>
<description>Mit diesem Plugin steht der Inhalt der Artikelfreitextfelder auch in den Varianten zur Verfügung.</description>
</plugin>

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben scrollen