-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (49 loc) · 1.44 KB
/
index.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import dotenv from 'dotenv';
import Shopify from 'shopify-api-node';
import axios from 'axios';
dotenv.config();
const shopify = new Shopify({
shopName: process.env.SHOPIFY_SHOP_NAME,
apiKey: process.env.SHOPIFY_API_KEY,
password: process.env.SHOPIFY_API_PASSWORD
});
const shopwareApi = axios.create({
baseURL: process.env.SHOPWARE_API_URL,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${process.env.SHOPWARE_ACCESS_KEY}`
}
});
async function exportShopifyProducts() {
try {
const products = await shopify.product.list();
console.log('Exported Shopify products:', products.length);
return products;
} catch (error) {
console.error('Error exporting Shopify products:', error);
}
}
function mapProducts(shopifyProducts) {
return shopifyProducts.map(product => ({
name: product.title,
description: product.body_html,
// Add more mappings as needed
}));
}
async function importToShopware(mappedProducts) {
try {
for (const product of mappedProducts) {
await shopwareApi.post('/product', product);
}
console.log('Products imported to Shopware successfully');
} catch (error) {
console.error('Error importing to Shopware:', error);
}
}
async function main() {
const shopifyProducts = await exportShopifyProducts();
const mappedProducts = mapProducts(shopifyProducts);
await importToShopware(mappedProducts);
}
main();