ntzrbtr/shopware-custom-field-installer

Shopware 6的自定义字段安装程序

v1.0.3 2024-02-05 09:51 UTC

This package is auto-updated.

Last update: 2024-09-05 10:57:04 UTC


README

此包提供了一种简单的方法来安装和卸载Shopware安装中的自定义字段:它利用Shopware核心中的代码来处理应用程序,使其可以作为独立程序使用。

该包提供了一个新的命令netzarbeiter:custom-fields:update,用于更新Shopware安装中的自定义字段。该命令接受一个遵循Shopware应用程序Manifest标准的XML文件作为输入,并更新数据库。

有关应用程序中自定义字段的更多信息,请参阅https://developer.shopware.com/docs/guides/plugins/apps/custom-data/custom-fields

用法

bin/console netzarbeiter:custom-fields:install <file>
bin/console netzarbeiter:custom-fields:uninstall <file>

由于包的核心是在一个服务中实现的,您也可以不使用命令来使用它,例如将其集成到Shopware插件的安装过程中。

<?php declare(strict_types=1);

namespace Swag\BasicExample;

use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;

class SwagBasicExample extends Plugin
{
    public function install(InstallContext $installContext): void
    {
        $customFieldInstaller = $this->container->get(CustomFieldInstaller::class);
        $customFieldInstaller->install($this->getPath() . '/Resources/app/custom-field-set.xml', $installContext->getContext());
    }
}

XML文件

XML文件必须符合应用程序系统的模式;这意味着您还需要在文件中提供最小的meta部分。

以下是一个简约示例

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/Framework/App/Manifest/Schema/manifest-2.0.xsd">
    <meta>
        <name>MyExampleApp</name>
        <author>Your Company Ltd.</author>
        <copyright>(c) by Your Company Ltd.</copyright>
        <version>1.0.0</version>
        <license>MIT</license>
    </meta>
    <custom-fields>
        <!-- register each custom field set you may want to add -->
        <custom-field-set>
            <!-- the technical name of the custom field set, needs to be unique, therefor use your vendor prefix -->
            <name>swag_example_set</name>
            <!-- Translatable, the label of the field set -->
            <label>Example Set</label>
            <label lang="de-DE">Beispiel-Set</label>
            <!-- define the entities to which your field set should be assigned -->
            <related-entities>
                <order/>
            </related-entities>
            <!-- define the fields in your set -->
            <fields>
                <!-- the element type, defines the type of the field -->
                <!-- the name needs to be unique, therefore use your vendor prefix -->
                <text name="swag_code">
                    <!-- Translatable, the label of the field -->
                    <label>Example field</label>
                    <!-- Optional, Default = 1, order your fields by specifying the position -->
                    <position>1</position>
                    <!-- Optional, Default = false, mark a field as required -->
                    <required>false</required>
                    <!-- Optional, Translatable, the help text for the field -->
                    <help-text>Example field</help-text>
                </text>
                <float name="swag_test_float_field">
                    <label>Test float field</label>
                    <label lang="de-DE">Test-Kommazahlenfeld</label>
                    <help-text>This is an float field.</help-text>
                    <position>2</position>
                    <!-- some elements allow more configuration, like placeholder, main and max values etc. -->
                    <!-- Your IDE should give you pretty good autocompletion support to explore the configuration for a given type -->
                    <placeholder>Enter an float...</placeholder>
                    <min>0.5</min>
                    <max>1.6</max>
                    <steps>0.2</steps>
                </float>
            </fields>
        </custom-field-set>
    </custom-fields>
</manifest>

安装

请确保已全局安装Composer,如Composer文档中的安装章节中所述。

使用Symfony Flex的应用程序

打开命令行,进入项目目录,执行以下命令:

$ composer require <package-name>

不使用Symfony Flex的应用程序

步骤1:下载包

打开命令行,进入项目目录,执行以下命令以下载此包的最新稳定版本:

$ composer require <package-name>

步骤2:启用包

然后,通过将其添加到项目中config/bundles.php文件中注册的包列表中,来启用该包。

// config/bundles.php

return [
    // ...
    Netzarbeiter\Shopware\CustomFieldInstaller\NetzarbeiterShopwareCustomFieldInstallerBundle::class => ['all' => true],
];