Skip to main content

PrestaShop - Customer sync

PrestaShop Connector - Customer Update This function synchronizes customer and address information from a PrestaShop instance to the A...

Updated over a week ago

PrestaShop Connector - Customer Update

This function synchronizes customer and address information from a PrestaShop instance to the App4Sales platform. It retrieves customer and address data via the PrestaShop API, applies various filters and transformations, and updates the corresponding App4Sales customer and address records. It also retrieves and caches language and country mappings, and certain configuration settings like the default currency.

Customer Core Fields

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

CustomerCode

prestashop/customer/id

If the connector setting CustomerCodeForField is empty, the PrestaShop customer ID is used.

CustomerCode

prestashop/customer/<field_name>

If the connector setting CustomerCodeForField is specified, the value from the indicated PrestaShop customer field is used. The original PrestaShop customer ID is stored in KeySettingsContext as PrestaShop_CustomerCode_<CustomerCode> for later lookup.

LanguageCode

prestashop/customer/id_lang

PrestaShop language ID is mapped to its ISO 639-1 alpha-2 code (e.g., 'en', 'nl', 'fr') using a helper method that queries the PrestaShop API for language details.

CustomerName

prestashop/customer/firstname, prestashop/customer/lastname, prestashop/customer/company

Initially set by concatenating firstname and lastname (e.g., "John Doe"). If the company field is not empty, it overrides the concatenated name. Leading and trailing whitespace is removed.

Contacts

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

ContactId

prestashop/customer/id

The PrestaShop customer ID is used as the contact ID.

FirstName

prestashop/customer/firstname

LastName

prestashop/customer/lastname

Email

prestashop/customer/email

FullName

Derived

Concatenation of FirstName and LastName.

Addresses

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

AddressType

Hardcoded

Hardcoded to "vis" (visit address).

AddressId

prestashop/address/id

City

prestashop/address/city

AddressLine1

prestashop/address/address1

AddressLine2

prestashop/address/address2

PostCode

prestashop/address/postcode

Phone

prestashop/address/phone

Country

prestashop/address/id_country

PrestaShop country ID is mapped to its ISO 3166-1 alpha-2 code (e.g., 'US', 'NL', 'FR') using a helper method that queries the PrestaShop API for country details and caches the mapping in KeySettingsContext.

Special Logic & Filters

  • **Customer Filtering:** Customers are filtered out if they are marked as deleted (prestashop/customer/deleted == "1") or inactive (prestashop/customer/active != "1") in PrestaShop.

  • **Shop Filtering:** Only customers belonging to the shop ID configured in the connector settings (Settings.IdShop) are processed.

  • **Address Clearing:** At the start of the update, any previously stored customer address links in the KeySettingsContext are cleared (keys starting with "CustomerAddressLink_").

  • **Parallel Address Processing:** The connector processes addresses in parallel to improve performance.

  • **Configuration Retrieval:** The value of the PrestaShop configuration PS_CURRENCY_DEFAULT is retrieved and stored in KeySettingsContext under the keys "CurrentVersion" and "CurrentCurrency".

Settings & Prerequisites

The following connector settings and internal contexts influence the behavior of the Customer Update process:

  • **Id Shop**: This setting (configured in the connector) specifies the ID of the PrestaShop shop from which customers should be synchronized. Customers not associated with this Id Shop will be skipped.

  • **Customer Code For Field**: This setting allows administrators to define which PrestaShop customer field should be used as the unique CustomerCode in App4Sales. If left empty, the internal PrestaShop customer ID is used.

  • **Application Key**: This key is used for authenticating all API requests to the PrestaShop instance.

  • **KeySettingsContext**: This internal context is used to cache country and language ISO code mappings from PrestaShop IDs, store the mapping between App4Sales CustomerCode and PrestaShop customer ID, and to store the default currency from PrestaShop configuration.

Known Limitations

  • Only visit addresses are currently synchronized, hardcoded with AddressType = "vis".

  • There is no explicit handling for different address types (e.g., delivery, invoice) beyond the hardcoded 'vis' type.

  • Addresses are linked to customers based on the id_customer field from PrestaShop. If an address cannot be matched to a customer processed in the current run, it will be skipped.

Did this answer your question?