-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread.js
More file actions
41 lines (37 loc) · 1.23 KB
/
Copy pathread.js
File metadata and controls
41 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import dotenv from 'dotenv';
import { create, Criteria } from 'shopware-admin-api-client';
import fs from 'fs';
async function main() {
dotenv.config();
let api = await create(process.env.SHOPWARE_API_URL, process.env.SHOPWARE_API_CLIENT_ID, process.env.SHOPWARE_API_CLIENT_SECRET);
await shopware(api)
}
async function shopware(api) {
let repository = api.create('product');
let criteria = new Criteria();
criteria.limit = 1;
criteria.addFilter(Criteria.equals('parentId', null));
// criteria.addFilter(Criteria.range('childCount', { gt: 0 }));
// criteria.addAssociation('children.cover');
while (true) {
const context = api.defaultContext();
context.inheritance = true;
let entities = await repository.search(criteria, context);
if (criteria.page < 2) {
console.log(`Entities total: ${entities.total} (limit: ${criteria.limit})`);
}
if (entities.length < 1) {
break;
}
console.log(`Page: ${criteria.page} / ${Math.ceil(entities.total / criteria.limit)}`);
for (const entity of entities) {
await handleEntity(entity)
}
criteria.page++;
break; // Optional: break after the first page
}
}
async function handleEntity(entity) {
console.log(entity.name);
}
main()