PrestaShop Connector - Send Order to Backoffice
This function is responsible for transferring App4Sales orders to the PrestaShop e-commerce platform. It prepares the order header and order lines based on the App4Sales order object and sends them to PrestaShop via its API. The process involves retrieving customer, address, and carrier information from PrestaShop and then creating a cart and an order within PrestaShop.
Data Source Configuration
The connector retrieves various pieces of information from PrestaShop via its API using the GetResultFromApi method. This includes:
Carriers: Fetched from the 'carriers' endpoint to determine the default carrier for the order.
Customer Details: Retrieved from the 'customers' endpoint using either the App4Sales customer code directly or a mapped PrestaShop customer ID stored in
KeySettingsContext(key prefixPrestaShop_CustomerCode_).Customer Address: The delivery and invoice address ID is retrieved from
KeySettingsContext(key prefixCustomerAddress_), which links an App4Sales customer to a PrestaShop address.Current Currency: The default currency ID is retrieved from
KeySettingsContextwith the keyCurrentCurrency.Language: The customer's language ID is retrieved from the PrestaShop customer details.
Product ID: For each order line, the PrestaShop product ID is obtained. If the setting
ProductReferenceAsItemCodeis enabled, the product ID is looked up inKeySettingsContext(key prefixPrestaShop_ArtReference_) using the App4Sales item code. Otherwise, the App4Sales item code is used directly as the PrestaShop product ID.
Data Mapping Tables
PrestaShop Cart Object Mapping
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
id_customer | App4Sales Order.Customer.CustomerCode / PrestaShop customer ID | Mapped from App4Sales CustomerCode. If |
id_shop | PrestaShop customer document ( | Retrieved from the customer information fetched from PrestaShop. |
id_shop_group | PrestaShop customer document ( | Retrieved from the customer information fetched from PrestaShop. |
id_currency |
| Retrieved from |
id_lang | PrestaShop customer document ( | Retrieved from the customer information fetched from PrestaShop. |
secure_key | PrestaShop customer document ( | Retrieved from the customer information fetched from PrestaShop. |
id_address_delivery |
| Retrieved from |
id_address_invoice |
| Same as |
id_carrier | PrestaShop carriers API response | The ID of the first carrier found from the PrestaShop 'carriers' API endpoint. |
PrestaShop Cart Row Mapping (for each Order Line)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
id_product | App4Sales OrderLine.Item.ItemCode / PrestaShop product ID | Mapped from App4Sales ItemCode. If |
id_product_attribute | Hardcoded | Always set to |
quantity | App4Sales OrderLine.Quantity | Directly mapped from the App4Sales order line quantity, cast to an integer. |
PrestaShop Order Object Mapping
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
id_address_delivery |
| Retrieved from |
id_address_invoice |
| Same as |
id_cart | Derived | The ID of the newly created PrestaShop cart. |
id_currency |
| Retrieved from |
id_lang | PrestaShop customer document ( | Retrieved from the customer information fetched from PrestaShop. |
id_customer | App4Sales Order.Customer.CustomerCode / PrestaShop customer ID | Mapped from App4Sales CustomerCode. If |
id_carrier | PrestaShop carriers API response | The ID of the first carrier found from the PrestaShop 'carriers' API endpoint. |
module |
| If |
payment |
| If |
total_paid_real | Hardcoded | Always set to |
total_paid_tax_excl | Hardcoded | Always set to |
total_paid_tax_incl | Hardcoded | Always set to |
total_products | Hardcoded | Always set to |
total_products_wt | Hardcoded | Always set to |
conversion_rate | Hardcoded | Always set to |
secure_key | PrestaShop customer document ( | Retrieved from the customer information fetched from PrestaShop. |
id_shop | PrestaShop customer document ( | Retrieved from the customer information fetched from PrestaShop. |
id_shop_group | PrestaShop customer document ( | Retrieved from the customer information fetched from PrestaShop. |
current_state | Hardcoded | Initially set to |
PrestaShop Order Row Mapping (for each Order Line)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
product_id | App4Sales OrderLine.Item.ItemCode / PrestaShop product ID | Mapped from App4Sales ItemCode. If |
product_attribute_id | Hardcoded | Always set to |
quantity | App4Sales OrderLine.Quantity | Directly mapped from the App4Sales order line quantity, cast to an integer. |
Special Logic & Filters
Customer Address Validation: The connector checks if a valid address ID exists for the customer in
KeySettingsContext. If not, the order send process is aborted, and an error message "ERROR: Customer needs a valid address" is returned.Customer and Product ID Resolution: Customer and product IDs for PrestaShop are resolved using
KeySettingsContextbased on connector settings (Settings.CustomerCodeForFieldandSettings.ProductReferenceAsItemCode). This allows for mapping App4Sales codes to PrestaShop specific IDs.Cart and Order Creation: The process involves two main steps: first, a PrestaShop
cartobject is created usingCartFactory.Add, and then anorderobject is created usingOrderFactory.Add, referencing the created cart.Order State Update: After an order is initially created with
current_state = 1, it is immediately updated tocurrent_state = 9. The exact meaning of these states (e.g., 'pending' to 'completed') would depend on PrestaShop's internal state definitions.Order Number Update: Upon successful creation of the order in PrestaShop, the returned PrestaShop order ID is saved back into the App4Sales system using
OrdersContext.Instance.UpdateOrderNumber.
Domain Specifics / Extension Section
Order Header Logic
Customer information (ID, shop, shop group, language, secure key) is sourced directly from PrestaShop's customer API endpoint, using the App4Sales customer code to identify the corresponding PrestaShop customer. The delivery and invoice address IDs are retrieved from the KeySettingsContext, which must contain a valid PrestaShop address ID linked to the App4Sales customer. The currency ID is also obtained from the KeySettingsContext. The connector selects the first carrier returned by the PrestaShop carriers API as the default carrier for the order. Payment module and method are configured via connector settings or default to "cheque" and "Payments by check" respectively.
Line & Pricing Logic
Each App4Sales order line is translated into a PrestaShop cart row and order row. The PrestaShop product ID is resolved based on the App4Sales item code, potentially using a lookup in KeySettingsContext if ProductReferenceAsItemCode is enabled. The quantity is directly mapped. No specific pricing logic (customer price list, action price, promotional override) or discount aggregation, rounding rules, tax/VAT recalculation, or currency conversions are handled within this method for the order lines themselves, as total_paid_real, total_paid_tax_excl, total_paid_tax_incl, total_products, and total_products_wt are hardcoded to 0.
Charges & Attachments
There is no explicit logic within the SendOrderToBackoffice method to handle charges (freight, payment fees, coupons) or attachments (PDF, signature images, custom payloads). These would not be transferred to PrestaShop through this specific function.
Responses & Error Handling
If the order is successfully created in PrestaShop, the returned PrestaShop order ID is used as the order number and stored in the App4Sales system. In case of an exception during the process, a generic error message including the exception details is returned, prefixed with "ERRORORDERNR". A specific error is returned if the customer does not have a valid address stored in the KeySettingsContext.
Related Settings & Prerequisites
For this function to operate correctly, the following settings and prerequisites must be in place:
Application key: A valid PrestaShop API key (
Settings.Applicationkey) for authentication with the PrestaShop API.PrestaShop Admin Address: The base URL of the PrestaShop administration interface (
AdministrationSession.CurrentSession.Administration.Address).Customer Code for Field: (
Settings.CustomerCodeForField) If specified, this setting determines which field in the PrestaShop customer object is used as the customer code. This also influences how the PrestaShop customer ID is retrieved fromKeySettingsContext(PrestaShop_CustomerCode_).Product Reference as Item Code: (
Settings.ProductReferenceAsItemCode) If true, the connector uses the PrestaShop product reference as the item code and performs a lookup inKeySettingsContext(PrestaShop_ArtReference_) to get the actual PrestaShop product ID. Otherwise, the App4Sales item code is used directly as the PrestaShop product ID.Module: (
Settings.Module) Specifies the PrestaShop payment module to use. Defaults to "cheque" if not set.Order Payment: (
Settings.OrderPayment) Specifies the payment method description for the order. Defaults to "Payments by check" if not set.Multi Order Rows: (
Settings.MultiOrderRows) This setting is passed to theOrderFactory.AddandOrderFactory.Updatemethods, likely influencing how multiple order lines are handled.KeySettingsContext Entries: The
KeySettingsContextmust contain the following entries:PrestaShop_CustomerCode_[App4SalesCustomerCode]: Maps App4Sales customer codes to PrestaShop customer IDs (ifSettings.CustomerCodeForFieldis used).CustomerAddress_[App4SalesCustomerCode]: Stores the PrestaShop address ID for a given App4Sales customer code. This is crucial for successful order placement.PrestaShop_ArtReference_[App4SalesItemCode]: Maps App4Sales item codes to PrestaShop product IDs (ifSettings.ProductReferenceAsItemCodeis true).CurrentCurrency: The default currency ID used for orders.
Known Limitations
Limited Pricing Detail: The connector does not transfer detailed pricing information (like individual unit prices, discounts, or tax breakdowns) from App4Sales to PrestaShop. The
total_paid_real,total_paid_tax_excl,total_paid_tax_incl,total_products, andtotal_products_wtfields in the PrestaShop order are hardcoded to 0.No Surcharges or Attachments: There is no functionality to send order surcharges (e.g., freight, payment fees) or attachments (e.g., PDFs, signatures) to PrestaShop.
Single Carrier: Only the first carrier retrieved from the PrestaShop API is used, without any logic for selecting a specific carrier based on App4Sales order details.
No Product Attributes: The
id_product_attributefor order lines is hardcoded to 0, meaning product variations or attributes are not supported by this send order function.Generic Error Handling: Beyond checking for a valid customer address, error handling is generic, returning a general error message on exceptions without detailed insights into the cause of failure from the PrestaShop API.