bestit/commercetools-custom-types-bundle

帮助您创建自定义类型的包。

0.10.0 2021-01-27 15:21 UTC

README

帮助您创建自定义类型的包。它提供了与您的自定义类型结构匹配的symfony配置参数,然后将其镜像到您的commercetools项目中。

安装

步骤 1: 下载包

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

$ composer require bestit/commercetools-custom-types-bundle

此命令要求您全局安装了Composer,如Composer文档的安装章节中所述。

步骤 2: 启用包

然后,将包添加到项目中app/AppKernel.php文件中注册的包列表中,以启用该包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new BestIt\CTCustomTypesBundle\BestItCTCustomTypesBundle(),
        );

        // ...
    }

    // ...
}

步骤 3: 配置

# Default configuration for extension with alias: "best_it_ct_custom_types"
best_it_ct_custom_types:

    # Add the types mainly documented under: <https://dev.commercetools.com/http-api-projects-types.html>
    types:

        # Prototype
        key:
            name:                 # Required

                # Prototype
                lang:                 ~
            description:          # Required

                # Prototype
                lang:                 ~

            # https://dev.commercetools.com/http-api-projects-custom-fields.html#customizable-resources
            resourceTypeIds:      [] # Required

            # http://dev.commercetools.com/http-api-projects-types.html#fielddefinition
            fieldDefinitions:     # Required

                # Prototype
                name:
                    type:                 # Required
                        name:                 ~ # One of "Boolean"; "String"; "LocalizedString"; "Enum"; "Number"; "Money"; "Date"; "T
ime"; "DateTime"; "Set", Required

                        # Specially used to the set type: <http://dev.commercetools.com/http-api-projects-types.html#settype>
                        elementType:
                            name:                 ~ # One of "Boolean"; "String"; "LocalizedString"; "Enum"; "Number"; "Money"; "Date"
; "Time"; "DateTime"; "Set", Required
                            values:

                                # Prototype
                                key:                  ~
                        values:

                            # Prototype
                            key:                  ~
                    required:             false # Required
                    inputHint:            ~ # One of "MultiLine"; "SingleLine", Required
                    label:                # Required

                        # Prototype
                        lang:                 ~

    # The shell command works on the complete set of types normally. To prevent side effects while changing or deleting types which ar
e "unknown at this moment" define a whitelist for types, on which you are allowed to work on.
    whitelist:            []
    commercetools_client_service: ~ # Required

用法

以下symfony命令将您的类型配置镜像到commercetools数据库

$ php bin/console commercetools:process-custom-types [<whitelist>]

它尝试删除配置中未声明或由白名单(配置或不含分隔符的pcre正则表达式)排除的每个自定义类型。

其他待办事项

  • 添加单元测试
  • 重构命令
  • 更好地支持复杂类型