ctidigital/magento-configurator

Magento 配置器

安装: 153

依赖关系: 0

建议者: 0

安全: 0

星标: 73

关注者: 26

分支: 18

开放问题: 4

类型:magento-module

v0.15.0 2016-04-11 10:10 UTC

This package is auto-updated.

Last update: 2024-09-09 19:02:47 UTC


README

这是一个由 CTI Digital 初始创建的 Magento 模块,用于通过文件创建和维护数据库变量。本模块旨在为 Magento 开发者的工作流程带来以下好处

  • 从零开始安装 Magento,并准备好重要的基于数据库的配置。
  • 使用您自己的版本控制系统与其他同事共享和协作配置。
  • 使用您自己的版本控制系统保留配置的版本。
  • 根据您正在开发的 环境 分割配置。

如果您想了解更多关于配置器背景的信息,请观看 Rick Steckles 在曼彻斯特 Mage Titans 上的闪电演讲,YouTube

版本

0.15.0

安装

使用 Modman

$ cd <your magento install>
$ modman clone https://github.com/ctidigital/magento-configurator.git

传统方式

下载并将 src/ 文件夹的内容复制到您的 Magento 基础目录。

如何使用

首先,我们需要配置我们的组件。您可以在“组件”标题下找到如何配置您的组件。

在您的 magento 目录中,您可以使用以下命令运行配置器

$ cd <your magento install>/shell
$ php configurator.php

列出可用组件

$ php configurator.php --list-components

运行特定组件

$ php configurator.php --run-components "media,pages,staticBlocks"

组件

网站 & 商店

通常,在启动项目时应该配置的第一个组件。它用于创建和维护您的网站、商店和商店视图,并使用 YAML 控制,该 YAML 需要位于 app/etc/components/websites.yaml。一般结构如下

- websites:
  - website_code_1:
      name: Website Name
      - store_groups:
          -
            name: Store Group Name
            root_category: Default Category
            stores:
              - store_code_1:
                  name: Default Store View Name
              - store_code_2:
                  name: Store View Name 2
         -
            name: Store Group Name 2
            root_category: New Root Category
            stores:
              - store_code_3:
                  name: Store View Name 3
  - website_code_2:
      name: Website Name 2
      - store_groups:
          -
            name: Store Group Name 3
            root_category: Default Category
            stores:
              - store_code_4:
                  name: Store View Name 4

YAML 遵循树状结构,支持以下规则

  • 可以创建许多网站
  • 一个网站可以有多个商店组
  • 商店组分支可以有多个商店视图

排序顺序将根据 YAML 编写的顺序自动创建。

核心配置数据

在您的网站正确设置后,此步骤用于设置默认(全局)、网站级别和商店视图级别的核心配置元素。最终节点需要一个 path 和一个 value,这将设置在您的 Magento 的 core_config_data 中。如果您不知道路径应该是多少,您可以通过查看模块的 system.xml 文件或保存一个带有配置的页面(在 Magento 的管理界面中)来找到它,然后保存相关部分在“系统 -> 配置”中,并在数据库的 core_config_data 表中查找它。该文件需要位于 app/etc/components/config.yaml。您也可以在我们的 config.yaml 文件中找到一个例子,说明如何构建文件。

默认

- global:
    core_config:
      -
        path: design/package/name
        value: base
      -
        path: design/theme/default
        value: default

可继承

有时我们需要将配置分组用于许多网站或商店视图,因此为了保持我们的 YAML 结构整洁,我们也有分组配置的支持。例如,一些网站可能共享相同的 PayPal 支付配置。

- grouped:
  - paypal:
      core_config:
        -
          path: payment/pbridge/profilestatus
          value: 0
        -
          path: payment/paypal_express/active
          value: 1
        -
          path: payment/paypal_express_bml/active
          value: 0

网站

如果我们需要特定的网站配置,可以这样定义

- websites:
  - base:
      core_config:
        -
          path: general/locale/timezone
          value: Europe/London

我们还可以使用 inherit 键继承我们的分组配置

- websites:
  - base:
      inherit:
        - paypal
      core_config:
        -
          path: general/locale/timezone
          value: Europe/London

商店

类似于网站,我们也可以定义商店视图级别的配置,它也支持继承

- stores:
  - default:
      core_config:
        -
          path: general/locale/code
          value: en_GB

加密值

一些核心 Magento 字段也加密了我们的配置,我们可以这样定义

        -
          path: paypal/wpp/api_password
          value: 111111111
          encrypted: 1

产品属性

用于维护产品属性的文件位于 app/etc/components/attributes.yaml。这允许您修改自定义属性,并使用此文件维护属性选项。

以下是属性的基本所需结构

- attributes:
  - attribute_code:
      frontend_label: Attribute Code
      frontend_input: select
      product_types:
        - simple
        - configurable
        - bundle
        - grouped

以下是典型属性及其默认值的基本结构

- attributes:
  - attribute_code:
      is_global: 0
      is_visible: 1
      is_searchable: 0
      is_filterable: 0
      is_comparable: 0
      is_visible_on_front: 0
      is_html_allowed_on_front: 0
      is_filterable_in_search: 0
      used_in_product_listing: 0
      used_for_sort_by: 0
      is_configurable: 0
      is_visible_in_advanced_search: 0
      position: 0
      is_wysiwyg_enabled: 0
      is_used_for_promo_rules: 0
      default_value_text: ''
      default_value_yesno: 0
      default_value_date: ''
      default_value_textarea: ''
      is_unique: 0
      is_required: 0
      frontend_input: boolean
      search_weight: 1

我们还可以指定选择类型属性的产品选项,如下所示

- attributes:
  - colour:
      frontend_label: Colour
      frontend_input: select
      product_types:
        - simple
      options:
        - Red
        - Green
        - Yellow
        - Blue
        - Purple
        - Pink
        - Orange

我们还可以指定属性的商店标签,如下所示

- attributes:
  - attribute_code:
      frontend_label: Attribute Code
      frontend_input: select
      - store_labels:
        default: Default Store Label
        en: Label for store code en

请注意,某些属性配置遵循某些规则,因此请确保您熟悉 Magento 产品属性的工作方式,以便充分利用此组件。属性的配置元素仅仅是 catalog_eav_attribute 表中的字段,但有少数例外。

属性集

创建自定义产品属性后,这些属性将需要包含在属性集中。为此,我们需要文件 app/etc/components/attribute-sets.yaml 和文件内容如下

- attribute_sets:
  -
    name: Example Attribute Set
    inherit: Attribute Set to Inherit (Default)
    groups:
      -
        name: Attribute Group Name (General)
        attributes:
          - attribute_code
          - attribute_code2

使用 inherit: <属性集名称> 将使用现有属性集作为新属性集的框架。默认情况下,它将继承名为 Default 的属性集,该属性集必须已存在于您的 Magento 安装中。

请以我们的示例文件为参考。

其他组件

有许多其他组件可以帮助填充 Magento,您可以从 samples/components 中查看这些组件。这些组件可以帮助您使用相关的示例/配置数据启动 Magneto 安装。

限制

  • 无法在属性组之间移动属性。
  • 无法从属性集中删除现有属性。

开发

想要贡献?太好了!我们已尝试构建模块以使其可扩展,因此如果您愿意贡献,那么应该相当容易。但是,您必须遵循一些规则。

Config.xml

首先,在 app/code/community/Cti/Configurator/etc/config.xml 中,您将找到以下 xml

...
    <global>
        <configurator_processors>
            <components>
                <website>cti_configurator/components_website</website>
                <config>cti_configurator/components_config</config>
            </components>
        </configurator_processors>
    </global>
...

在此,您可以定义您希望贡献的任何组件。如果您想扩展以在您的模块内创建自己的组件,您可以通过在您的模块的 config.xml 中添加自己的组件助手别名来实现。

组件助手

您需要在模块中创建一个助手类,最好在组件子文件夹中,并且它应该扩展 Cti_Configurator_Helper_Components_Abstract,这将要求您

  • 指定一个唯一的组件名称,用于记录过程和事件分发 $this->_componentName
  • 指定您要处理的文件,通过将绝对路径分配给变量 $this->_filePath1
  • (可选)指定 $this->_filePath2 作为在环境之间拆分配置的方法。
  • 创建一个受保护的 _processFile() 函数,用于将您的文件(和合并)解析为您的选择格式。
  • 创建一个受保护的 _processComponent() 函数,用于处理您从已处理的文件中获取的数据。

抽象函数将处理其余部分。您可以查看我们的 Helper/Components/Website.phpHelper/Components/Config.php,了解您应该如何构建组件助手。

路线图

  • 为管理员用户和角色创建组件
  • 更好的 CLI 记录
  • 编写测试

许可证

MIT