API reference
WARNING
Single File Component (SFC) support for Administration extensions is experimental. It is available since Shopware 6.7.16.0. The APIs described on this page can still change without a deprecation. Try it out and tell us what you find, but do not ship an extension built on it to customers or to the Shopware Store until the API is declared stable (planned for 6.9).
Everything a Single File Component in an extension can use. The tutorial introduces these in the order you need them; this section is for looking one up.
Filenames
A .vue file needs no registration call. Its name decides both what the component is called and whether it is a base component or an override.
A base component declares the name. Either layout works:
| File | Declares |
|---|---|
sw-my-component.vue | sw-my-component |
sw-my-component/index.vue | sw-my-component |
An override targets the name, with .override before the extension:
| File | Overrides |
|---|---|
sw-my-component.override.vue | sw-my-component |
sw-my-component/index.override.vue | sw-my-component |
Two base files declaring the same name fail the build. Any number of overrides may target the same component, from any number of plugins. Within one plugin, two overrides of the same component cannot share a directory: both would have to be called sw-my-component.override.vue, because the filename is what names the target. Put them in different directories, for example override/sw-my-component.override.vue and override-demo/sw-my-component.override.vue. In practice one override per component per plugin is almost always enough. See internals for the mechanism.
Every .vue file in an extension is compiled by the Shopware setup transform. It must have a <script setup> block, and that block must declare its role with one of the two macros.
Vue's own macros
Base components are compiled as ordinary <script setup>, so Vue's macros behave as in any Vue 3 project - including prop defaults, reactive destructuring and withDefaults - with the exceptions in this table.
| Macro | Base | Override |
|---|---|---|
defineProps, withDefaults | yes | use useSwProps() |
defineEmits, defineSlots | yes | use useSwContext() |
defineOptions | yes | no |
defineExpose | no, swDefinePublic() generates it | no |
defineModel | no | no |
One Shopware-specific rule in base components: a top-level binding must not share a declared prop's name. The extension runtime strips declared prop keys from the returned state, so the binding is deleted and the template renders undefined. See troubleshooting.
What you never import
| Name | Where it comes from |
|---|---|
swDefinePublic, swDefineOverride | Compile-time macros, like Vue's own defineProps |
useSwPreviousState, useSwProps, useSwContext | Provided by the build in every .override.vue file |
sw-block, sw-block-parent | Globally registered components, resolved by tag name |
$t | Vue global property, available in every template ($t('key', n) for plurals). In <script setup> use useTranslateWithFallback(); a plugin cannot import vue-i18n |
Shopware | The Administration's global object. Read it freely; Shopware is a reserved binding name |
Everything else comes from a shopware:* virtual module - the published composables, plus stores, utilities, mixins and DAL helpers:
import { useNotification } from 'shopware:composables';
import useSwProductDetailStore from 'shopware:stores/swProductDetail';
import { Criteria } from 'shopware:data';
import { createId } from 'shopware:utils';