feat(prestashop): sync mapped statuses from Orbito in 1.1.11

This commit is contained in:
fatequod
2026-09-21 15:01:30 +02:00
parent af0dceaa1b
commit 11f1c99e2b
16 changed files with 587 additions and 32 deletions
+21
View File
@@ -34,6 +34,26 @@ function resolveStatusId(psStateId, statusMapping, fallbackStatusId) {
return normalizeStatusId(match?.orbitoStatusId) ?? normalizeStatusId(fallbackStatusId);
}
// Mapowanie jest konfigurowane w wierszach PrestaShop -> Orbito, ale po
// zapisaniu służy wyłącznie do wysyłki statusu w przeciwnym kierunku.
// Jeden status Orbito nie może wskazywać kilku statusów PrestaShop, bo wtedy
// wynik synchronizacji zależałby od kolejności pól formularza.
function resolvePsStateId(orbitoStatusId, statusMapping) {
const normalizedStatusId = normalizeStatusId(orbitoStatusId);
if (!normalizedStatusId || !Array.isArray(statusMapping)) return null;
const matches = statusMapping
.filter(entry => normalizeStatusId(entry?.orbitoStatusId) === normalizedStatusId)
.map(entry => parseInt(entry.psStateId, 10))
.filter(stateId => !Number.isNaN(stateId));
const uniqueMatches = [...new Set(matches)];
if (uniqueMatches.length > 1) {
throw new Error(`Status Orbito ${normalizedStatusId} jest przypisany do kilku statusów PrestaShop`);
}
return uniqueMatches[0] ?? null;
}
function formatPsStatesPreview(states) {
if (!Array.isArray(states) || !states.length) {
return 'Brak statusów PrestaShop — najpierw przetestuj połączenie.';
@@ -59,6 +79,7 @@ module.exports = {
normalizeStatusId,
parseStatusMapping,
resolveStatusId,
resolvePsStateId,
formatPsStatesPreview,
extractPsStateName
};