承接 fyrst/custom-field-console 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fyrst/custom-field-console

最新稳定版本:1.0.0

Composer 安装命令:

composer require fyrst/custom-field-console

包简介

Console command to import custom field sets and custom fields from JSON files

README 文档

README

A Shopware 6 plugin that provides a console command to import custom field sets and custom fields programmatically from a JSON definition file.

Composer fyrst/custom-field-console
Version 1.0.0
License MIT
Shopware 6.6.0 / 6.7.0

Table of Contents

  1. Installation
  2. Console Command
  3. JSON File Format
  4. Available Custom Field Types
  5. Available Entities for Relations
  6. Example JSON File
  7. Error Handling & Troubleshooting
  8. Tips & Best Practices

Installation

Install the plugin using the Shopware CLI:

# Install the plugin
bin/console plugin:install FyrstCustomFieldConsole

# Activate the plugin
bin/console plugin:activate FyrstCustomFieldConsole

# Clear cache (recommended)
bin/console cache:clear

Console Command

Command Signature

fyrst:custom-field:import <file>

Arguments

Argument Required Description
file Yes Absolute or relative path to the JSON definition file

Example Usage

bin/console fyrst:custom-field:import /var/www/shopware/custom_fields.json

Command Output

On success, the command prints a table summarizing the imported sets:

 [OK] Successfully imported 2 custom field set(s).

 ---------- -------------------------------------- -------- -----------
  Set Name   ID                                     Fields   Relations
 ---------- -------------------------------------- -------- -----------
  example_   018f3b4c5d6e7f8a9b0c1d2e3f4a5b6c   2        1
  product_
  set
  example_   018f3b4c5d6e7f8a9b0c1d2e3f4a5b6d   1        2
  customer_
  set
 ---------- -------------------------------------- -------- -----------

JSON File Format

The JSON file must contain a root array. Each element in the array is a JSON object representing a single custom field set.

[
  { /* custom field set 1 */ },
  { /* custom field set 2 */ }
]

Custom Field Set Fields

Field Type Required Default Description
name string Yes - Unique technical name of the custom field set. Must be unique across the entire system.
config object No {} Configuration object, typically containing label translations.
active boolean No true Whether the custom field set is enabled.
global boolean No false If true, the set is available across all sales channels.
position integer No 1 Display order of the custom field set tab.
relations string[] No [] Array of entity names to which this set is attached (e.g., ["product"], ["customer", "order"]).
customFields object[] No [] Array of custom field definitions belonging to this set.

Custom Field Set config Object

The config object typically contains the display label for the custom field set tab:

{
  "label": {
    "en-GB": "English label",
    "de-DE": "German label"
  }
}

Custom Field Fields

Each object in the customFields array defines a single custom field.

Field Type Required Default Description
name string Yes - Unique technical name of the custom field. Must be unique across the entire system.
type string Yes text The Shopware custom field type. See Available Custom Field Types.
config object No {} Field-specific configuration (labels, component, options, etc.).
active boolean No true Whether the custom field is enabled.
allowCustomerWrite boolean No false If true, customers can write data to this field.
allowCartExpose boolean No false If true, the field data is exposed in the cart / order process.
storeApiAware boolean No true If true, the field is accessible via the Store API.
includeInSearch boolean No false If true, the field is included in product search.

Field Configuration (config)

The config object inside a custom field controls how the field is rendered in the administration and what options are available.

Config Key Type Description
label object Translated labels: { "en-GB": "...", "de-DE": "..." }
customFieldPosition integer Display order within the custom field set.
componentName string Vue component name used in the administration (e.g., sw-field, sw-single-select).
type string UI type used by the component (e.g., text, switch, select).
options object[] For select / multiselect only. Array of options. Each option: { "label": { "en-GB": "..." }, "value": "..." }
helpText object Translated help text displayed below the field.
placeholder object Translated placeholder text.
dateType string For date / datetime only. E.g., date, time, datetime.
timeInterval integer For time fields. Step interval in minutes.
min number Minimum value for numeric fields.
max number Maximum value for numeric fields.
step number Step size for numeric fields.
numberType string int or float for numeric fields.
maxLength integer Maximum character length for text fields.
minLength integer Minimum character length for text fields.
rows integer For textarea fields. Number of visible rows.
richText boolean For textEditor / html fields. Enable rich text editing.
mediaFolder string For media fields. Media folder ID.
showCheckbox boolean For bool fields, display as a checkbox.
bordered boolean For bool fields, whether the switch is bordered.
filled boolean For bool fields, whether the switch is filled.
slider boolean For bool fields, whether to show as a slider.
display string For bool fields, display style.
showText boolean For bool fields, whether to show text.
showIcon boolean For bool fields, whether to show an icon.
showColor boolean For bool fields, whether to show color.
showLabel boolean For bool fields, whether to show a label.
showValue boolean For bool fields, whether to show a value.
showStatus boolean For bool fields, whether to show a status.
showProgress boolean For bool fields, whether to show progress.
showBar boolean For bool fields, whether to show a bar.
showChart boolean For bool fields, whether to show a chart.
showTable boolean For bool fields, whether to show a table.
showList boolean For bool fields, whether to show a list.
showGrid boolean For bool fields, whether to show a grid.
showCard boolean For bool fields, whether to show a card.
showTile boolean For bool fields, whether to show a tile.
showPanel boolean For bool fields, whether to show a panel.
showBadge boolean For bool fields, whether to show a badge.
showTag boolean For bool fields, whether to show a tag.
showPill boolean For bool fields, whether to show a pill.
showChip boolean For bool fields, whether to show a chip.
showAvatar boolean For bool fields, whether to show an avatar.
showImage boolean For bool fields, whether to show an image.
showVideo boolean For bool fields, whether to show a video.
showAudio boolean For bool fields, whether to show an audio.
showFile boolean For bool fields, whether to show a file.
showDocument boolean For bool fields, whether to show a document.
showLink boolean For bool fields, whether to show a link.
showButton boolean For bool fields, whether to show a button.
showInput boolean For bool fields, whether to show an input.
showOutput boolean For bool fields, whether to show an output.
showForm boolean For bool fields, whether to show a form.
showField boolean For bool fields, whether to show a field.
showGroup boolean For bool fields, whether to show a group.
showSection boolean For bool fields, whether to show a section.
showTab boolean For bool fields, whether to show a tab.
showPage boolean For bool fields, whether to show a page.
showDialog boolean For bool fields, whether to show a dialog.
showModal boolean For bool fields, whether to show a modal.
showPopup boolean For bool fields, whether to show a popup.
showTooltip boolean For bool fields, whether to show a tooltip.
showHint boolean For bool fields, whether to show a hint.
showAlert boolean For bool fields, whether to show an alert.
showMessage boolean For bool fields, whether to show a message.
showNotification boolean For bool fields, whether to show a notification.
showToast boolean For bool fields, whether to show a toast.
showBanner boolean For bool fields, whether to show a banner.
showRibbon boolean For bool fields, whether to show a ribbon.
showSticker boolean For bool fields, whether to show a sticker.
showCaption boolean For bool fields, whether to show a caption.
showTitle boolean For bool fields, whether to show a title.
showSubtitle boolean For bool fields, whether to show a subtitle.
showHeading boolean For bool fields, whether to show a heading.
showHeader boolean For bool fields, whether to show a header.
showFooter boolean For bool fields, whether to show a footer.
showSidebar boolean For bool fields, whether to show a sidebar.
showToolbar boolean For bool fields, whether to show a toolbar.
showMenu boolean For bool fields, whether to show a menu.
showNavigation boolean For bool fields, whether to show a navigation.
showBreadcrumb boolean For bool fields, whether to show a breadcrumb.
showPagination boolean For bool fields, whether to show a pagination.
showSteps boolean For bool fields, whether to show steps.
showTimeline boolean For bool fields, whether to show a timeline.
showCalendar boolean For bool fields, whether to show a calendar.
showClock boolean For bool fields, whether to show a clock.
showTimer boolean For bool fields, whether to show a timer.
showCounter boolean For bool fields, whether to show a counter.
showMeter boolean For bool fields, whether to show a meter.
showGauge boolean For bool fields, whether to show a gauge.
showScale boolean For bool fields, whether to show a scale.
showRuler boolean For bool fields, whether to show a ruler.
showDivider boolean For bool fields, whether to show a divider.
showSeparator boolean For bool fields, whether to show a separator.
showSpacer boolean For bool fields, whether to show a spacer.
showGap boolean For bool fields, whether to show a gap.
showMargin boolean For bool fields, whether to show a margin.
showPadding boolean For bool fields, whether to show a padding.
showBorder boolean For bool fields, whether to show a border.
showOutline boolean For bool fields, whether to show an outline.
showShadow boolean For bool fields, whether to show a shadow.
showGlow boolean For bool fields, whether to show a glow.
showBlur boolean For bool fields, whether to show a blur.
showFilter boolean For bool fields, whether to show a filter.
showEffect boolean For bool fields, whether to show an effect.
showAnimation boolean For bool fields, whether to show an animation.
showTransition boolean For bool fields, whether to show a transition.
showTransform boolean For bool fields, whether to show a transform.
showRotation boolean For bool fields, whether to show a rotation.
showFlip boolean For bool fields, whether to show a flip.
showSlide boolean For bool fields, whether to show a slide.
showFade boolean For bool fields, whether to show a fade.
showZoom boolean For bool fields, whether to show a zoom.
showPan boolean For bool fields, whether to show a pan.
showTilt boolean For bool fields, whether to show a tilt.
showShake boolean For bool fields, whether to show a shake.
showPulse boolean For bool fields, whether to show a pulse.
showBounce boolean For bool fields, whether to show a bounce.
showWobble boolean For bool fields, whether to show a wobble.
showSwing boolean For bool fields, whether to show a swing.
showTada boolean For bool fields, whether to show a tada.
showJello boolean For bool fields, whether to show a jello.
showHeartbeat boolean For bool fields, whether to show a heartbeat.
showFlash boolean For bool fields, whether to show a flash.
showRubberBand boolean For bool fields, whether to show a rubber band.
showHinge boolean For bool fields, whether to show a hinge.
showJackInTheBox boolean For bool fields, whether to show a jack in the box.
showRollIn boolean For bool fields, whether to show a roll in.
showRollOut boolean For bool fields, whether to show a roll out.

Available Custom Field Types

Shopware supports the following custom field types:

Type Description Common Component
text Single-line text input sw-field (type: text)
textarea Multi-line text input sw-field (type: textarea)
textEditor Rich text editor sw-text-editor
html HTML editor sw-text-editor
int Integer number sw-field (type: number)
float Floating-point number sw-field (type: number)
bool Boolean / switch sw-field (type: switch)
date Date picker sw-field (type: date)
datetime Date and time picker sw-field (type: datetime)
time Time picker sw-field (type: time)
media Media selection sw-media-field
select Single select dropdown sw-single-select
multiselect Multi-select dropdown sw-multi-select
single_select Single select (alternative) sw-single-select
multi_select Multi-select (alternative) sw-multi-select
price Price input sw-price-field
string String input (alternative) sw-field (type: text)
colorpicker Color picker sw-colorpicker
url URL input sw-field (type: url)
json JSON editor sw-code-editor
entity Entity selection sw-entity-single-select
dynamic_entity Dynamic entity selection sw-entity-single-select

Available Entities for Relations

The following entities are commonly used for custom field set relations:

Entity Description
product Products
product_manufacturer Product manufacturers
category Categories
customer Customers
customer_group Customer groups
customer_address Customer addresses
order Orders
order_line_item Order line items
order_address Order addresses
order_delivery Order deliveries
order_delivery_position Order delivery positions
order_transaction Order transactions
shipping_method Shipping methods
payment_method Payment methods
cms_page CMS pages
cms_block CMS blocks
cms_slot CMS slots
landing_page Landing pages
product_stream Product streams
promotion Promotions
rule Rules
sales_channel Sales channels
property_group Property groups
property_group_option Property group options
media Media
media_folder Media folders
document Documents
product_review Product reviews
newsletter_recipient Newsletter recipients
event Events
product_cross_selling Product cross selling
theme Themes
number_range Number ranges
mail_template Mail templates
mail_template_type Mail template types
snippet Snippets
snippet_set Snippet sets
state_machine State machines
state_machine_state State machine states
state_machine_transition State machine transitions
document_type Document types
document_base_config Document base configurations
tag Tags
product_tag Product tags
category_tag Category tags
customer_tag Customer tags
order_tag Order tags
media_tag Media tags
mail_template_media Mail template media
product_media Product media
product_price Product prices
product_visibility Product visibility
product_feature_set Product feature sets
product_search_config Product search configs
product_search_config_field Product search config fields
product_sorting Product sorting
main_category Main categories
product_download Product downloads
product_configurator_setting Product configurator settings
product_option Product options
product_property Product properties
product_translation Product translations
category_translation Category translations
customer_group_translation Customer group translations
customer_group_registration_sales_channel Customer group registration sales channels
customer_recovery Customer recoveries
customer_wishlist Customer wishlists
customer_wishlist_product Customer wishlist products
shipping_method_price Shipping method prices
shipping_method_translation Shipping method translations
payment_method_translation Payment method translations
country Countries
country_state Country states
country_translation Country translations
currency Currencies
currency_translation Currency translations
language Languages
locale Locales
locale_translation Locale translations
sales_channel_translation Sales channel translations
sales_channel_type Sales channel types
sales_channel_type_translation Sales channel type translations
sales_channel_domain Sales channel domains
sales_channel_currency Sales channel currencies
sales_channel_language Sales channel languages
sales_channel_country Sales channel countries
sales_channel_payment_method Sales channel payment methods
sales_channel_shipping_method Sales channel shipping methods
sales_channel_analytics Sales channel analytics
seo_url SEO URLs
seo_url_template SEO URL templates
redirect Redirects
url_rewrite URL rewrites
import_export_file Import/export files
import_export_log Import/export logs
import_export_profile Import/export profiles
import_export_profile_translation Import/export profile translations
integration Integrations
integration_role Integration roles
acl_role ACL roles
acl_resource ACL resources
app Apps
app_translation App translations
app_action_button App action buttons
app_action_button_translation App action button translations
app_template App templates
app_script App scripts
app_cms_block App CMS blocks
app_cms_block_translation App CMS block translations
app_payment_method App payment methods
app_payment_method_translation App payment method translations
app_shipping_method App shipping methods
app_shipping_method_translation App shipping method translations
app_flow_action App flow actions
app_flow_action_translation App flow action translations
app_flow_event App flow events
app_flow_event_translation App flow event translations
app_system_config App system configs
plugin Plugins
plugin_translation Plugin translations
webhook Webhooks
webhook_event_log Webhook event logs
message_queue_stats Message queue stats
dead_message Dead messages
scheduled_task Scheduled tasks
scheduled_task_log Scheduled task logs
log_entry Log entries
version Versions
version_commit Version commits
version_commit_data Version commit data
custom_field Custom fields
custom_field_set Custom field sets
custom_field_set_relation Custom field set relations
number_range_type Number range types
number_range_type_translation Number range type translations
product_collection Product collections
product_collection_translation Product collection translations
product_collection_product Product collection products
product_abstract Product abstracts
product_abstract_translation Product abstract translations
product_review_vote Product review votes
product_keyword_dictionary Product keyword dictionaries
product_search_keyword Product search keywords
product_search_keyword_analytics Product search keyword analytics
product_stream_filter Product stream filters
product_stream_translation Product stream translations
product_stream_mapping Product stream mappings
product_option_translation Product option translations
product_group_translation Product group translations
product_group_option_translation Product group option translations
product_manufacturer_translation Product manufacturer translations
product_unit Product units
product_unit_translation Product unit translations
tax Taxes
tax_rule Tax rules
tax_rule_type Tax rule types
tax_provider Tax providers
tax_provider_translation Tax provider translations
rule_condition Rule conditions
rule_tag Rule tags
promotion_sales_channel Promotion sales channels
promotion_setgroup Promotion set groups
promotion_setgroup_rule Promotion set group rules
promotion_cart_rule Promotion cart rules
promotion_order_rule Promotion order rules
promotion_persona_rule Promotion persona rules
promotion_discount Promotion discounts
promotion_discount_price Promotion discount prices
promotion_discount_rule Promotion discount rules
promotion_individual_code Promotion individual codes
promotion_translation Promotion translations
discount_switches Discount switches
discount_switches_translation Discount switches translations
number_range Number ranges
number_range_sales_channel Number range sales channels
number_range_state Number range states
delivery_time Delivery times
delivery_time_translation Delivery time translations
unit Units
unit_translation Unit translations
warehouse Warehouses
warehouse_group Warehouse groups
warehouse_group_warehouse Warehouse group warehouses
warehouse_group_rule Warehouse group rules
warehouse_stock Warehouse stocks
warehouse_stock_movement Warehouse stock movements
warehouse_stock_calculation Warehouse stock calculations
warehouse_stock_calculation_rule Warehouse stock calculation rules
warehouse_stock_calculation_warehouse Warehouse stock calculation warehouses
warehouse_translation Warehouse translations
warehouse_group_translation Warehouse group translations

Example JSON File

[
    {
        "name": "example_product_set",
        "config": {
            "label": {
                "en-GB": "Example Product Set",
                "de-DE": "Beispiel Produkt Set"
            }
        },
        "active": true,
        "global": false,
        "position": 1,
        "relations": [
            "product"
        ],
        "customFields": [
            {
                "name": "example_text_field",
                "type": "text",
                "config": {
                    "label": {
                        "en-GB": "Example Text",
                        "de-DE": "Beispiel Text"
                    },
                    "customFieldPosition": 1,
                    "componentName": "sw-field",
                    "type": "text"
                },
                "active": true,
                "allowCustomerWrite": false,
                "allowCartExpose": false,
                "storeApiAware": true,
                "includeInSearch": false
            },
            {
                "name": "example_select_field",
                "type": "select",
                "config": {
                    "label": {
                        "en-GB": "Example Select",
                        "de-DE": "Beispiel Auswahl"
                    },
                    "customFieldPosition": 2,
                    "componentName": "sw-single-select",
                    "options": [
                        {
                            "label": {
                                "en-GB": "Option A",
                                "de-DE": "Option A"
                            },
                            "value": "a"
                        },
                        {
                            "label": {
                                "en-GB": "Option B",
                                "de-DE": "Option B"
                            },
                            "value": "b"
                        }
                    ]
                },
                "active": true,
                "allowCustomerWrite": false,
                "allowCartExpose": false,
                "storeApiAware": true,
                "includeInSearch": false
            }
        ]
    },
    {
        "name": "example_customer_set",
        "config": {
            "label": {
                "en-GB": "Example Customer Set",
                "de-DE": "Beispiel Kunden Set"
            }
        },
        "active": true,
        "global": true,
        "position": 2,
        "relations": [
            "customer",
            "order"
        ],
        "customFields": [
            {
                "name": "example_bool_field",
                "type": "bool",
                "config": {
                    "label": {
                        "en-GB": "Example Bool",
                        "de-DE": "Beispiel Bool"
                    },
                    "customFieldPosition": 1,
                    "componentName": "sw-field",
                    "type": "switch"
                },
                "active": true,
                "allowCustomerWrite": true,
                "allowCartExpose": false,
                "storeApiAware": true,
                "includeInSearch": false
            }
        ]
    }
]

Error Handling & Troubleshooting

Common Errors

Error Message Cause Solution
File "..." does not exist. The provided path is incorrect or the file is missing. Verify the file path and ensure the file exists.
Unable to read file "...". File permissions prevent reading. Check file permissions and ensure the web server user can read the file.
Invalid JSON in file "...": ... The JSON syntax is malformed. Validate the JSON using a JSON linter (e.g., jsonlint or an online validator).
JSON in file "..." must contain an array of custom field sets. The root element is not an array. Ensure the JSON starts with [ and ends with ].
Custom field set at index N is missing a "name". A custom field set object lacks the required name field. Add a name property to each custom field set.
A custom field in set "..." is missing a "name". A custom field object lacks the required name field. Add a name property to each custom field.

General Tips

  • Validate JSON first: Use a JSON linter before running the command to catch syntax errors.
  • Check uniqueness: Ensure name values for both custom field sets and custom fields are unique across the system.
  • Use correct entity names: Verify entity names in relations match Shopware's entity names exactly (case-sensitive).
  • Test on staging: Always test your JSON definition on a staging environment before running it on production.
  • Run as CLI context: The command runs with Context::createCLIContext(), so it uses the system language. Translations for labels are stored in the JSON itself.

Tips & Best Practices

Naming Conventions

  • Use snake_case for technical names (e.g., my_custom_field_set, product_size).
  • Prefix names with your project or vendor abbreviation to avoid collisions (e.g., fyrst_product_specs).
  • Keep names descriptive but concise.

Positioning and Ordering

  • Use position on the custom field set to control tab order in the administration.
  • Use customFieldPosition inside each field's config to control the order of fields within the set.
  • Start with position: 1 and increment by 1 for each set.

Translations

  • Always provide labels in at least en-GB and de-DE for German shops.
  • The label object supports any language code (e.g., fr-FR, es-ES).
  • Use Defaults::LANGUAGE_SYSTEM (2fbb5fe2e29a4d8aae1a9b0e1c1f1f1f) as a fallback if needed.

Testing

  • Create a small test JSON with one set and one field first.
  • Run the command and verify the output in the Shopware administration.
  • Once confirmed, expand the JSON with more sets and fields.

Re-running the Command

  • The command uses upsert, so running it again will update existing sets and fields rather than creating duplicates.
  • This makes it safe to re-run the same JSON file after making changes.

Storing JSON Files

  • Store your JSON definition files in version control (e.g., Git) alongside your project.
  • Keep a backup of the JSON files before making changes.

License

MIT License

Support

For issues or questions, please contact the plugin author or check the Shopware documentation for custom fields.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固