StyleMan Connector - Customer Update
This document describes the customer update functionality of the StyleMan connector. The connector processes incoming customer data from App4Sales to update existing customer, address, and contact records in the StyleMan ERP system. Important: This functionality does NOT support the creation of new customers; it is strictly for updating existing records.
Trigger & Permissions
The customer update flow is triggered when the `OptA4SNewCustomers` method is invoked. This method is enabled only if the 'Edit Customer' feature is active within the connector settings, corresponding to `Constants.ConnectorInfoInternalIds.EditCustomer`. The incoming request is expected to contain customer data in an XML payload format.
Data Source Configuration
Customer data for updates is retrieved from an XML payload embedded within the `InternalRequest` object. The `XMLParserObj.GetCustomersFromRequest(request)` method is responsible for parsing this XML into `XmlCustomer` objects. The XML structure is expected to contain fields that map to the properties listed in the payload mapping tables below.
Payload Mapping: Customer
App4Sales Field (`RestJson.Shared.Customer`) | Source Field (`XmlCustomer`) | Logic/Notes |
Id | CustomerGuid | Unique identifier for the customer. |
Code | CustomerCode | The customer's unique code. This field is mandatory for updates; new customer creation is not supported if this field is empty. |
ChamberOfCommerceCode | ChamberOfCommerceCode | Chamber of Commerce registration number. |
Discount | Discount | The discount percentage for the customer. String value is parsed to a decimal; defaults to 0 if parsing fails. |
LanguageCode | LanguageCode | The preferred language code for the customer (e.g., 'en', 'nl'). |
Name | CustomerName | The full name of the customer. |
VatCode | VatCode | The VAT code applicable to the customer. |
VatLiable | VatLiable | Indicates whether the customer is VAT liable. |
The primary email address of the customer. | ||
Phone | Phone | The primary phone number of the customer. |
Addresses | N/A | Addresses are handled via a separate update call; this field is not populated directly during the customer update. |
Contacts | N/A | Contacts are handled via a separate update call; this field is not populated directly during the customer update. |
Payload Mapping: Address
App4Sales Field (`AddressSales`) | Source Field (`XmlCustomer`) | Logic/Notes |
Id | Derived | Initially generated as a new GUID. This ID is then overwritten by `UpdateAddressId` if an existing main delivery address is found for the customer in the App4Sales database. The retrieved ID is prefixed with "del" and "vis". |
AddressLine1 | DeliveryAddress1 | First line of the delivery address. |
AddressLine2 | DeliveryAddress2 | Second line of the delivery address. |
City | DeliveryCity | City of the delivery address. |
CountryCode | CountryCode | Country code of the delivery address. |
Customer | CustomerGuid | The GUID of the customer associated with this address. |
IsMainAddress | Hardcoded | Hardcoded to `true`, indicating this is a main address. |
PostalCode | DeliveryPostCode | Postal code of the delivery address. |
Type | Hardcoded | Hardcoded to "del", indicating a delivery address. |
Payload Mapping: Contact Person
App4Sales Field (`RestJsonContact`) | Source Field (`XmlCustomer`) | Logic/Notes |
Id | Derived | Initially generated as a new GUID. This ID is then overwritten by `UpdateContactId` if an existing main contact person is found for the customer in the App4Sales database. |
Phone | Phone | Phone number of the contact person. |
LanguageCode | LanguageCode | Preferred language code for the contact. |
Email address of the contact person. | ||
FirstName | ContactFullName | Extracted first name from the `ContactFullName` field. |
LastName | ContactFullName | Extracted last name from the `ContactFullName` field. |
IsMainContact | Hardcoded | Hardcoded to `true`, indicating this is a main contact. |
Customer | CustomerGuid | The GUID of the customer associated with this contact. |
Mobile | Mobile | Mobile phone number of the contact person. |
Validation & Defaults
Mandatory Customer Code: The `CustomerCode` field in the incoming `XmlCustomer` object is mandatory. If it is empty or null, the update will be rejected with an error message: "Not supported to create a new customer".
Character Sanitization: All `XmlCustomer` data undergoes a sanitization step where non-ISO-8859-1 characters are removed using `c.RemoveNonIso88591Chars()`.
Discount Parsing: The `Discount` field is parsed from a string to a decimal. If parsing fails, a default value of 0 is used.
Address and Contact ID Lookup: For addresses and contacts, if an existing main delivery address or main contact person is found in the App4Sales database for the given customer, their respective IDs are retrieved and used to ensure an update rather than an insertion.
Hardcoded Values: `IsMainAddress` for addresses and `IsMainContact` for contact persons are hardcoded to `true`. The `Type` for addresses is hardcoded to "del".
Response & Error Handling
Upon successful processing of the customer, address, and contact updates, the method returns a success indicator along with the `CustomerCode` (`Constants.RequestParameter.SUCCESS_CUSTOMER + customerCode`).
In case of any exception during the update process, the error is logged using `Log.Error`, and an error message (`Constants.Error.ERROR + exc.Message`) is returned to the caller. This includes issues during data conversion, API calls to StyleMan, or internal processing. Specific JSON payloads sent to the StyleMan API are logged at an "Essential" level (`Log.Essential`) for debugging purposes.
If no customer data is found or processed in the request, the method returns `Constants.Error.NoBackoffice`.
Known Limitations
No New Customer Creation: This connector explicitly does not support the creation of new customers. It is designed solely for updating existing customer records.
Single Main Address/Contact: The logic for updating addresses and contacts focuses on a single "main" delivery address and "main" contact person, retrieving their IDs from the App4Sales database. It does not handle multiple addresses or contacts for a customer beyond this scope.