The data module provides methods for extensions to access and manage data in the Shopware Administration.
Methods
subscribe()
Subscribe to dataset changes and receive updates when data changes.
Unique identifier for the dataset to subscribe to
Callback function that receives data updates(data: {id: string, data: unknown}) => void | Promise<unknown>
Optional configuration for the subscriptionArray of field selectors to filter which data fields trigger updates
Returns an unsubscribe function to stop receiving updates
Example
import { data } from '@shopware-ag/admin-sdk';
// Subscribe to product data changes
const unsubscribe = data.subscribe(
'product-detail',
(response) => {
console.log('Product updated:', response.data);
},
{
selectors: ['name', 'price', 'stock']
}
);
// Unsubscribe when done
unsubscribe();
Request data from a registered dataset.
Unique identifier for the dataset to retrieve
Optional data to pass with the request
Array of field selectors to specify which fields to retrieve
Returns a promise that resolves with the requested data
Example
import { data } from '@shopware-ag/admin-sdk';
// Get current product data
const productData = await data.get('product-detail', {
selectors: ['name', 'description', 'price']
});
console.log('Product:', productData);
update()
Update data in a registered dataset.
Unique identifier for the dataset to update
The new data to update the dataset with
Returns a promise that resolves when the update is complete
Example
import { data } from '@shopware-ag/admin-sdk';
// Update product data
await data.update('product-detail', {
name: 'Updated Product Name',
price: 29.99
});
Classes
The data module exports utility classes for data manipulation:
Criteria
Build search criteria for querying entities. See Repository for usage.
Represents a single entity with change tracking and state management.
EntityCollection
Represents a collection of entities returned from search operations.
Type Definitions
datasetSubscribe
type datasetSubscribe = {
responseType: unknown,
id: string,
data: unknown,
selectors?: string[],
}
datasetGet
type datasetGet = {
responseType: unknown,
id: string,
data?: unknown,
selectors?: string[],
}
datasetUpdate
type datasetUpdate = {
responseType: unknown,
id: string,
data: unknown,
}
Best Practices
Always unsubscribe from datasets when your component unmounts to prevent memory leaks.
The subscribe method automatically sends a registration message to the admin. Make sure the dataset ID exists before subscribing.
Error Handling
import { data } from '@shopware-ag/admin-sdk';
data.subscribe('my-dataset', (response) => {
// Check for privilege errors
if (response.data instanceof MissingPrivilegesError) {
console.error('Missing privileges:', response.data);
return;
}
// Handle data normally
console.log('Data:', response.data);
});