Пример файла addon.xml (схема 3.0) c комментариями

Совместим с CS-Cart: 4.2.x — ...

Схема модуля

Полная схема модуля с комментариями.

Пример:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?xml version="1.0"?>
<!--
    Описание схемы аддона версии 3.0
    Все параметры не отмеченные как необязательные должны быть определены в схеме.
    @edition_type - Необязательный атрибут, доступный для любого элемента, связанного с настройками. Определяет редакции, в которых доступна та или иная настройка. Берётся либо значение текущего узла, либо родителя, либо ROOT (если вообще ничего нет).
-->
<addon scheme="3.0" edition_type="ROOT,ULT:VENDOR">
    <!-- Идентификатор аддона; должен быть равен имени каталога, в котором лежит аддон. -->
    <id>sample_addon_3_0</id>
    <!-- Версия аддона -->
    <version>1.0</version>
    <!-- Родной язык аддона (по умолчанию). Необязательный параметр; если не указан, то язык будет распознаваться как английский (EN). -->
    <default_language>en</default_language>
    <!-- Приоритет аддона. Чем выше, тем позже аддон подключается. -->
    <priority>100</priority>
    <!-- Статус, который будет выставлен после установки аддона (active/disabled). По умолчанию disabled. -->
    <status>active</status>
    <!-- Определяет, в каких редакциях аддон будет установлен по умолчанию. -->
    <auto_install>MULTIVENDOR,ULTIMATE</auto_install>
    <!-- Блок для описания совместимостей с другими аддонами. -->
    <compatibility>
        <!-- Зависимости. Эти аддоны должны быть установлены, чтобы установить текущий аддон; в противном случае будет выведено сообщение об ошибке. -->
        <dependencies>discussion,form_builder</dependencies>
        <!-- Конфликты. Эти аддоны будут автоматически выключены перед установкой данного аддона, и будет выведено сообщение об этом. -->
        <conflicts>catalog_mode,reward_points</conflicts>
    </compatibility>
    
    <!-- Блок настроек аддона. Необязательный.
        @layout - Место, где будет открываться страница с настройками (popup/separate). Необязательный атрибут. По умолчанию popup.
    -->
    <settings layout="separate" edition_type="ROOT,ULT:VENDOR">
        <!-- Список вкладок на странице настроек аддона. -->
        <sections>
            <!-- Вкладка для настроек.
                @id - текстовый идентификатор. В дальнейшем к этой настройке можно будет обращаться через Registry::get('addons.[addon_id].[setting_id]')
                @edition_type - список редакций, в которых данная вкладка будет доступна. Необязательный.
            -->
            <section id="section1">
                <!-- Список настроек во вкладке. -->
                <items>
                    <!-- Настройки аддона
                        @id - идентификатор настройки.
                        @edition_type - список редакций, в которых данная настройка будет доступна. Необязательный.
                    -->
                    <item id="header">
                        <!-- Тип элемента:
                            input, textarea, password, checkbox, selectbox, multiple select,
                            multiple checkboxes, countries list, states list,
                            file, info, header, template
                        -->
                        <type>header</type>
                        <variants/>
                    </item>
                    <item id="input">
                        <type>input</type>
                        <variants/>
                    </item>
                    <item id="password">
                        <type>password</type>
                        <variants/>
                    </item>
                    <item id="checkbox">
                        <type>checkbox</type>
                        <variants/>
                    </item>
                    <item id="textarea">
                        <type>textarea</type>
                        <default_value>Sample textarea text</default_value>
                        <variants/>
                    </item>
                    <item id="radiogroup">
                        <type>radiogroup</type>
                        <default_value>radio_2</default_value>
                        <!-- Варианты - для типов selectbox, multiple select,
                            multiple checkboxes, combo select -->
                        <variants>
                            <!-- @id - идентификатор варианта-->
                            <item id="radio_1"></item>
                            <item id="radio_2"></item>
                        </variants>
                    </item>
                    <item id="file">
                        <type>file</type>
                        <variants/>
                    </item>
                </items>
            </section>
            <section id="section2">
                <translations>
                    <item lang="ru">Списки</item><!-- Может быть переведен через PO (SettingsSection) -->
                </translations>
                <items>
                    <item id="selectbox">
                        <type>selectbox</type>
                        <variants>
                            <item id="select_box_1"></item>
                            <item id="select_box_2"></item>
                        </variants>
                    </item>
                    <item id="countries_list">
                        <type>countries list</type>
                        <variants/>
                    </item>
                    <item id="states_list">
                        <type>states list</type>
                        <variants/>
                    </item>
                    <item id="multiple_select">
                        <type>multiple select</type>
                        <variants>
                            <item id="select_box_1"></item>
                            <item id="select_box_2"></item>
                            <item id="select_box_3"></item>
                        </variants>
                    </item>
                    <item id="multiple_checkboxes">
                        <type>multiple checkboxes</type>
                        <variants>
                            <item id="select_box_1"></item>
                            <item id="select_box_2"></item>
                            <item id="select_box_3"></item>
                        </variants>
                        <default_value>select_box_2</default_value>
                    </item>
                </items>
            </section>
            <section id="section3">
                <items>
                    <item id="selectable_box">
                        <!-- Варианты данной настройки будут браться из функции fn_settings_variants_addons_[addon_id]_[setting_id]-->
                        <type>selectable_box</type>
                        <default_value><![CDATA[#M#product_code=Y&product=Y&amount=Y&price=Y]]></default_value>
                        <variants/>
                    </item>
                    <!-- В данном случае будет выводиться информация, возвращаемая функцией handler -->
                    <item id="info">
                        <type>info</type>
                        <handler>fn_sample_addon_3_0_info</handler>
                        <variants/>
                    </item>
                    <!-- Вид настройки типа шаблон. В данном случае подключается пользовательский шаблон из папки themes/THEME_NAME/addons/ADDON_NAME/setings/TEMPLATE_NAME
                         Имя шаблона хранится в default_value. -->
                    <item id="template">
                        <type>template</type>
                        <default_value>sample.tpl</default_value>
                        <variants/>
                    </item>
                    <!-- Скрытая настройка. Существует в базе данных и в Registry, но не выводится пользователю. -->
                    <item id="hidden">
                        <type>hidden</type>
                        <default_value>Some hidden setting value</default_value>
                    </item>
                </items>
            </section>
        </sections>
    </settings>

    <!-- Дополнительные запросы к базе данных-->
    <queries>
        <!-- Если параметр for="install" или его вообще нет - запрос выполняется во время установки аддона-->
        <item for="install">
        CREATE TABLE `?:addon_test_123456789` (
            `queue_id` mediumint NOT NULL auto_increment,
            PRIMARY KEY  (`queue_id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=UTF8
        </item>
        <!-- Если задан атрибут editions, то запрос будет выполнен только для тех редакций, которые указаны в нём через запятую. -->
        <item for="install" editions="ULTIMATE,MULTIVENDOR">
            ALTER TABLE `?:addon_test_123456789` ADD company_id INT NOT NULL DEFAULT 0;
        </item>
        <!-- Если параметр for="uninstall", запрос выполняется во время удаления аддона-->
        <item for="uninstall">DROP TABLE IF EXISTS `?:addon_test_123456789`</item>
    </queries>
    <!-- Пользовательские функции, вызывающиеся при наступлении определённых событий
            before_install - перед установкой аддона.
            install - после установки аддона, его шаблонов, настроек, языковых переменных, но перед его активацией и очисткой кэша
            uninstall - перед удалением
            -->
    <functions>
        <item for="install">fn_google_export_add_features</item>
        <item for="install">fn_google_export_add_feed</item>
        <item for="uninstall">fn_google_export_remove_features</item>
        <item for="uninstall">fn_google_export_remove_feed</item>
    </functions>
</addon>

Функции для настроек

Вы можете использовать функции, чтобы получить варианты настроек, если это необходимо.

Пример:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/***************************************************************************
*                                                                          *
*   (c) 2004 Vladimir V. Kalynyak, Alexey V. Vinokurov, Ilya M. Shalnev    *
*                                                                          *
* This  is  commercial  software,  only  users  who have purchased a valid *
* license  and  accept  to the terms of the  License Agreement can install *
* and use this program.                                                    *
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/

if (!defined('BOOTSTRAP')) { die('Access denied'); }

function fn_settings_variants_addons_sample_addon_3_0_selectable_box()
{
    $schema = array(
        'fields' => array(
            'product_id' => array('title' => __('product_id'), 'sort_by' => ''),
            'product' => array('title' => __('product_name'), 'sort_by' => 'product'),
            'min_qty' => array('title' => __('min_order_qty'), 'sort_by' => ''),
            'max_qty' => array('title' => __('max_order_qty'), 'sort_by' => ''),
            'product_code' => array('title' => __('sku'), 'sort_by' => 'code'),
            'amount' => array('title' => __('quantity'), 'sort_by' => 'amount'),
            'price' => array('title' => __('price'), 'sort_by' => 'price'),
            'weight' => array('title' => __('weight'), 'sort_by' => 'weight'),
            'image' => array('title' => __('image'), 'sort_by' => ''),
        ),
    );
    $result = array();

    if (!empty($schema['fields'])) {
        foreach ($schema['fields'] as $field_id => $field) {
            $result[$field_id] = $field['title'];
        }
    }

    return $result;
}

function fn_sample_addon_3_0_info()
{
    $text = __('sample_addon_handler') . '<hr/>' . __('test_xml_3.0_1') . '<br />' . __('test_xml_3.0_2');

    return $text . '<hr/>' ;
}

Файл с переводами

Переводы добавляются с помощью файла «.po», который должен быть расположен в папке: /var/langs/en/addons/[id_модуля].po

Важно

Для каждого яыка потребуется отдельный «.po» файл с переводом. Размещать дополнительные переводы необходимо в папке с соответсвующим кодом языка: /var/langs/[код_языка]/addons/[id_модуля].po

Значение msgid должно быть одинаковым для всех языков.

Пример:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
msgid ""
msgstr "Project-Id-Version: tygh"
"Content-Type: text/plain; charset=UTF-8\n"
"Language-Team: English\n"
"Language: en_US"

msgctxt "Addons::name::sample_addon_3_0"
msgid "3.0 scheme addon sample"
msgstr "3.0 scheme addon sample"

msgctxt "Addons::description::sample_addon_3_0"
msgid "Sample add-on description. Do not use the add-on in production mode."
msgstr "Sample add-on description. Do not use the add-on in production mode."

msgctxt "Languages::test_xml_3.0_1"
msgid "First language variable"
msgstr "First language variable"

msgctxt "Languages::test_xml_3.0_2"
msgid "Second language variable"
msgstr "Second language variable"

msgctxt "Languages::sample_addon_handler"
msgid "Sample addon handler"
msgstr "Sample addon handler"

msgctxt "SettingsSections::sample_addon_3_0::section1"
msgid "Generic settings"
msgstr "Generic settings"

msgctxt "SettingsSections::sample_addon_3_0::section2"
msgid "Selects"
msgstr "Selects"

msgctxt "SettingsSections::sample_addon_3_0::section3"
msgid "Additional settings"
msgstr "Additional settings"

msgctxt "SettingsOptions::sample_addon_3_0::header"
msgid "Header"
msgstr "Header"

msgctxt "SettingsOptions::sample_addon_3_0::input"
msgid "Input"
msgstr "Input"

msgctxt "SettingsOptions::sample_addon_3_0::password"
msgid "Password input"
msgstr "Password input"

msgctxt "SettingsOptions::sample_addon_3_0::checkbox"
msgid "Checkbox"
msgstr "Checkbox"

msgctxt "SettingsOptions::sample_addon_3_0::textarea"
msgid "Textarea"
msgstr "Textarea"

msgctxt "SettingsOptions::sample_addon_3_0::radiogroup"
msgid "Radio group box"
msgstr "Radio group box"

msgctxt "SettingsOptions::sample_addon_3_0::file"
msgid "File"
msgstr "File"

msgctxt "SettingsOptions::sample_addon_3_0::selectbox"
msgid "Selectbox"
msgstr "Selectbox"

msgctxt "SettingsOptions::sample_addon_3_0::countries_list"
msgid "Countries list"
msgstr "Countries list"

msgctxt "SettingsOptions::sample_addon_3_0::states_list"
msgid "States list"
msgstr "States list"

msgctxt "SettingsOptions::sample_addon_3_0::multiple_select"
msgid "Multiple select"
msgstr "Multiple select"

msgctxt "SettingsOptions::sample_addon_3_0::multiple_checkboxes"
msgid "Multiple checkboxes"
msgstr "Multiple checkboxes"

msgctxt "SettingsOptions::sample_addon_3_0::selectable_box"
msgid "Selectable box"
msgstr "Selectable box"

msgctxt "SettingsOptions::sample_addon_3_0::info"
msgid "Info Url"
msgstr "Info Url"

msgctxt "SettingsTooltips::sample_addon_3_0::input"
msgid "Tooltip"
msgstr "Tooltip"

msgctxt "SettingsVariants::sample_addon_3_0::radiogroup::radio_1"
msgid "Radio button 1"
msgstr "Radio button 1"

msgctxt "SettingsVariants::sample_addon_3_0::radiogroup::radio_2"
msgid "Radio button 2"
msgstr "Radio button 2"

msgctxt "SettingsVariants::sample_addon_3_0::multiple_checkboxes::select_box_1"
msgid "Select box item 1"
msgstr "Select box item 1"

msgctxt "SettingsVariants::sample_addon_3_0::multiple_checkboxes::select_box_2"
msgid "Select box item 2"
msgstr "Select box item 2"

msgctxt "SettingsVariants::sample_addon_3_0::multiple_checkboxes::select_box_3"
msgid "Select box item 3"
msgstr "Select box item 3"