Overview
What is a DataField?
A DataField is a resolvable field that provides a single data value for transmission to a procurement system (e.g. item number, price, quantity). Each DataField has:
- a technical name (
technicalName) – used to reference it in the connector configuration, - a list of available systems (
availableSystems) – determines for which system types (OCI, cXML) the field can be selected, - a
resolve()method – receives aDataFieldResolutionContextand returns astringornull.
All DataFields extend AbstractDataField:
abstract readonly class AbstractDataField
{
public function __construct(
private string $technicalName,
private array $availableSystems = []
) {}
abstract public function resolve(DataFieldResolutionContext $context): ?string;
}
DataField Types
Every DataField belongs to a type. The type determines which context data the field reads its value from and is set via the PHP attribute #[DataFieldTypeAttribute(...)] on the field class.
The connector ships with the following built-in types:
| Type value | Enum case | Description |
|---|---|---|
context | DataFieldType::Context | General Sales Channel context data (language, currency, etc.) |
line_item | DataFieldType::LineItem | Cart line item data (quantity, reference, price) |
product | DataFieldType::Product | Product catalog data (item number, name, EAN, …) |
shipping | DataFieldType::Shipping | Shipping data (shipping method) |
session | DataFieldType::Session | Data from the current connector session |
system | DataFieldType::System | Data from the configured connector system |
customized_product | DataFieldType::CustomizedProduct | Data for configurable products (Shopware Customized Products) |
Custom types can be added – see Adding a Custom DataField Type.
DataFieldResolutionContext
When resolving a DataField, a DataFieldResolutionContext is passed in. It holds all data that might be needed to determine the value:
| Getter | Type | Always available? | Description |
|---|---|---|---|
getSalesChannelContext() | SalesChannelContext | ✅ yes | The Sales Channel context |
getProduct() | ProductEntity|null | Only for product fields | The resolved product entity |
getLineItem() | LineItem|null | Only for line item fields | The cart line item |
getShippingMethod() | ShippingMethodEntity|null | Only for shipping fields | The shipping method |
getCart() | Cart|null | Optional | The current cart |
getSession() | ConnectorSession|null | Optional | The connector session |
getSystem() | ConnectorSystemEntity|null | Optional | The connector system |
getCustomFieldKey() | string|null | Only for custom field fields | The Shopware custom field key |
Which properties are populated depends on the transmission context. A DataField should always check for null before accessing optional properties.