The SetupModule makes it easy to install new persistent data for your current Magento 2 project.
It allows adding of the following Magento 2 data:
- EAV attribute groups
- EAV attributes
- content pages
- content blocks
customer groups(TBD / WIP!)menus(TBD / WIP!)
If you want to setup data, just add the resource folders as described in the following sections
in your themes Team23_SetupModule module override and run bin/magento setup:upgrade
.
All resources with a version >= the setup version stored in core_config_data
's path team23/setup_module/version
will become installed.
In rare cases when you want to repeat the installation process, just change the config with path
team23/setup_module/version
stored in core_config_data
in the database.
In app/design/frontend/VENDOR/THEME/Team23_SetupModule/
app
|-- ...
`-- design
|-- ...
`-- frontend
|-- ...
`-- VENDOR
`-- THEME
|-- ...
`-- Team23_SetupModule
`-- resources
|-- attribute
|-- attribute_group
|-- block
|-- customer_group # (TBD / WIP!)
|-- menu # (TBD / WIP!)
`-- page
Whenever bin/magento setup:upgrade
will be run the extension will
- look in its data resource folders for defined and valid xml files (i.e.
filename_1.0.0.xml
) - extract the files version number of the files & compare it with the current setup version in the database (in
core_config_data
:team23/setup_module/version
) - run creation for all resources with a higher version than the setup version stored in the database (initially 0.0.0)
- increase the setup version in the database to the highest version of all resources
- Add satis.team23.de composer repository in your composer.json
composer config repositories.team23 composer https://satis.team23.de/
- Require team23/module-setupmodule
composer require team23/module-setupmodule ^dev-master
Resource files will be read from resources/{TYPE}/
.
To add a new resource file add a XML file with the of your choice. The file MUST end on (_
) followed by a
php compatible version number >= 1.0.0
and the file extension .xml
e.g. new-attribute_1.0.0.xml
.
The xml tags contents refer to the resources creation parameters, that Magento 2 uses in its functions. Therefore they MUST follow Magentos internal requirements (i.e. attribute codes must be written in snake_case).
Attribute files will be read from resources/attribute
.
xml
- the surrounding root tagcode
- the attribute code
The following optional attributes are currently supported. For more information check the Product EAV Attribute Options Reference
input
label
type
source
visible
- defaults to0
required
- defaults to0
user_defined
- defaults to0
default
searchable
- defaults to0
filterable
- defaults to0
comparable
- defaults to0
visible_on_front
- defaults to0
is_used_in_grid
- defaults to0
is_filterable_in_grid
- defaults to0
used_in_product_listing
- defaults to0
backend
IMPORTANT NOTE
When using source
or backend
tags, make sure the provided class is defined, otherwise that will lead to errors once
stored in the database. That's why SetupModule will throw an Exception if the class is not already defined.
<xml>
<code>my_custom_code</code>
<input>text</input>
<label>My label text</label>
<visible>1</visible>
<required>0</required>
<user_defined>1</user_defined>
<searchable>0</searchable>
<filterable>0</filterable>
<comparable>0</comparable>
<visible_on_front>1</visible_on_front>
<is_used_in_grid>0</is_used_in_grid>
<used_in_product_listing>1</used_in_product_listing>
<group>My example group</group>
</xml>
Attribute Group files will be read from resources/attribute_group
.
xml
- the surrounding root tagname
- the groups name
sort_order
<xml>
<name>Demo Group</name>
<sort_order>1</sort_order>
</xml>
Block files will be read from resources/block
.
xml
- the surrounding root tagidentifier
- the blocks unique identifier (must be snake_case)title
- the blocks title
content
- defaults to''
; Feel free to use CDATA for unescaped htmlstore_id
- defaults to0
is_active
- defaults to0
<xml>
<identifier>block_mydemo</identifier>
<title>My demo block</title>
<content><![CDATA[<h2>My demo title in HTML</h2>
<p>Foo bar baz!</p>]]></content>
<store_id>0</store_id>
<is_active>1</is_active>
</xml>
Page files will be read from resources/page
.
xml
- the surrounding root tagidentifier
- the pages unique identifier (must be snake_case)title
- the pages title
content_heading
content
- defaults to''
; Feel free to use CDATA for unescaped htmlstore_id
- defaults to0
is_active
- defaults to0
page_layout
- defaults to1column
<xml>
<identifier>no-route</identifier>
<title>404 - My custom 404 override</title>
<content_heading>404 - This is my overrides content heading</content_heading>
<content>
<![CDATA[
<div class="error-section">
<p>Im sorry...</p>
<div class="error-row">
<a href="/">Back to home</a>
</div>
</div>
]]>
</content>
<store_id>0</store_id>
<is_active>1</is_active>
<page_layout>1column</page_layout>
</xml>