Skip to main content
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.
id
string
required
Unique identifier for the dataset to subscribe to
callback
function
required
Callback function that receives data updates
(data: {id: string, data: unknown}) => void | Promise<unknown>
options
object
Optional configuration for the subscription
options.selectors
string[]
Array of field selectors to filter which data fields trigger updates
unsubscribe
function
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();

get()

Request data from a registered dataset.
id
string
required
Unique identifier for the dataset to retrieve
data
unknown
Optional data to pass with the request
selectors
string[]
Array of field selectors to specify which fields to retrieve
response
Promise<unknown>
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.
id
string
required
Unique identifier for the dataset to update
data
unknown
required
The new data to update the dataset with
response
Promise<void>
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.

Entity

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);
});

Build docs developers (and LLMs) love