Initial commit: core-prestashop module v1.1.1

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
fatequod
2026-07-07 14:30:30 +02:00
co-authored by Cursor
commit f163100ad4
33 changed files with 2605 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
const { getOrderStatuses, searchOrders } = require('../../src/orders-api');
// status.get_with_counts — lista statusów zamówień (z core/orders) wraz z liczbą
// zamówień PrestaShop w każdym statusie. Wynik krótko cache'owany per firma,
// bo zlicza N zapytań (po jednym na status).
const cache = new Map();
const CACHE_TTL = 5000;
module.exports = async function(companyId, instanceId, params, ctx) {
const key = companyId?.toString?.() ?? companyId;
const now = Date.now();
const cached = cache.get(key);
if (cached && now - cached.ts < CACHE_TTL) {
return { data: cached.data };
}
const statuses = await getOrderStatuses(companyId);
const data = [];
for (const status of statuses) {
const statusId = status._id?.toString?.() ?? status._id;
const result = await searchOrders(companyId, {
statusId,
page: 1,
perPage: 1
});
data.push({
_id: statusId,
name: status.name ?? '',
color: status.color ?? 'secondary',
positionInGroup: status.positionInGroup ?? 0,
count: result.pagination?.total ?? 0
});
}
data.sort((a, b) => (a.positionInGroup ?? 0) - (b.positionInGroup ?? 0));
cache.set(key, { ts: now, data });
return { data };
};