Skip to main content

Access & Extension

ConnectorSessionService

The ConnectorSessionService is the central access point for the ConnectorSession in PHP code. It can be obtained via dependency injection.

MethodReturnDescription
has()boolChecks whether an active session currently exists
get()ConnectorSession|nullReturns the current session, or null if none exists
set(ConnectorSession)voidStores a session (overwrites any existing one)
clear()voidDeletes the current session
putAdditionalField(string $key, mixed $value)voidAdds an additionalField to the current session (creates an empty session if needed)

Example:

public function __construct(
private readonly ConnectorSessionService $connectorSessionService
) {}

public function doSomething(): void
{
if (!$this->connectorSessionService->has()) {
return;
}

$session = $this->connectorSessionService->get();

$hookUrl = $session->getHookUrl();
$systemType = $session->getSystemType(); // ConnectorSystemType::OCI or ::cXML
}

Extending additionalFields

additionalFields are freely definable key-value pairs carried over from the transmission. They can be extended at any time via the ConnectorSessionService — the most natural place is a ConnectorSessionLoginEvent listener:

use AgiqonConnector\Connector\Event\ConnectorSessionLoginEvent;
use AgiqonConnector\Connector\Service\ConnectorSessionService;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(event: ConnectorSessionLoginEvent::EVENT_NAME)]
final class MySessionLoginListener
{
public function __construct(
private readonly ConnectorSessionService $connectorSessionService
) {}

public function __invoke(ConnectorSessionLoginEvent $event): void
{
// Add a custom field to the session
$this->connectorSessionService->putAdditionalField(
'myCustomKey',
'myCustomValue'
);
}
}

The field is then accessible via $session->getAdditionalField('myCustomKey').


Access in Twig templates

Once a connector session is active, the StorefrontSessionSubscriber provides the session as a template variable:

VariableAvailable on
agiqonConnectorSessionHeader, cart, offcanvas cart, listing, product page
agiqonConnectorIsCxmlInspectHeader
agiqonConnectorShowAccountHeader (OCI only)
agiqonConnectorPunchoutLevel2Listing, product page

Example in Twig:

{% if agiqonConnectorSession %}
<p>Active system: {{ agiqonConnectorSession.system }}</p>
<p>System type: {{ agiqonConnectorSession.systemType.value }}</p>
{% endif %}

Events

The session fires events at defined points in its lifecycle. These can be used to hook in custom logic.

Event classEvent nameWhen
ConnectorSessionLoginEventagiqon_connector.connector_session.loginAfter successful login
ConnectorSessionLogoutEventagiqon_connector.connector_session.logoutOn logout (generic)
OciSessionLogoutEventagiqon_connector.connector_session.logoutOn logout of an OCI session
CxmlSessionLogoutEventagiqon_connector.connector_session.logoutOn logout of a cXML session
info

OciSessionLogoutEvent and CxmlSessionLogoutEvent extend ConnectorSessionLogoutEvent and are fired under the same event name. A listener on ConnectorSessionLogoutEvent receives all logout events; a listener on OciSessionLogoutEvent receives only OCI-specific ones.

All events provide: getConnectorSession(), getSalesChannelContext(), getRequest(). The logout event additionally provides isTransferred(): bool.


Pre-populated additionalFields

During login the connector automatically populates additionalFields with protocol-specific data. These are available throughout the entire session.

OCI

All GET or POST parameters of the login request are stored in additionalFields with lowercased keys. Excluded are the configured login parameters and function, as they are consumed by the login process itself:

Excluded parameterDescription
varUserName (configured)Username
varPassword (configured)Password
varToken (configured)Token
varUrl (configured)Hook URL
functionOCI function parameter

All other parameters sent by the procurement system (e.g. language, cost center, order number) land directly in additionalFields and can be retrieved via $session->getAdditionalField('paramName').

cXML

During cXML login, the following fields are populated automatically:

Fixed fields:

KeyTypeSource
buyerCookiestringPunchOutSetupRequest > BuyerCookie
operationstring@operation attribute on PunchOutSetupRequest (create, edit, inspect)
cxmlStringstringFull login XML string
isPunchoutLevel2boolSystem configuration
systemAutoIncrementintSystem number from the login URL

Extrinsic user identity fields (only when present in the PunchOutSetupRequest):

Key
UserEmail
FirstName
LastName
UserPrintableName
UserFullName
UniqueName
UniqueUsername
User
UserId
UserPhoneNumber
PhoneNumber