Overview
The Context API provides methods to access information about the Shopware environment, user session, language settings, and app configuration. All context methods are exposed through the SDK and use the underlying message passing system.Available Context Methods
The Context API is implemented incontext/index.ts and provides several methods:
Language and Locale
Get Language
Retrieve the current content language IDs:Subscribe to Language Changes
Get Locale
Retrieve UI locale information:Subscribe to Locale Changes
User Information
Get User Information
Access detailed information about the current admin user:Get User Timezone
Environment Information
Get Environment
Determine the current environment:Get Shopware Version
Compare Shopware Version
Check if the current Shopware version meets requirements:'>', '>=', '<', '<=', '=', '==', '==='
App Information
Get App Information
Access metadata about your app:Check Privileges
Thecan helper simplifies privilege checking:
Module Information
Get Module Information
Retrieve information about registered modules:Currency and Shop
Get Currency
Retrieve system currency information:Get Shop ID
Retrieve the current shop context ID (useful for multi-shop setups):Practical Examples
Initialize App with Context
Localized UI
Conditional Features Based on Privileges
Implementation Details
All context methods use the channel communication system:send and subscribe functions from the channel module.
Best Practices
1. Cache Context Data
2. Handle Context Changes
Subscribe to changes for dynamic data like language:3. Validate Version Requirements Early
4. Check Privileges Before Actions
Next Steps
- Learn about Architecture for message passing details
- Explore Data Handling for working with entities
- Understand Location Module for iframe management