Search code examples
configuratione-commerceshopware6

Shopware 6: how to add to custom plugin configuration single-select with list of country


For the creation single select list we have:

        <input-field type="single-select">
            <name>currentCountry</name>
            <label>Current country</label>
            <required>true</required>
            <options>
                <option>
                    <id>..</id>
                    <name>...</name>
                </option>
                <option>
...
                </option>
            </options>
        </input-field>

But what if we want to show the list of countries that already exist in SW?

Can we specify the source of the entity so that it can be transformed into the desired format? In Magento 2, we have such an opportunity, does SW support something similar, or is it possible at some stage to substitute the necessary data there so as not to form a permanent list in xml?


Solution

  • You can have a custom component and pass the required entity to it. It's written within the Documentation - There's an example for an Entity single select for products

    Just specify the Entity within <entity> - The entity in this case is called country. You can take a look at the CountryDefinition.

    So a full working example would be:

    <component name="sw-entity-single-select">
        <name>shopwareCountries</name>
        <entity>country</entity>
        <label>Choose a country</label>
    </component>
    

    Example Screen:

    sw-entity-single-select within plugin configuration