### Get Scheduler Information
Source: https://context7.com/magesuite/erp-connector/llms.txt
Retrieves available scheduler types and their corresponding processors. It can also fetch a specific provider processor based on scheduler type and provider code.
```php
// Get available scheduler types and their processors
$schedulerTypes = $this->schedulersPool->getSchedulersByType('general');
// Returns: ['general' => ['label' => 'General', 'code' => 'general', 'class' => ...]]
// Get the processor for a specific scheduler type and provider code
$providerProcessor = $this->schedulersPool->getProviderProcessorBySchedulerTypeAndProviderCode(
'order_export', // Scheduler type
'sap-erp' // Provider code
);
```
--------------------------------
### Custom Provider Processor Implementation
Source: https://context7.com/magesuite/erp-connector/llms.txt
Example of a custom provider processor implementation for handling order exports. It defines how to retrieve orders, prepare items, and send them using a connector client.
```php
// Custom provider processor implementation
// In di.xml:
//
//
//
// -
//
- Vendor\Module\Model\Processor\SapOrderExport
// - Vendor\Module\Model\Processor\GenericOrderExport
//
//
//
//
// Custom processor implementation
class SapOrderExport extends \MageSuite\ErpConnector\Model\ProviderProcessor\ProviderProcessor
implements \MageSuite\ErpConnector\Model\ProviderProcessor\ProviderProcessorInterface
{
public function execute()
{
$provider = $this->getProvider();
$scheduler = $this->scheduler;
// Get orders to export based on scheduler configuration
$orders = $this->getOrdersForExport($scheduler);
// Prepare items for the connector
$items = [];
foreach ($orders as $order) {
$items[] = [
'files' => [
'order_' . $order->getIncrementId() . '.xml' => $this->generateOrderXml($order)
]
];
}
// Get connector and send items
$connectors = $this->connectorRepository->getByProviderId($provider->getId());
foreach ($connectors as $connector) {
$client = $connector->getClient();
$client->sendItems($provider, $items);
}
return true;
}
}
```
--------------------------------
### Retrieve and Use Decrypted Credential
Source: https://context7.com/magesuite/erp-connector/llms.txt
Retrieves a decrypted credential by its identifier and demonstrates its use in configuring an HTTP client for API requests. Includes an example of deleting a vault item.
```php
// Retrieve decrypted value by identifier
$decryptedToken = $this->vaultRepository->getDecryptedValueByIdentifier('sap_api_token');
// Returns the original unencrypted value
// Use in connector configuration
$httpClient = $this->httpClientFactory->create([
'data' => [
'url' => 'https://api.sap.com/orders',
'request_method' => 'POST',
'authorization_bearer' => $this->vaultRepository->getDecryptedValueByIdentifier('sap_api_token'),
'content_type' => 'application/json'
]
]);
// Delete vault item
$this->vaultRepository->deleteById('sap_api_token');
```
--------------------------------
### Configure and Use FTP Client
Source: https://context7.com/magesuite/erp-connector/llms.txt
Demonstrates how to instantiate, configure, and use the FTP client for uploading and downloading files. Includes connection checking and error handling.
```php
connectorRepository->getById($connectorId);
$ftpClient = $connector->getClient(); // Returns configured Ftp instance
// Or create manually with configuration
$ftpClient = $this->ftpFactory->create([
'data' => [
'host' => 'ftp.erp-server.com',
'port' => 21,
'username' => 'magento_ftp',
'password' => 'secure_password',
'passive_mode' => true,
'source_dir' => '/incoming',
'destination_dir' => '/processed',
'rename_moved_file' => true,
'skip_validation' => false,
'file_name_pattern' => '/^order_.*\.xml$/'
]
]);
// Check connection before operations
try {
$ftpClient->checkConnection();
echo "FTP connection successful";
} catch (\
MageSuite\ErpConnector\Exception\RemoteExportFailed $e) {
echo "Connection failed: " . $e->getMessage();
}
// Send files to FTP server
$provider = $this->providerRepository->getById(1);
$items = [
[
'files' => [
'order_12345.xml' => '12345',
'order_12346.xml' => '12346'
]
]
];
try {
$ftpClient->sendItems($provider, $items);
echo "Files uploaded successfully";
} catch (\
MageSuite\ErpConnector\Exception\RemoteExportFailed $e) {
echo "Upload failed: " . $e->getMessage();
}
// Download files from FTP server
try {
$downloadedFiles = $ftpClient->downloadItems($provider);
// Files are automatically moved to destination_dir after download
foreach ($downloadedFiles as $fileName => $content) {
echo "Downloaded: $fileName (" . strlen($content) . " bytes)" . PHP_EOL;
// Process the file content...
}
} catch (\
MageSuite\ErpConnector\Exception\MissingDownloadData $e) {
echo "No files to download: " . $e->getMessage();
}
// Validate a specific file exists in destination
$exists = $ftpClient->validateProcessedFile('order_12345.xml');
```
--------------------------------
### Configure and Use SFTP Client
Source: https://context7.com/magesuite/erp-connector/llms.txt
Shows how to set up and utilize the SFTP client for secure file transfers, including proxy support and date-based directory structures. Demonstrates connection testing, file uploads, and downloads.
```php
sftpFactory->create([
'data' => [
'host' => 'sftp.erp-server.com',
'username' => 'magento_sftp',
'password' => 'secure_password',
'timeout' => 30,
'source_dir' => '/data/outbound/{Y}/{m}', // Supports date placeholders
'destination_dir' => '/data/archive/{Y}/{m}',
'rename_moved_file' => true,
'skip_validation' => false,
'use_proxy' => true, // Enable proxy connection
'allowed_files' => ['orders.xml', 'inventory.xml'],
'file_name_pattern' => '/\.xml$/'
]
]);
// Test SFTP connection
try {
$sftpClient->checkConnection();
} catch (\
MageSuite\ErpConnector\Exception\RemoteExportFailed $e) {
// Directory not found or connection failed
$this->logger->error('SFTP connection error: ' . $e->getMessage());
}
// Send inventory update files
$provider = $this->providerRepository->getByCode('erp-inventory');
$inventoryData = [
[
'files' => [
'inventory_update.xml' => $this->generateInventoryXml($products)
]
]
];
try {
$sftpClient->sendItems($provider, $inventoryData);
} catch (\
MageSuite\ErpConnector\Exception\RemoteExportFailed $e) {
// File already exists, upload failed, or validation error
throw $e;
}
// Download and process incoming files
try {
$files = $sftpClient->downloadItems($provider);
foreach ($files as $fileName => $xmlContent) {
// Validate file name pattern
if ($sftpClient->isValidFileName($fileName)) {
$this->processIncomingFile($fileName, $xmlContent);
}
}
} catch (\
MageSuite\ErpConnector\Exception\RemoteImportFailed $e) {
// File move operation failed
$this->logger->critical($e->getMessage());
}
// Get raw SFTP connection for advanced operations
$connection = $sftpClient->getConnection();
$connection->cd('/custom/directory');
$fileList = $connection->ls();
$sftpClient->closeConnection($connection);
```
--------------------------------
### Manage Connector Configurations in PHP
Source: https://context7.com/magesuite/erp-connector/llms.txt
Demonstrates creating an SFTP connector, assigning connection parameters, and retrieving configuration values.
```php
connectorFactory->create();
$connector->setProviderId(1)
->setName('Order Export SFTP')
->setType('sftp'); // Options: ftp, sftp, http, soap, email
$savedConnector = $this->connectorRepository->save($connector);
// Configure the SFTP connection parameters
$configurations = [
'host' => 'sftp.erp-system.com',
'username' => 'magento_user',
'password' => 'secure_password',
'timeout' => 30,
'source_dir' => '/outbound/orders',
'destination_dir' => '/outbound/processed',
'rename_moved_file' => true,
'skip_validation' => false,
'use_proxy' => false
];
foreach ($configurations as $name => $value) {
$config = $this->configFactory->create();
$config->setConnectorId($savedConnector->getId())
->setName($name)
->setValue($value);
$this->configRepository->save($config);
}
// Retrieve connectors for a provider
$connectors = $this->connectorRepository->getByProviderId(1);
foreach ($connectors as $connector) {
echo "Connector: " . $connector->getName() . " (Type: " . $connector->getType() . ")" . PHP_EOL;
// Get configured client with all parameters loaded
$client = $connector->getClient();
echo "Host: " . $client->getData('host') . PHP_EOL;
}
// Get specific configuration value
$hostConfig = $this->configRepository->getItemByConnectorIdAndName(
$savedConnector->getId(),
'host'
);
echo $hostConfig->getValue(); // "sftp.erp-system.com"
```
--------------------------------
### Configure and Use HTTP Client for REST API
Source: https://context7.com/magesuite/erp-connector/llms.txt
Demonstrates configuring the HTTP client, sending order data, and downloading items from an ERP system.
```php
httpClientFactory->create([
'data' => [
'url' => 'https://api.erp-system.com/v1/orders',
'request_method' => 'POST', // GET, POST, PUT, DELETE
'content_type' => 'application/json',
'login' => 'api_user', // For Basic Auth
'password' => 'api_password',
'authorization_bearer' => null, // Or use Bearer token instead
'timeout' => 60,
'custom_headers' => [
'custom_headers' => [
['key' => 'X-API-Version', 'value' => '2.0'],
['key' => 'X-Client-Id', 'value' => 'magento-store-1']
]
]
]
]);
// Send order data to REST API
$provider = $this->providerRepository->getById(1);
$orderData = [
[
'files' => [
'order_batch.json' => json_encode([
'orders' => [
['order_id' => '100001', 'total' => 150.00],
['order_id' => '100002', 'total' => 275.50]
]
])
]
]
];
try {
$responseContent = $httpClient->sendItems($provider, $orderData);
$response = json_decode($responseContent, true);
if ($response['status'] === 'success') {
echo "Orders submitted successfully";
}
} catch (\MageSuite\ErpConnector\Exception\RemoteExportFailed $e) {
echo "API Error: " . $e->getMessage();
}
// Download data from REST API
try {
$downloadedData = $httpClient->downloadItems($provider);
// Key is the URL, value is the response body
foreach ($downloadedData as $url => $content) {
$data = json_decode($content, true);
$this->processApiResponse($data);
}
} catch (\MageSuite\ErpConnector\Exception\MissingDownloadData $e) {
echo "No data received from API";
}
// Using Bearer token authentication
$httpClientWithBearer = $this->httpClientFactory->create([
'data' => [
'url' => 'https://api.erp-system.com/v1/inventory',
'request_method' => 'GET',
'content_type' => 'application/json',
'authorization_bearer' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
'timeout' => 30
]
]);
```
--------------------------------
### Configure and Use SOAP Client
Source: https://context7.com/magesuite/erp-connector/llms.txt
Configure a SOAP client for WSDL-based integration with legacy ERP systems. Supports connection checking, sending data, and downloading data with specific parameters.
```php
soapClientFactory->create([
'data' => [
'wsdl' => 'https://erp.company.com/api/soap?wsdl',
'location' => 'https://erp.company.com/api/soap',
'action' => 'CreateOrder',
'version' => SOAP_1_2, // SOAP_1_1 or SOAP_1_2
'login' => 'soap_user',
'password' => 'soap_password',
'use_proxy' => false,
'parameters' => [
'parameters' => [
['key' => 'companyCode', 'value' => 'STORE01'],
['key' => 'warehouse', 'value' => 'WH-MAIN']
]
]
]
]);
// Check SOAP connection
try {
$soapClient->checkConnection();
echo "SOAP API connection verified";
} catch (\MageSuite\ErpConnector\Exception\ConnectionFailed $e) {
echo "Cannot connect to SOAP service: " . $e->getMessage();
}
// Send SOAP envelope for order creation
$provider = $this->providerRepository->getById(1);
$soapEnvelope = <<
100001
CUST123
- PROD-0012
XML;
$items = [
['files' => ['order_100001.xml' => $soapEnvelope]]
];
try {
$soapClient->sendItems($provider, $items);
} catch (\MageSuite\ErpConnector\Exception\RemoteExportFailed $e) {
// SOAP fault or response error
echo "SOAP Error: " . $e->getMessage();
}
// Download data using SOAP call with parameters
$soapClientForDownload = $this->soapClientFactory->create([
'data' => [
'wsdl' => 'https://erp.company.com/api/soap?wsdl',
'action' => 'GetInventoryLevels',
'version' => SOAP_1_2,
'login' => 'soap_user',
'password' => 'soap_password',
'parameters' => [
'parameters' => [
['key' => 'warehouseCode', 'value' => 'WH-MAIN'],
['key' => 'lastSyncDate', 'value' => '2024-01-01']
]
]
]
]);
try {
$results = $soapClientForDownload->downloadItems($provider);
// Key is action name, value is the response result
$inventoryData = $results['GetInventoryLevels'];
// Returns GetInventoryLevelsResult from SOAP response
} catch (\MageSuite\ErpConnector\Exception\MissingDownloadData $e) {
echo "No inventory data returned";
}
```
--------------------------------
### Manage Scheduler Tasks in PHP
Source: https://context7.com/magesuite/erp-connector/llms.txt
Shows how to define a cron-based scheduler with templates and retrieve existing schedules.
```php
schedulerFactory->create();
$scheduler->setProviderId(1)
->setName('Daily Order Export')
->setType('order_export') // Custom type defined in your implementation
->setCronExpression('10 03 * * *')
->setFileName('orders_{date}.xml')
->setTemplates([
'order' => 'MageSuite_ErpConnector::templates/order.phtml',
'item' => 'MageSuite_ErpConnector::templates/order_item.phtml'
]);
try {
$savedScheduler = $this->schedulerRepository->save($scheduler);
echo "Scheduler created with ID: " . $savedScheduler->getId();
} catch (\Magento\Framework\Exception\CouldNotSaveException $e) {
echo "Error: " . $e->getMessage();
}
// Retrieve schedulers
$scheduler = $this->schedulerRepository->getById(1);
$scheduler = $this->schedulerRepository->getByProviderId(1);
$scheduler = $this->schedulerRepository->getByProviderIdAndType(1, 'order_export');
// Get all schedulers
$schedulerList = $this->schedulerRepository->getList();
foreach ($schedulerList->getItems() as $scheduler) {
echo sprintf(
"Scheduler: %s | Cron: %s | Type: %s" . PHP_EOL,
$scheduler->getName(),
$scheduler->getCronExpression(),
$scheduler->getType()
);
}
// Access scheduler templates
$templates = $scheduler->getTemplates();
// Returns: ['order' => '...', 'item' => '...']
```
--------------------------------
### Accessing ERP Connector Configuration
Source: https://context7.com/magesuite/erp-connector/llms.txt
Inject the Configuration helper to access module settings, proxy configurations, and email sender details.
```php
configuration->isEnabled()) {
// Proceed with ERP operations
}
// Get SFTP proxy configuration
$sftpProxy = $this->configuration->getSftpConnectorProxy();
// Returns: ['host' => 'proxy.company.com', 'port' => '1080']
// Get HTTP proxy for REST API calls
$httpProxy = $this->configuration->getHttpConnectorProxy();
// Returns: 'http://proxy.company.com:8080'
// Get SOAP proxy settings
$soapProxyHost = $this->configuration->getSoapConnectorProxyHost();
$soapProxyPort = $this->configuration->getSoapConnectorProxyPort();
// Get email sender information for notifications
$senderInfo = $this->configuration->getEmailSenderInfo();
// Returns: ['name' => 'Store Name', 'email' => 'store@example.com']
// Get provider additional configuration codes
$configCodes = $this->configuration->getProviderAdditionalConfigurationCodes();
// Returns array of custom configuration codes defined in admin
// System configuration paths (for use in system.xml):
// erp_connector/general/is_enabled
// erp_connector/general/provider_configuration_codes
// erp_connector/connector/sftp_proxy_host
// erp_connector/connector/sftp_proxy_port
// erp_connector/connector/http_proxy
// erp_connector/connector/soap_proxy_host
// erp_connector/connector/soap_proxy_port
```
--------------------------------
### Configure and Use Email Client
Source: https://context7.com/magesuite/erp-connector/llms.txt
Configure an Email client for sending data via email with attachments. Supports integration with Magento's transactional email templates and multiple recipients.
```php
emailClientFactory->create([
'data' => [
'email' => 'orders@erp-system.com,backup-orders@erp-system.com',
'template' => 'erp_connector_order_export_email' // Magento email template ID
]
]);
// Prepare order export with attachment
$order = $this->orderRepository->get(100001);
$orderXml = $this->orderExportService->generateXml($order);
$items = [
[
'order' => $order, // Required: Magento order object
'files' => [
'order_100001.xml' => $orderXml
]
],
[
'order' => $anotherOrder,
'files' => [
'order_100002.xml' => $this->orderExportService->generateXml($anotherOrder),
'order_100002.json' => json_encode($anotherOrder->getData())
]
]
];
$provider = $this->providerRepository->getById(1);
try {
$emailClient->sendItems($provider, $items);
echo "Order export emails sent successfully";
} catch (\Exception $e) {
echo "Email sending failed: " . $e->getMessage();
}
// Email template variables available in the template:
// - {{ var file_name }} - Name of the first attached file
// - {{ var provider.getName() }} - Provider name
// - {{ var order.getIncrementId() }} - Order increment ID
// - {{ var order }} - Full order object for custom template logic
```
--------------------------------
### Manage ERP Providers with ProviderRepositoryInterface
Source: https://context7.com/magesuite/erp-connector/llms.txt
Use the ProviderRepositoryInterface for CRUD operations on ERP provider configurations. Inject the repository and factory via constructor dependency injection. Handle potential exceptions like CouldNotSaveException and NoSuchEntityException.
```php
providerFactory->create();
$provider->setName('SAP ERP Integration')
->setCode('sap-erp')
->setEmail('erp-alerts@example.com');
try {
$savedProvider = $this->providerRepository->save($provider);
echo "Provider saved with ID: " . $savedProvider->getId();
} catch (\Magento\Framework\Exception\CouldNotSaveException $e) {
echo "Error saving provider: " . $e->getMessage();
}
// Retrieve provider by ID
try {
$provider = $this->providerRepository->getById(1);
echo $provider->getName(); // "SAP ERP Integration"
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
echo "Provider not found";
}
// Retrieve provider by name
$provider = $this->providerRepository->getByName('SAP ERP Integration');
// Get all providers with search criteria
$searchCriteriaBuilder = $this->searchCriteriaBuilder
->addFilter('code', 'sap%', 'like')
->create();
$providerList = $this->providerRepository->getList($searchCriteriaBuilder);
foreach ($providerList->getItems() as $provider) {
echo $provider->getCode() . ': ' . $provider->getName() . PHP_EOL;
}
// Delete provider
$this->providerRepository->deleteById(1);
```
--------------------------------
### Execute Scheduler Processor
Source: https://context7.com/magesuite/erp-connector/llms.txt
Typically invoked by cron jobs, this service can also be called programmatically for testing or manual execution. It executes a specific scheduler by its ID.
```php
schedulerProcessor->execute($schedulerId);
```
--------------------------------
### Store Sensitive Credential
Source: https://context7.com/magesuite/erp-connector/llms.txt
Stores a sensitive credential securely using the Vault Repository. The value is automatically encrypted before storage. Handles potential exceptions during the save operation.
```php
vaultItemFactory->create();
$vaultItem->setIdentifier('sap_api_token')
->setValue('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...');
try {
$this->vaultRepository->save($vaultItem);
// Value is automatically encrypted before storage
echo "Credential stored securely";
} catch (\Magento\Framework\Exception\LocalizedException $e) {
echo "Error storing credential: " . $e->getMessage();
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.