momocode / shopware-6-plugin-base
可作为Shopware 6插件内部Composer依赖项加载的基本库
v1.1.1
2022-09-01 18:31 UTC
This package is auto-updated.
Last update: 2024-09-29 05:48:45 UTC
README
此库包含可能在所有自定义插件中都有用的抽象。它提供以下功能
- 迁移助手
- 用于新邮件类型的助手类
- 更多功能即将推出
安装
在您的插件中要求Composer包
composer require momocode/shopware-6-plugin-base
将Composer自动加载器添加到插件引导类,并让您的插件继承Momocode\Shopware6Base\Plugin
抽象
<?php namespace MyPlugin; use Momocode\Shopware6Base\Plugin; // Autload extra dependencies if (file_exists(__DIR__ . '/vendor/autoload.php')) { require_once __DIR__ . '/vendor/autoload.php'; } class MyPlugin extends Plugin {}
因此,如果您的迁移扩展了AbstractMigration
,则在插件卸载时将调用所有reverse
函数。
迁移
以下是一些Shopware 6迁移的辅助类。首先使用以下命令为您的插件创建迁移
./bin/console database:create-migration -p YourPluginName --name MigrationDescription
在您的插件的Migration
文件夹中现在有一个新的迁移文件。它扩展了Shopware\Core\Framework\Migration\MigrationStep
类。现在您可以将扩展更改为以下辅助类之一。
邮件类型迁移
如果您想添加新的邮件模板类型,您可以使用MailTypeMigration
类。如果您的迁移扩展了MailTypeMigration
,则需要两个函数。以下是一个示例
<?php declare(strict_types=1); namespace YourPlugin\Migration; use Momocode\Shopware6Base\Migration\MailTypeMigration; use Shopware\Core\Framework\Uuid\Uuid; class Migration1586007577NewMailTypes extends MailTypeMigration { public function getCreationTimestamp(): int { return 1586007577; } protected function getMailTypeMapping(): array { return [ 'your_technical_template_name' => [ 'id' => Uuid::randomHex(), 'name' => 'Your english template description', 'nameDe' => 'Deine deutsche Beschreibung', 'availableEntities' => json_encode(['salesChannel' => 'sales_channel']), ], ]; } }
现在助手类将调用getMailTypeMapping
并创建您的邮件类型。