Skip to main content

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 a DataFieldResolutionContext and returns a string or null.

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 valueEnum caseDescription
contextDataFieldType::ContextGeneral Sales Channel context data (language, currency, etc.)
line_itemDataFieldType::LineItemCart line item data (quantity, reference, price)
productDataFieldType::ProductProduct catalog data (item number, name, EAN, …)
shippingDataFieldType::ShippingShipping data (shipping method)
sessionDataFieldType::SessionData from the current connector session
systemDataFieldType::SystemData from the configured connector system
customized_productDataFieldType::CustomizedProductData 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:

GetterTypeAlways available?Description
getSalesChannelContext()SalesChannelContext✅ yesThe Sales Channel context
getProduct()ProductEntity|nullOnly for product fieldsThe resolved product entity
getLineItem()LineItem|nullOnly for line item fieldsThe cart line item
getShippingMethod()ShippingMethodEntity|nullOnly for shipping fieldsThe shipping method
getCart()Cart|nullOptionalThe current cart
getSession()ConnectorSession|nullOptionalThe connector session
getSystem()ConnectorSystemEntity|nullOptionalThe connector system
getCustomFieldKey()string|nullOnly for custom field fieldsThe Shopware custom field key

Which properties are populated depends on the transmission context. A DataField should always check for null before accessing optional properties.