Skip to main content

Context

Language

Get current language

Usage:

const language = await sw.context.getLanguage();

Parameters

No parameters needed.

Return value:

Promise<{
languageId: string,
systemLanguageId: string
}>

Example value:

{
languageId: '2fbb5fe2e29a4d70aa5854ce7ce3e20b',
systemLanguageId: '2fbb5fe2e29a4d70aa5854ce7ce3e20b'
}

Subscribe on language changes

Usage:

sw.context.subscribeLanguage(({ languageId, systemLanguageId }) => {
// do something with the callback data
});

Parameters

NameDescription
callbackMethodCalled every-time the language changes

Callback value:

{
languageId: string,
systemLanguageId: string
}

Example callback value:

{
languageId: '2fbb5fe2e29a4d70aa5854ce7ce3e20b',
systemLanguageId: '2fbb5fe2e29a4d70aa5854ce7ce3e20b'
}

Environment

Get current environment

Usage:

const environment = await sw.context.getEnvironment();

Parameters

No parameters needed.

Return value:

Promise<'development' | 'production' | 'testing'>

Example value:

'development'

Locale

Get current locale

Usage:

const locale = await sw.context.getLocale();

Parameters

No parameters needed.

Return value:

Promise<{
locale: string,
fallbackLocale: string
}>

Example value:

{
locale: 'de-DE',
fallbackLocale: 'en-GB'
}

Subscribe on locale changes

Usage:

sw.context.subscribeLocale(({ locale, fallbackLocale }) => {
// do something with the callback data
});

Parameters

NameDescription
callbackMethodCalled every-time the locale changes

Callback value:

{
locale: string,
fallbackLocale: string
}

Example callback value:

{
locale: 'de-DE',
fallbackLocale: 'en-GB'
}

Currency

Get current currency

Usage:

const currency = await sw.context.getCurrency();

Parameters

No parameters needed.

Return value:

Promise<{
systemCurrencyId: string,
systemCurrencyISOCode: string
}>

Example value:

{
systemCurrencyId: 'b7d2554b0ce847cd82f3ac9bd1c0dfca',
systemCurrencyISOCode: 'EUR'
}

Shopware version

Get current Shopware version

Usage:

const shopwareVersion = await sw.context.getShopwareVersion();

Parameters

No parameters needed.

Return value:

string

Example value:

'6.4.0.0'

App information

Get app information

Usage:

const { name, version, type } = await sw.context.getAppInformation();

Parameters

No parameters needed.

Return value:

Promise<{ name: string ; version: string ; type: 'app' | 'plugin' }>

Example value:

{
name: 'my-extension',
version: '1.2.3',
type: 'app'
}

User information

Get user information

caution

Do not use this feature yet. It is not implemented in a Shopware release yet.

Usage:

const userInformation = await sw.context.getUserInformation();

Parameters

No parameters needed.

Return value:

Promise<{
aclRoles: Array<{
name: string,
type: string,
id: string,
privileges: Array<string>,
}>,
active: boolean,
admin: boolean,
avatarId: string,
email: string,
firstName: string,
id: string,
lastName: string,
localeId: string,
title: string,
type: string,
username: string,
}>

Example value:

{
"aclRoles": [],
"active": true,
"admin": true,
"avatarId": "",
"email": "info@shopware.com",
"firstName": "",
"id": "e2a77f4c718d407591b4826222aa3546",
"lastName": "admin",
"localeId": "35bbb8c4305c47ec88b13ab30c0c5c5a",
"title": "",
"type": "user",
"username": "admin"
}

User Timezone

Get user timezone

caution

This feature will be available with Shopware ^6.6.2.0

This feature allows you to get the timezone of the user.

Usage:

const userTimezone = await sw.context.getUserTimezone();

Parameters

No parameters needed.

Return value:

Promise<string>

This function returns a Promise that resolves to a string representing the user's timezone.

Module information

Get module information

Get information about all registered modules. These modules are created by adding new menu items, setting items, etc.

The ID can be used to change the current route to the module.

Usage:

const { modules } = await sw.context.getModuleInformation();

sw.window.routerPush({
name: 'sw.extension.sdk.index',
params: {
id: modules[0].id // get the ID of the wanted module
}
})

Parameters

No parameters needed.

Return value:

Promise<{
modules: Array<{
displaySearchBar: boolean,
heading: string,
id: string,
locationId: string
}>
}}>

Example value:

{
modules: [
{
displaySearchBar: true,
heading: 'My module',
id: 'sd5aasfsdfas',
locationId: 'my-location-id'
}
]
}