Spector Connector - Item Update
This function synchronizes item information from the Spector ERP system to App4Sales. It performs a full synchronization every Sunday or when the 'ForceFullItemSync' setting is enabled. During synchronization, it processes item details, various price lists, staffle (tier) prices, and language-specific descriptions.
Data Source Configuration
Item data is retrieved from the Spector API using the 'ItemInfo' endpoint. Data is fetched in batches.
Data Mapping Table (Items)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
ItemCode | entity.ItemCode | Direct mapping from Spector's item code. |
InternalItemCode | entity.InternalItemCode | Direct mapping from Spector's internal item code. |
Description | entity.Description | Direct mapping from Spector's item description. |
VatPercentage | entity.VatPercentage | Direct mapping from Spector's VAT percentage. |
EanCode | entity.EanCode | Direct mapping from Spector's EAN code. |
ItemClasses | entity.ItemGroup | Mapped to a single ItemClass. The ItemClass description is taken from the 'ArticleGroupName' setting (default "Artikelgrupp"), and its value is derived from Spector's 'ItemGroup'. |
SalesPrice | entity.SalesPriceExVat | Direct mapping from Spector's sales price, excluding VAT. |
VatIncluded | 'E' | Hardcoded value 'E'. |
LastAvailableStock | entity.Stocks | Calculated sum of available stock. If the 'Warehouses' setting is configured, stock is filtered by the specified warehouses. If 'ShowShelfStock' is true, 'ShelfStock' is used; otherwise, 'AvailableStock' is used. If no specific warehouses are configured, stock from all default warehouses ('IsDefaultStock') is summed. |
PurchasePackageSize | entity.PackagingSize | Direct mapping from Spector's packaging size. |
ItemCategories (Article info) | entity.WebshopInfo?.ItemInfo | If present and not empty, added as an item category after HTML decoding. |
ItemCategories (Short article info) | entity.WebshopInfo?.ShortItemInfo | If present and not empty, added as an item category after HTML decoding. |
ItemCategories (Extra info) | entity.ItemComment | If present and not empty, added as an item category. |
ItemCategories (Extra info (internal)) | entity.InternalComment | If present and not empty, added as an item category. |
ItemCategories (Supplier) | supplier.Name | For each supplier associated with the item, their name is added as an item category. |
Description2-5 | entity.LanguageArticleInfo | Language-specific descriptions are mapped to Description2 through Description5 based on the 'LanguageCodeISO1' from Spector and the corresponding 'DescriptionField' configured in App4Sales Language settings. |
Data Mapping Table (Price Lists)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Id | Derived from Currency Code or Discount List ID | A unique hash code is generated for each price list (e.g., 'C_P{price.Id}' for currency-based, 'D{discountList.Id}_P{price.Id}' for discount lists). |
Code | Derived from Currency Code or Discount List ID | For currency prices, the code is 'C-{CurrencyCode}' (e.g., 'C-SEK'). For discount lists, it's '{DiscountList.Id}-{CurrencyCode}'. A default SEK pricelist ('C-SEK') is always created. |
Description | Derived from Currency Code or Discount List Description | For currency prices, the description is '{CurrencyCode} Price'. For discount lists, it's '{DiscountList.Description} ({CurrencyCode})'. |
Currency | price.CurrencyCode | Direct mapping from the currency code. Default SEK pricelist has 'SEK'. |
Selectable | true | Hardcoded to true. |
Data Mapping Table (Price List Prices)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
ItemCode | entity.ItemCode | Direct mapping from Spector's item code. |
Price | price.PriceExclVat | Direct mapping from the price excluding VAT. |
PriceListId | pricelist.Id | Mapped to the ID of the corresponding price list. |
Data Mapping Table (Staffle Prices)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
ItemCode | entity.ItemCode | Direct mapping from Spector's item code. |
MinQuantity | priceInterval.FromInterval | Direct mapping from the minimum quantity for the price interval. |
Discount | priceInterval.Discount | Direct mapping from the discount percentage for the price interval. |
Special Logic & Filters
Full Synchronization: A full synchronization of all items, customers, and item prices is triggered every Sunday or if the 'ForceFullItemSync' setting is explicitly enabled. During a full sync, existing item batches in App4Sales are cleared before new data is imported.
Item Exclusion: Items are excluded from synchronization if they are marked as deleted in Spector (
entity.IsDeleted == true). Additionally, if the 'OnlySyncWebshopItems' setting is enabled, items not marked for viewing in the webshop (entity.WebshopInfo.ViewInShop == false) will also be excluded.Language Descriptions: App4Sales supports up to five description fields. Language-specific descriptions from Spector's 'LanguageArticleInfo' are mapped to 'Description2' through 'Description5' based on language codes and the 'DescriptionField' configured within App4Sales for each language.
Stock Calculation: The available stock for an item is calculated by summing quantities from 'entity.Stocks'. The specific stock type ('AvailableStock' or 'ShelfStock') used in this calculation depends on the 'ShowShelfStock' setting. The calculation can be further refined by the 'Warehouses' setting, which allows administrators to specify a subset of warehouses to consider.
Price List Generation: A default SEK pricelist is always generated. Additional price lists are dynamically created for each unique currency found in Spector's item currency prices and for each discount list. Prices with a zero value ('PriceExclVat == 0') in discount lists are skipped during price list generation.
Domain Specifics
Price Logic
The connector comprehensively handles various pricing structures from Spector. A default SEK pricelist is always established to support new customers. For each item, price lists are dynamically generated based on currency codes (e.g., "C-USD" for US Dollar prices) and specific discount lists (e.g., "D123-EUR" for discount list 123 in Euro). Individual item prices are extracted from 'CurrencyPrices' and 'DiscountLists' within Spector's item data, providing the 'PriceExclVat' for each. Additionally, 'StafflePrice' (tier pricing) is supported, derived from 'PriceIntervals', which defines minimum quantities and associated discounts. Note that discount list prices with a value of zero are explicitly excluded.
Image Handling
The provided code for the 'ItemUpdate' method and its direct dependencies does not explicitly contain logic for synchronizing or processing item images. Image handling is not managed by this specific update function.
Stock & Availability
Stock levels for items are calculated from the 'Stocks' information provided by Spector. Administrators can configure the 'Warehouses' setting to include stock from specific warehouses; otherwise, stock from all default warehouses (marked as 'IsDefaultStock') is aggregated. The 'ShowShelfStock' setting determines whether the 'ShelfStock' (physical stock on shelves) or 'AvailableStock' (stock ready for sale) is used in the calculation. It's important to note that while the 'fullStockValues' parameter is received by the 'ItemUpdate' method, its direct utilization for stock calculation is not evident in this code segment, suggesting its potential use elsewhere in the connector or as a placeholder.
Matrix & Attributes
The connector maps Spector's 'ItemGroup' to an App4Sales 'ItemClass'. The descriptive name for this 'ItemClass' can be customized via the 'ArticleGroupName' setting; if not specified, it defaults to "Artikelgrupp". This mechanism allows for categorizing items based on their group definitions in Spector.
Related Settings & Prerequisites
Force full item sync: (Boolean) If enabled, forces a full synchronization of all item data, regardless of the day of the week. This clears existing item batches before importing new data.
Warehouses: (Text) A comma or semicolon-separated list of Spector warehouse names. If provided, item stock will only be calculated for these specified warehouses. If left empty, stock from all default warehouses will be considered.
Only sync webshop items: (Boolean) If enabled, only items that are explicitly marked as visible in the webshop within Spector (
WebshopInfo.ViewInShop == true) will be synchronized to App4Sales.Show shelf stock: (Boolean) When calculating available stock, if this setting is true, the 'ShelfStock' value from Spector will be used. If false, the 'AvailableStock' value will be used instead.
Article group name: (Text) Specifies the display name for the ItemClass derived from Spector's 'ItemGroup'. If not set, it defaults to "Artikelgrupp".
Known Limitations
No explicit image handling is identified within the 'ItemUpdate' method or its directly associated helper functions.
The 'fullStockValues' parameter, though part of the 'ItemUpdate' method signature, is not directly used for stock calculation in the analyzed code. Its purpose may lie in other parts of the connector or it may be a placeholder.