feat(prestashop): sync mapped statuses from Orbito in 1.1.11
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user