FtpXml Connector - ItemUpdate
The ItemUpdate method in the FtpXml Connector is responsible for synchronizing item-related data from external XML files, primarily items.xml and itemfilters.xml, located on an FTP server. It updates App4Sales with item details, sales prices, VAT information, stock levels, item classifications, matrix/variant data, and embedded item images. The process involves downloading these XML files, parsing their content, applying various transformations and conditional logic, and then persisting the processed data into the App4Sales internal database.
Data Source Configuration
The connector retrieves data from the following sources, accessed via an FTP connection configured within App4Sales. File paths are relative to the configured FTP root directory.
items.xml: This is the primary data source for item details. It contains individual item records, their descriptions, pricing, stock information, EAN codes, matrix data, and embedded Base64 image data. This file is downloaded from the FTP server and processed.itemfilters.xml: This XML file defines item classification categories. It is downloaded from the FTP server and parsed to establish a mapping between internal IDs and human-readable captions, which are then used to interpret item attributes fromitems.xml.languages.xml: An optional XML file containing language codes. If present, it is downloaded and processed to update language descriptions within App4Sales. Errors during the processing of this file are logged but do not halt the item update process.Internal App4Sales Database:
VAT Code Percentages: Retrieved from
VatCodePercentagesContextfor VAT calculations.Stock Data: If configured to calculate the Stock Indicator by formula, base stock data for items is retrieved from
ItemsContext.
Item Data Mapping
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
|
| Directly mapped from the |
| Hardcoded / | If |
|
| Parsed from string to a decimal value. If parsing fails, the value will be |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| Parsed from string to a DateTime object. |
|
| Parsed from string to a DateTime object. |
|
| Parsed from string to a character. Items without a value in this field are skipped from processing. |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| Parsed from string to a decimal value. |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| Parsed from string to an integer value. |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. Values are HTML decoded unless they start with '<'. |
|
| If the source contains ' |
|
| Parsed from string to a decimal value. |
|
| Parsed from string to a nullable DateTime object. |
|
| Direct mapping. Used to identify the parent item of a variant. Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. Describes the X-axis of a matrix (e.g., "Color"). Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. The value for the X-axis of a matrix (e.g., "Red"). Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. Describes the Y-axis of a matrix (e.g., "Size"). Values are HTML decoded unless they start with '<'. |
|
| Direct mapping. The value for the Y-axis of a matrix (e.g., "Large"). Values are HTML decoded unless they start with '<'. |
|
| Direct mapping for a search field used to link items on the scan page. Values are HTML decoded unless they start with '<'. |
|
| Direct mapping for XML content containing linked items on the item detail card. Values are HTML decoded unless they start with '<'. |
|
| Parsed from string to a decimal value. |
|
| If the 'Use stock indicator from connector' setting is true, maps directly from |
Item Classification Mapping
Item classifications (ItemClasses and their ItemClassValues) are derived from two sources: itemfilters.xml and specific fields within items.xml.
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
|
| The |
|
| The value of fields such as |
Price List Item Mapping
Additional sales prices beyond the primary SalesPrice are mapped to PriceListPrice entities, creating dynamic Price Lists as needed.
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
| Derived from | The numeric suffix 'X' (e.g., '2' from |
| Derived from | Automatically generated as "Pricelist X" (e.g., "Pricelist 2"). |
| Derived from | The numeric suffix 'X' is also used as the Price List ID. |
| Derived from | The numeric suffix 'X' of the source field. |
|
| The App4Sales |
|
| The value of the |
Special Logic & Filters
Item Filtering by VAT Included: Any item record in
items.xmlthat does not contain a value foritems.vatincludedwill be skipped entirely.Item Filtering by Price List Presence: The system can be configured via the 'Only import items with pricelist' setting. If this setting is active (set to 1, 2, 3, or 4), items will only be imported if the corresponding
items.salespackageprice,items.price_2,items.price_3, oritems.price_4field, respectively, contains a value. If the required price field is missing, the item is skipped.Language Synchronization: The
SyncLanguages()helper method attempts to download and processlanguages.xml. This file is expected to contain language codes which are used to update App4Sales language descriptions. Any errors during the download or parsing oflanguages.xmlare logged but do not prevent the main item update process from continuing.Error Handling: The process includes robust error handling with
try-catchblocks around XML file downloads and item processing loops. Errors are logged, and in critical cases,Session.PortalServerProvider.ResetDataUpdateIntervals()is called to manage update intervals.
Domain Specifics (Expanded)
Price Logic
The connector supports a base sales price and multiple additional price lists, along with detailed VAT handling.
Base Sales Price: The core selling price is mapped from
items.salespackagepricetoItem.SalesPrice.Tiered/Customer-Specific Prices: Additional price lists are dynamically created and populated from fields like
items.price_2,items.price_3, etc. Eachitems.price_Xfield (where 'X' is a number) represents a specific price list. If a value is present, aPriceListPricerecord is created for the item within that price list.VAT Calculation:
Item.VatIncludedindicates if the sales price already includes VAT.Item.VatPercentageis determined based on theitems.vatpercentagefield. This field can either contain a direct percentage or a combined code and country (e.g., "HIGH~NL") which is then looked up against pre-configured VAT percentages in App4Sales. If a combined code/country is used and no match is found, the VAT percentage defaults to 0.
Image Handling
Item images are handled directly through embedded Base64 strings within the items.xml.
Image Source: Images are expected to be provided as Base64 encoded strings in the
items.picturefield ofitems.xml.Processing: The Base64 string is decoded into a byte array and associated with the item using a method that includes a hash check, likely to prevent duplicate image storage.
Optimized Updates: If the 'Only update new pictures' setting is enabled, the 'lastupdated' timestamp for existing item pictures in the database is updated at the beginning of the sync, potentially optimizing subsequent image processing.
Cleanup: A temporary directory used for item pictures, determined by
FtpSyncManager.Instance.ItemPicturesFolder, is deleted after the update process completes.
Stock & Availability
Stock information primarily consists of available stock, next delivery dates, and a stock indicator.
Available Stock: The
items.lastavailablestockfield is mapped toItem.LastAvailableStock, representing the quantity of stock currently available.Next Delivery: The
items.nextdeliveryfield is mapped toItem.NextDelivery, providing an estimated date for future stock availability.Stock Indicator: The
Item.StockIndicatorcan be sourced directly fromitems.stockindicatorin the XML if the 'Use stock indicator from connector' setting is true. Alternatively, if the 'Get stock indicator by formula' setting is true, the indicator is dynamically calculated. This calculation involves fetching additional stock data from App4Sales' internal database and using an external script (CalculateStockIndicatorByFormula) that considers thresholds (QuantityForRed,QuantityForGreenfrom App4Sales settings) to determine the indicator status (e.g., green, orange, red).
Matrix & Attributes
The connector supports robust handling of matrix items (parent-child variants) and custom item attributes.
Matrix Items:
Parent-Child Linking: The
items.matrixparentfield explicitly links a child variant to its parent item.Variant Axes: Fields like
items.matrixxdescription/items.matrixxcodeanditems.matrixydescription/items.matrixycodedefine the characteristics (e.g., "Color", "Size") and their respective values for each variant.
Item Classifications (Attributes):
Custom attributes are defined using
itemfilters.xml(which maps internal IDs to descriptions like "Material" or "Brand").Specific attribute values for each item are provided in
items.xmlusing fields likeitemclassvalues.value1,itemclassvalues.value2, etc. These values are then associated with their corresponding item class descriptions.
Related Settings & Prerequisites
The behavior of the Item Update process can be influenced by several connector and App4Sales settings:
Only update new pictures: (Connector Setting) If true, a database update timestamp for item pictures is set, potentially influencing how images are re-processed.
Only import items with pricelist: (Connector Setting) An integer value (1-4) that determines which sales price field (
items.salespackageprice,items.price_2,items.price_3, oritems.price_4, respectively) must have a value for an item to be imported.Use stock indicator from connector: (Connector Base Setting) If true, the
Item.StockIndicatoris taken directly from theitems.stockindicatorfield in the XML.Get stock indicator by formula: (Connector Base Setting) If true (and 'Use stock indicator from connector' is false), the
Item.StockIndicatoris calculated using an internal formula and script.Quantity for Red: (App4Sales Setting) A threshold used in the stock indicator formula to determine when stock should be flagged as 'red'.
Quantity for Green: (App4Sales Setting) A threshold used in the stock indicator formula to determine when stock should be flagged as 'green'.
XML File Structure: The connector expects
items.xml,itemfilters.xml, and optionallylanguages.xmlto adhere to a specific XML structure for successful parsing.FTP Connection: A correctly configured FTP connection (host, credentials, root directory) is essential for the connector to download the necessary XML files.
Known Limitations
languages.xmlError Handling: Errors encountered during the download or parsing oflanguages.xmlare logged but are intentionally suppressed, meaning language synchronization failures will not prevent the primary item update from completing. The comment in the code suggests this is a low-priority process.Stock Indicator Formula Complexity: The exact logic for the 'Stock Indicator' when calculated by formula is defined in an external script (
DataConstants.Scripts.CalculateStockIndicatorByFormula). Administrators configuring the system would need to understand this script's logic to predict stock indicator behavior accurately. The C# code only orchestrates the execution of this script.Image File Naming/Structure: While Base64 embedded images are supported, the documentation from code analysis does not indicate support for image files on the FTP server with specific naming conventions for linking to items. The primary image handling observed is via Base64.