Access & Extension
ConnectorSessionService
The ConnectorSessionService is the central access point for the ConnectorSession in PHP code. It can be obtained via dependency injection.
| Method | Return | Description |
|---|---|---|
has() | bool | Checks whether an active session currently exists |
get() | ConnectorSession|null | Returns the current session, or null if none exists |
set(ConnectorSession) | void | Stores a session (overwrites any existing one) |
clear() | void | Deletes the current session |
putAdditionalField(string $key, mixed $value) | void | Adds 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:
| Variable | Available on |
|---|---|
agiqonConnectorSession | Header, cart, offcanvas cart, listing, product page |
agiqonConnectorIsCxmlInspect | Header |
agiqonConnectorShowAccount | Header (OCI only) |
agiqonConnectorPunchoutLevel2 | Listing, 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 class | Event name | When |
|---|---|---|
ConnectorSessionLoginEvent | agiqon_connector.connector_session.login | After successful login |
ConnectorSessionLogoutEvent | agiqon_connector.connector_session.logout | On logout (generic) |
OciSessionLogoutEvent | agiqon_connector.connector_session.logout | On logout of an OCI session |
CxmlSessionLogoutEvent | agiqon_connector.connector_session.logout | On logout of a cXML session |
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 parameter | Description |
|---|---|
varUserName (configured) | Username |
varPassword (configured) | Password |
varToken (configured) | Token |
varUrl (configured) | Hook URL |
function | OCI 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:
| Key | Type | Source |
|---|---|---|
buyerCookie | string | PunchOutSetupRequest > BuyerCookie |
operation | string | @operation attribute on PunchOutSetupRequest (create, edit, inspect) |
cxmlString | string | Full login XML string |
isPunchoutLevel2 | bool | System configuration |
systemAutoIncrement | int | System 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 |