conneqt / m2-module-sap-base
N/A
Package info
git.dev.epartment.nl/conneqt/m2/module-sap-base
Type:magento2-module
pkg:composer/conneqt/m2-module-sap-base
Requires
- php: >=8.1
- conneqt/m2-base: 1.*
- magento/framework: *
README
What this module does
Conneqt_SapBase is the foundation module for SAP integrations in this Magento 2 codebase.
In short, it:
- stores the SAP connection settings in Magento configuration
- creates and maintains an authenticated SAP HTTP client
- retries login and request calls when SAP rate-limits or expires the session
- caches SAP session cookies between requests
- exposes SAP-related customer and address data on orders through extension attributes
- adds an admin Test Connection button so configuration can be checked from the Magento backend
This module does not contain a full business flow by itself. Instead, it provides the shared SAP connection and order-enrichment pieces that other SAP-related modules can build on.
Packages that use this module
This module is intended to be shared by other SAP-related Magento packages.
Known packages using it include:
conneqt/module-sap-my-accountconneqt/module-sap-service-layer-special-prices
Dependency
This module depends on Conneqt_Base.
See:
composer.jsonetc/module.xml
How it works
1. Configuration is read from Magento admin
The module adds a SAP configuration section in the Magento admin where you can configure:
- SAP base URL
- username and password
- company database
- optional API manager header key/value
- default request timeouts
- login-specific timeouts and retry limits
- cooldown after repeated login failures
- optional proxy settings
- request/response logging
Main files:
etc/adminhtml/system.xml- defines the admin configuration fieldsetc/config.xml- provides default timeout, retry, cooldown, and logging valuesHelper/ScopeConfigHelper.php- reads the configured values for the current store scope
2. A reusable SAP client is created
Helper/SapClient.php is the low-level integration helper.
It is responsible for:
- building the Guzzle client with the configured base URL and headers
- adding the optional proxy configuration
- loading cached SAP cookies into a cookie jar
- logging in when no valid SAP session is available
- saving updated cookies back into Magento cache
- preventing repeated failed logins by storing a temporary cooldown flag
This means the module tries to reuse the SAP session instead of logging in again on every request.
3. API calls go through a wrapper helper
Helper/Api.php wraps the actual GET, POST, and PATCH requests.
This helper:
- uses the shared client from
SapClient - logs requests and responses when logging is enabled
- saves cookies after successful calls
- retries when SAP returns HTTP
429 - tries to log in again when SAP returns HTTP
401
This keeps the SAP request behavior consistent for any module that uses this helper.
4. SAP data is added to order extension attributes
The module extends Magento order and order address data with SAP-specific values.
Exposed order extension attributes:
sap_interncodecard_code
Exposed order address extension attributes:
sap_address_namesap_address_type
Main files:
etc/extension_attributes.xml- declares the extra API attributes on orders and order addressesetc/di.xml- registers plugins onMagento\Sales\Api\OrderRepositoryInterfacePlugin/Order/SapInternCodePlugin.php- copies the customer SAP internal code onto loaded ordersPlugin/Order/CardCodePlugin.php- copies the customer card code onto loaded ordersPlugin/Order/SapAddressPlugin.php- copies SAP address metadata from customer addresses onto order addresses
These plugins run after Magento loads orders from the repository, so API consumers and custom code can read the SAP values from extension attributes.
5. Customer and address attributes are created during setup
The module adds custom EAV attributes used by the plugins.
Customer attributes:
card_codesap_interncode
Customer address attributes:
sap_address_namesap_address_type
Main files:
Setup/Patch/Data/AddCustomerAttributesPatch.php- creates thecard_codecustomer attributeSetup/Patch/Data/AddCustomerInternCodePatch.php- creates thesap_interncodecustomer attributeSetup/Patch/Data/AddAddressAttributesPatch.php- creates the SAP address fields on customer addresses
These attributes are mainly intended for admin-side maintenance and for exposing SAP values on order data after an order is loaded.
6. Admin users can test the connection
The module includes a backend button for testing the current SAP configuration.
How that flow works:
- the system config page renders a custom button
- a small admin JavaScript file sends an AJAX request when the button is clicked
- the controller clears cached config/session state and tries to create a fresh SAP client
- the result is returned as JSON and shown in the admin UI
Main files:
Block/Adminhtml/Config/TestConnectionButton.php- renders the custom config field/buttonview/adminhtml/templates/system/config/test-connection-button.phtml- button markup and Magento init scriptview/adminhtml/web/js/test-connection.js- sends the AJAX request and shows success/error feedbackController/Adminhtml/Config/TestConnection.php- performs the actual connection test and returns JSON
Important files at a glance
composer.json- package metadata and dependency onconneqt/m2-baseregistration.php- registers the Magento moduleetc/module.xml- declares the module and its dependency sequenceetc/adminhtml/system.xml- admin configuration UI for SAP settingsetc/config.xml- default config valuesHelper/ScopeConfigHelper.php- central config lookup helperHelper/SapClient.php- authenticated SAP client, cookie cache, login retry handlingHelper/Api.php- request wrapper with logging and automatic retry/login refreshetc/extension_attributes.xml- declares extra order and order-address attributesetc/di.xml- plugs SAP enrichment into order repository resultsPlugin/Order/*.php- fills order extension attributes with SAP valuesSetup/Patch/Data/*.php- creates customer and address EAV attributes used by the integrationController/Adminhtml/Config/TestConnection.php- admin connection test endpoint
Typical usage in custom code
If another module needs to call SAP, it should usually use:
Conneqt\SapBase\Helper\Apifor request executionConneqt\SapBase\Helper\SapClientonly when low-level client access is needed
If another module needs SAP values on loaded orders, it can read them from the order extension attributes populated by this module.
Notes
- Configuration is store-scoped through
ScopeConfigHelper - SAP cookies and login-failure state are cached in Magento cache
- Logging is optional and can affect performance if many SAP calls are made
- The module is intended as shared infrastructure for SAP integrations, not as a complete end-user feature on its own