Skip to main content

PrestaShop - Item sync

PrestaShop Connector - ItemUpdate This function synchronizes item data from PrestaShop into the App4Sales platform. It retrieves product ...

Updated over a week ago

PrestaShop Connector - ItemUpdate

This function synchronizes item data from PrestaShop into the App4Sales platform. It retrieves product details, stock information, images, and specific pricing rules from the PrestaShop API. Only active and non-matrix products are processed. It runs on a scheduled basis, updating the App4Sales internal item database.

Data Source Configuration

Data is pulled from the PrestaShop API. The base URL for the API and the Application Key are configured in the connector settings.

  • Products: Fetched from the /products endpoint.

  • Taxes: Fetched from the /taxes and /tax_rules endpoints.

  • Stock: Fetched from the /stock_availables endpoint.

  • Categories: Fetched from the /categories endpoint.

  • Specific Prices: Fetched from the /specific_prices endpoint.

  • Images: Downloaded directly from [PrestaShop_Base_URL]/images/products/[productId]/[imageId].

Data Mapping Table - Items

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

ItemCode

prestashop/product/reference or productId

If the connector setting "Use Product Reference as Item Code" is enabled, the reference field is used. Otherwise, the internal PrestaShop productId is used. The mapping is stored in the KeySettingsContext for later use.

Description

prestashop/product/name/language, prestashop/product/description/language

Concatenation of the product name and description, separated by " - ".

SalesPrice

prestashop/product/price

The product's base price, converted to a decimal.

VatIncluded

Derived

Hardcoded to 'E' (Exclusive).

VatPercentage

prestashop/tax/rate

Determined by looking up the product's id_tax_rules_group against fetched tax rules and then retrieving the corresponding tax rate.

EanCode

prestashop/product/ean13

The product's EAN13 barcode.

PurchasePackageSize

prestashop/product/minimal_quantity

The minimal quantity for purchase, converted to a decimal.

Currency

Derived

Hardcoded to "EUR".

LastAvailableStock

prestashop/stock_available/quantity

The available stock quantity, converted to a decimal. Includes error handling for API changes.

Picture

prestashop/product/id_default_image

The default image for the product is downloaded using its ID. The raw image data is stored. Includes error handling for download failures.

ItemClasses

prestashop/category/name/language

An ItemClass with the description "Filters" is created. For each category associated with the product, an ItemClassValue is created using the category's name.

Special Logic & Filters

  • Product Filtering: Only active products (active = 1) are processed. Products identified as matrix items (having associations/combinations/combinations) are skipped.

  • Stock Retrieval: Includes a try-catch block to handle potential API breaking changes in PrestaShop's stock available endpoint. If stock retrieval fails, the stock value remains unset.

  • Image Download: The DownloadImage helper method handles fetching the image data from the PrestaShop URL. Exceptions during download are caught and ignored, meaning items will be synced without a picture if the download fails.

  • Category Handling: The connector attempts to retrieve category IDs from two possible XML paths (prestashop/product/associations/categories/categories/id and prestashop/product/associations/categories/category/id) to account for potential breaking changes in the PrestaShop API.

  • Specific Price Caching: Specific prices from PrestaShop are processed, and their IDs are saved in the KeySettingsContext, prefixed with "SpecificPrices_". This allows the OptA4SGetItemPriceForCustomer method to efficiently retrieve customer-specific pricing information without re-fetching all specific prices. Specific prices with an expired 'to' date are skipped.

Domain Specifics

Price Logic

The base sales price is taken from prestashop/product/price. Tax percentages are applied based on PrestaShop's tax rules. Customer-specific and quantity-based pricing (specific prices) are handled by the OptA4SGetItemPriceForCustomer method, which checks for specific price rules linked to the product and customer. Discounts can be applied as either a fixed amount or a percentage.

Image Handling

The default product image is downloaded from the PrestaShop instance using its ID. The image is fetched directly from the URL [PrestaShop_Base_URL]/images/products/[productId]/[imageId]. No explicit resizing or compression logic is observed within this method; the raw image data is stored.

Stock & Availability

Stock is retrieved from the stock_availables endpoint. The quantity is taken from prestashop/stock_available/quantity. If there are issues retrieving stock, the item is still processed, but without stock information.

Matrix & Attributes

Matrix (variant) products are explicitly skipped by this update function. Item categorization is handled by creating an ItemClass named "Filters" and populating its values with the names of the PrestaShop categories associated with the product.

Related Settings & Prerequisites

  • Use Product Reference as Item Code: (Settings.ProductReferenceAsItemCode) A boolean setting that determines whether the PrestaShop product 'reference' or the internal 'product ID' is used as the App4Sales Item Code.

  • Application Key: (Settings.Applicationkey) The API key required for authenticating requests to the PrestaShop API.

  • PrestaShop Base URL: (AdministrationSession.CurrentSession.Administration.Address) The base URL of the PrestaShop instance.

Known Limitations

This function explicitly skips matrix products; variant handling is not covered by this ItemUpdate method. The connector assumes a default currency of "EUR."

Did this answer your question?