@things-factory/integration-sellercraft 5.0.0-alpha.7 → 5.0.0-y.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/constants/index.js +1 -0
- package/dist-server/constants/index.js.map +1 -1
- package/dist-server/constants/order-status-mapping.js +31 -0
- package/dist-server/constants/order-status-mapping.js.map +1 -0
- package/dist-server/constants/platform.js +4 -1
- package/dist-server/constants/platform.js.map +1 -1
- package/dist-server/controllers/index.js +2 -0
- package/dist-server/controllers/index.js.map +1 -1
- package/dist-server/controllers/sellercraft/sellercraft.js +2 -2
- package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/decorators.js +2 -0
- package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js +19 -20
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js +5 -2
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +29 -19
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +27 -41
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +18 -7
- package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
- package/dist-server/routers/sellercraft-router.js +221 -135
- package/dist-server/routers/sellercraft-router.js.map +1 -1
- package/dist-server/service/index.js +5 -1
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/marketplace-channel/index.js +9 -0
- package/dist-server/service/marketplace-channel/index.js.map +1 -0
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +366 -0
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -0
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +212 -0
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -0
- package/dist-server/service/marketplace-channel/marketplace-channel.js +88 -0
- package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -0
- package/dist-server/service/sellercraft/sellercraft-mutation.js +3 -6
- package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft.js +1 -1
- package/dist-server/utils/tokencraft-util.js +63 -0
- package/dist-server/utils/tokencraft-util.js.map +1 -0
- package/package.json +15 -15
- package/server/constants/index.ts +2 -1
- package/server/constants/order-status-mapping.ts +28 -0
- package/server/constants/platform.ts +4 -1
- package/server/controllers/index.ts +2 -0
- package/server/controllers/sellercraft/sellercraft.ts +2 -2
- package/server/controllers/sellercraft-api/decorators.ts +3 -0
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +19 -20
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts +6 -2
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +30 -19
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +34 -48
- package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +16 -7
- package/server/routers/sellercraft-router.ts +231 -147
- package/server/service/index.ts +6 -1
- package/server/service/marketplace-channel/index.ts +6 -0
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +418 -0
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +221 -0
- package/server/service/marketplace-channel/marketplace-channel.ts +68 -0
- package/server/service/sellercraft/sellercraft-mutation.ts +3 -3
- package/server/service/sellercraft/sellercraft-query.ts +1 -1
- package/server/service/sellercraft/sellercraft.ts +1 -1
- package/server/utils/tokencraft-util.ts +60 -0
@@ -11,35 +11,27 @@ export function ingestChannelProduct() {
|
|
11
11
|
let productVariations: any[] = product.variations.map(variant => {
|
12
12
|
return {
|
13
13
|
seller_sku: variant.variationSku,
|
14
|
-
native_variant_id: variant.variationId,
|
14
|
+
native_variant_id: variant.variationId.toString(),
|
15
15
|
label: variant.name,
|
16
|
-
is_enabled: variant.isEnabled,
|
17
|
-
is_sellable: variant.isSellable,
|
16
|
+
is_enabled: variant.isEnabled || true,
|
17
|
+
is_sellable: variant.isSellable || true,
|
18
|
+
is_deleted: false, // default
|
18
19
|
variant_attributes: variant?.attributes
|
19
|
-
? variant
|
20
|
+
? variant?.attributes.map(attribute => {
|
20
21
|
return {
|
21
|
-
|
22
|
-
|
22
|
+
...attribute,
|
23
|
+
native_attribute_id: attribute?.native_attribute_id?.toString()
|
23
24
|
}
|
24
25
|
})
|
25
26
|
: [],
|
26
27
|
stock_locked: variant?.stockLocked ? variant.stockLocked : 0,
|
27
28
|
native_stock_reported: variant?.stockReported ? variant.stockReported : 0,
|
28
|
-
price_full: variant.fullPrice,
|
29
|
-
price_discounted: variant.priceDiscounted,
|
30
|
-
price_discounts: variant?.product_discounts
|
31
|
-
? variant.product_discounts.map(discount => {
|
32
|
-
return {
|
33
|
-
price_discounted: discount.priceDiscounted,
|
34
|
-
native_discount_id: discount.id,
|
35
|
-
name: discount.name
|
36
|
-
}
|
37
|
-
})
|
38
|
-
: [],
|
29
|
+
price_full: variant.fullPrice || 0,
|
30
|
+
price_discounted: variant.priceDiscounted || variant.fullPrice || 0,
|
39
31
|
inventory_products: variant?.inventoryProducts
|
40
32
|
? variant.inventoryProducts.map(inventoryProduct => {
|
41
33
|
return {
|
42
|
-
quantity: inventoryProduct.qty,
|
34
|
+
quantity: inventoryProduct.qty || 0,
|
43
35
|
name: inventoryProduct.name,
|
44
36
|
inventory_sku: inventoryProduct.sku,
|
45
37
|
product_versions: inventoryProduct?.productVersions
|
@@ -59,7 +51,8 @@ export function ingestChannelProduct() {
|
|
59
51
|
: []
|
60
52
|
}
|
61
53
|
})
|
62
|
-
: []
|
54
|
+
: [],
|
55
|
+
extra_metadata: variant?.extraMetadata
|
63
56
|
}
|
64
57
|
})
|
65
58
|
|
@@ -68,43 +61,36 @@ export function ingestChannelProduct() {
|
|
68
61
|
channel_shop_id: product.channelShopId,
|
69
62
|
channel_code: product.channelCode,
|
70
63
|
channel_country: product.channelCountry,
|
71
|
-
native_category_id: product.categoryId,
|
72
|
-
native_product_id: product.productId,
|
64
|
+
native_category_id: product.categoryId.toString(),
|
65
|
+
native_product_id: product.productId.toString(),
|
73
66
|
label: product.name,
|
74
|
-
brand: product.brand,
|
75
|
-
is_verified: product.isVerified,
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
67
|
+
brand: product.brand || '',
|
68
|
+
is_verified: product.isVerified || true,
|
69
|
+
flexible_attributes: product.channelCode == 'WCM' || product.channelCode == 'MGT' || product.channelCode == 'SPF' ? true : false, // add channels that do not support category_attributes ingestion
|
70
|
+
images:
|
71
|
+
product?.images?.map(image => {
|
72
|
+
return {
|
73
|
+
file_url: image.url
|
74
|
+
}
|
75
|
+
}) || [],
|
76
|
+
product_attributes:
|
77
|
+
product?.attributes?.map(attribute => {
|
78
|
+
return {
|
79
|
+
...attribute,
|
80
|
+
native_attribute_id: attribute.native_attribute_id.toString()
|
81
|
+
}
|
82
|
+
}) || [],
|
83
|
+
variants: productVariations,
|
84
|
+
has_all_variants: product.channelCode == 'MGT' ? false : true
|
87
85
|
}
|
88
86
|
})
|
89
87
|
|
90
88
|
return {
|
91
|
-
payload:
|
89
|
+
payload: [...newProducts]
|
92
90
|
}
|
93
91
|
},
|
94
92
|
normalize(res) {
|
95
|
-
|
96
|
-
handover_type: handOverType,
|
97
|
-
pickup_time: pickupTime,
|
98
|
-
pickup_address: pickupAddress,
|
99
|
-
dropoff_address: dropoffAddress
|
100
|
-
} = res.data
|
101
|
-
|
102
|
-
return {
|
103
|
-
handOverType,
|
104
|
-
pickupTime,
|
105
|
-
pickupAddress,
|
106
|
-
dropoffAddress
|
107
|
-
}
|
93
|
+
return res
|
108
94
|
}
|
109
95
|
}
|
110
96
|
}
|
package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import fetch from 'node-fetch'
|
2
|
-
import
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
3
|
+
import { createPayloadLog } from '@things-factory/integration-base'
|
3
4
|
|
4
5
|
const debug = require('debug')('things-factory:integration-sellercraft:sellercraft')
|
5
6
|
|
@@ -21,7 +22,7 @@ export class SellercraftChannelIntegration {
|
|
21
22
|
}
|
22
23
|
|
23
24
|
generateRequestId() {
|
24
|
-
return
|
25
|
+
return uuidv4()
|
25
26
|
}
|
26
27
|
|
27
28
|
async post(path: string, data: any = {}) {
|
@@ -38,15 +39,21 @@ export class SellercraftChannelIntegration {
|
|
38
39
|
headers: {
|
39
40
|
'Content-Type': 'application/json',
|
40
41
|
request_id: requestId,
|
41
|
-
'
|
42
|
+
'X-Api-Key': apiKey
|
42
43
|
},
|
43
44
|
body: jsondata
|
44
45
|
})
|
45
46
|
|
47
|
+
const result = await response.json()
|
48
|
+
try {
|
49
|
+
createPayloadLog(JSON.parse(jsondata)[0]?.channel_shop_id || requestId, fullPath, jsondata, result, {
|
50
|
+
state: { domain: null }
|
51
|
+
})
|
52
|
+
} catch (e) {}
|
46
53
|
if (response.ok) {
|
47
|
-
return
|
54
|
+
return result
|
48
55
|
} else {
|
49
|
-
throw new Error(`
|
56
|
+
throw new Error(`(${response.status}) ${result.detail}`)
|
50
57
|
}
|
51
58
|
}
|
52
59
|
|
@@ -71,7 +78,8 @@ export class SellercraftChannelIntegration {
|
|
71
78
|
if (response.ok) {
|
72
79
|
return await response.json()
|
73
80
|
} else {
|
74
|
-
|
81
|
+
const result = await response.json()
|
82
|
+
throw new Error(`(${response.status}) ${result.message}`)
|
75
83
|
}
|
76
84
|
}
|
77
85
|
|
@@ -100,7 +108,8 @@ export class SellercraftChannelIntegration {
|
|
100
108
|
if (response.ok) {
|
101
109
|
return await response.json()
|
102
110
|
} else {
|
103
|
-
|
111
|
+
const result = await response.json()
|
112
|
+
throw new Error(`(${response.status}) ${result.message}`)
|
104
113
|
}
|
105
114
|
}
|
106
115
|
}
|
@@ -1,202 +1,286 @@
|
|
1
1
|
import Router from 'koa-router'
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
2
3
|
|
3
4
|
import { config } from '@things-factory/env'
|
4
5
|
import { StoreAPI } from '@things-factory/integration-marketplace'
|
5
|
-
import {
|
6
|
+
import { getShop } from '../utils/tokencraft-util'
|
7
|
+
|
8
|
+
import { SHIPPING_TYPE } from '../constants'
|
6
9
|
|
7
10
|
const debug = require('debug')('things-factory:integration-sellercraft:sellercraft-router')
|
8
11
|
|
9
12
|
export const sellercraftRouter = new Router()
|
10
13
|
|
11
14
|
sellercraftRouter.post('/sellercraft/store/update-product-price', async (context, next) => {
|
12
|
-
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
13
|
-
const { apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
|
14
|
-
|
15
|
-
const xApiKey = context.headers['x-api-key']
|
16
|
-
|
17
|
-
if (apiKey !== xApiKey) context.throw(400, 'api key validation failed')
|
18
|
-
|
19
15
|
const requestBody = context.request.body
|
20
16
|
|
21
17
|
for (var i = 0; i < requestBody.length; i++) {
|
22
|
-
|
18
|
+
let mappedStore: any = await getShop(context, requestBody[i].channel_id, requestBody[i].shop_id)
|
23
19
|
var result
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
try {
|
22
|
+
if (requestBody[i].variant.native_variant_id != requestBody[i].native_product_id) {
|
23
|
+
const req = {
|
24
|
+
costPrice: requestBody[i].variant.full_price,
|
25
|
+
sellPrice: requestBody[i].variant.sale_price,
|
26
|
+
productId: requestBody[i].native_product_id,
|
27
|
+
variationId: requestBody[i].variant.native_variant_id,
|
28
|
+
variationSku: requestBody[i].variant.sku,
|
29
|
+
context: { state: { domain: null } }
|
30
|
+
}
|
31
|
+
result = await StoreAPI.updateStoreProductVariationPrice(mappedStore, req)
|
32
|
+
} else {
|
33
|
+
const req = {
|
34
|
+
costPrice: requestBody[i].variant.full_price,
|
35
|
+
sellPrice: requestBody[i].variant.sale_price,
|
36
|
+
productId: requestBody[i].native_product_id,
|
37
|
+
variationSku: requestBody[i].variant.sku,
|
38
|
+
context: { state: { domain: null } }
|
39
|
+
}
|
40
|
+
result = await StoreAPI.updateStoreProductPrice(mappedStore, req)
|
32
41
|
}
|
33
|
-
})
|
34
|
-
if (response.ok) {
|
35
|
-
store = await response.json()
|
36
|
-
}
|
37
42
|
|
38
|
-
|
39
|
-
accessKey: store.shop.credential.consumer_key,
|
40
|
-
accessSecret: store.shop.credential.consumer_secret,
|
41
|
-
storeURL: store.shop.credential.store_url,
|
42
|
-
platform: PLATFORM[`${store.shop.org_prefix}`]
|
43
|
-
}
|
43
|
+
debug(result)
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
result = await StoreAPI.updateStoreProductVariationPrice(mappedStore, req)
|
53
|
-
} else {
|
54
|
-
const req = {
|
55
|
-
costPrice: requestBody[i].full_price,
|
56
|
-
sellPrice: requestBody[i].sale_price,
|
57
|
-
productId: requestBody[i].native_product_id
|
58
|
-
}
|
59
|
-
result = await StoreAPI.updateStoreProductPrice(mappedStore, req)
|
45
|
+
context.type = 'application/json'
|
46
|
+
context.status = 200
|
47
|
+
context.body = 'Succeeded'
|
48
|
+
} catch (e) {
|
49
|
+
context.type = 'application/json'
|
50
|
+
context.status = 500
|
51
|
+
context.body = e.message
|
60
52
|
}
|
61
|
-
|
62
|
-
debug(result)
|
63
53
|
}
|
64
|
-
|
65
|
-
context.status = 200
|
66
54
|
})
|
67
55
|
|
68
56
|
sellercraftRouter.post('/sellercraft/store/update-product-stock', async (context, next) => {
|
69
|
-
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
70
|
-
const { apiKey, tokenCraftUrl } = sellercraftChannelIntegrationConfig
|
71
|
-
|
72
|
-
const xApiKey = context.headers['x-api-key']
|
73
|
-
|
74
|
-
if (apiKey !== xApiKey) context.throw(400, 'api key validation failed')
|
75
|
-
|
76
57
|
const requestBody = context.request.body
|
77
58
|
for (var i = 0; i < requestBody.length; i++) {
|
78
|
-
|
59
|
+
let mappedStore: any = await getShop(context, requestBody[i].channel_id, requestBody[i].shop_id)
|
79
60
|
var result
|
80
61
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
62
|
+
try {
|
63
|
+
if (requestBody[i].variant.native_variant_id != requestBody[i].native_product_id) {
|
64
|
+
const req = {
|
65
|
+
qty: requestBody[i].variant.stock,
|
66
|
+
itemId: requestBody[i].native_product_id,
|
67
|
+
variationId: requestBody[i].variant.native_variant_id,
|
68
|
+
distributors: requestBody[i].distributors || [], // for Magento
|
69
|
+
variationSku: requestBody[i].variant.sku,
|
70
|
+
locationId: requestBody[i]?.variant?.extra_metadata?.locationId, // for Shopify
|
71
|
+
inventoryItemId: requestBody[i]?.variant?.extra_metadata?.inventoryItemId, // for Shopify
|
72
|
+
context: { state: { domain: null } }
|
73
|
+
}
|
74
|
+
if (req.locationId) {
|
75
|
+
let location = JSON.parse(req.locationId)
|
76
|
+
req.qty -= await StoreAPI.getStoreProductVariationStock(mappedStore, { variantId: req.variationId })
|
77
|
+
req.locationId = location[0].location_id
|
78
|
+
}
|
79
|
+
result = await StoreAPI.updateStoreProductVariationStock(mappedStore, req)
|
80
|
+
} else {
|
81
|
+
const req = {
|
82
|
+
qty: requestBody[i].variant.stock,
|
83
|
+
itemId: requestBody[i].native_product_id,
|
84
|
+
distributors: requestBody[i].distributors || [], // for Magento
|
85
|
+
variationSku: requestBody[i].variant.sku,
|
86
|
+
context: { state: { domain: null } }
|
87
|
+
}
|
88
|
+
result = await StoreAPI.updateStoreProductStock(mappedStore, req)
|
88
89
|
}
|
89
|
-
})
|
90
|
-
if (response.ok) {
|
91
|
-
store = await response.json()
|
92
|
-
}
|
93
90
|
|
94
|
-
|
95
|
-
accessKey: store.shop.credential.consumer_key,
|
96
|
-
accessSecret: store.shop.credential.consumer_secret,
|
97
|
-
storeURL: store.shop.credential.store_url,
|
98
|
-
platform: PLATFORM[`${store.shop.org_prefix}`]
|
99
|
-
}
|
91
|
+
debug(result)
|
100
92
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
} else {
|
109
|
-
const req = {
|
110
|
-
qty: requestBody[i].stock,
|
111
|
-
itemId: requestBody[i].native_product_id
|
112
|
-
}
|
113
|
-
result = await StoreAPI.updateStoreProductStock(mappedStore, req)
|
93
|
+
context.type = 'application/json'
|
94
|
+
context.status = 200
|
95
|
+
context.body = 'Succeeded'
|
96
|
+
} catch (e) {
|
97
|
+
context.type = 'application/json'
|
98
|
+
context.status = 500
|
99
|
+
context.body = e.message
|
114
100
|
}
|
115
|
-
|
116
|
-
debug(result)
|
117
101
|
}
|
118
|
-
context.status = 200
|
119
102
|
})
|
120
103
|
|
121
104
|
sellercraftRouter.post('/sellercraft/store/update-order-status', async (context, next) => {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
105
|
+
try {
|
106
|
+
const requestBody = context.request.body
|
107
|
+
var result: any = {}
|
108
|
+
let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)
|
109
|
+
|
110
|
+
const reqBody = {
|
111
|
+
orderId: requestBody.native_order_id,
|
112
|
+
status: requestBody.order_status,
|
113
|
+
carrier: requestBody?.shipper_last_mile,
|
114
|
+
trackingNo: requestBody?.tracking_number,
|
115
|
+
orderItems: unmapOrderItems(
|
116
|
+
requestBody?.order_items.map(oi => {
|
117
|
+
return oi.native_order_item_id
|
118
|
+
}) || []
|
119
|
+
),
|
120
|
+
isSOF: requestBody?.seller_logistics,
|
121
|
+
locations:
|
122
|
+
mappedStore.platform == 'shopify'
|
123
|
+
? requestBody?.order_items.map(oi => {
|
124
|
+
let jsonLocation = oi.extra_metadata.locationId
|
125
|
+
return JSON.parse(jsonLocation)[0].location_id
|
126
|
+
})
|
127
|
+
: null,
|
128
|
+
context: { state: { domain: null } }
|
129
|
+
}
|
126
130
|
|
127
|
-
|
131
|
+
let responseBody: any = { operation_id: uuidv4() }
|
132
|
+
try {
|
133
|
+
try {
|
134
|
+
result = (await StoreAPI.updateOrderStatus(mappedStore, reqBody)) || {}
|
135
|
+
debug(result)
|
136
|
+
} catch (e) {
|
137
|
+
if (e?.requiredDocument) result.requiredDocument = e.requiredDocument
|
138
|
+
}
|
128
139
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
140
|
+
if (result?.requiredDocument) {
|
141
|
+
// call document api and ingest channel order package
|
142
|
+
const order: any = await StoreAPI.getStoreOrder(mappedStore, { orderId: reqBody.orderId })
|
143
|
+
let orderPackage: any = order ? (order[0]?.orderPackage ? order[0].orderPackage : {}) : {}
|
144
|
+
if (orderPackage) {
|
145
|
+
const packageId: string = orderPackage.packageId
|
146
|
+
|
147
|
+
let orderDocument: any = orderPackage.orderDocument
|
148
|
+
if (orderDocument?.length == 0) {
|
149
|
+
let hasDocument: boolean = false
|
150
|
+
while (!hasDocument) {
|
151
|
+
orderDocument = await StoreAPI.getStoreOrderDocument(mappedStore, { packageId, documentType: 1 })
|
152
|
+
if (orderDocument?.length > 0) {
|
153
|
+
hasDocument = true
|
154
|
+
break
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
// Order Package Payload
|
160
|
+
let newOrderPackage: any =
|
161
|
+
{
|
162
|
+
channel_shop_id: mappedStore.channelShopId,
|
163
|
+
native_order_id: reqBody.orderId,
|
164
|
+
native_package_id: orderPackage.packageId.toString(),
|
165
|
+
shipping_tracking_code: orderPackage.trackingNumber,
|
166
|
+
shipping_type_value: orderPackage?.shippingType ? orderPackage.shippingType : SHIPPING_TYPE.DROP_SHIPPING,
|
167
|
+
warehouse_code: SHIPPING_TYPE.DROP_SHIPPING,
|
168
|
+
shipper: {
|
169
|
+
name: orderPackage.shippingProvider,
|
170
|
+
is_cod_supported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
|
171
|
+
},
|
172
|
+
documents:
|
173
|
+
orderDocument?.map(doc => {
|
174
|
+
return {
|
175
|
+
file: doc.file,
|
176
|
+
file_type_value: doc.fileTypeValue,
|
177
|
+
mime_type: doc.mimeType
|
178
|
+
}
|
179
|
+
}) || [],
|
180
|
+
shipper_last_mile: {
|
181
|
+
name: orderPackage.shippingProvider,
|
182
|
+
is_cod_supported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
|
183
|
+
},
|
184
|
+
order_item_ids: orderPackage?.orderListIdList
|
185
|
+
? orderPackage.orderListIdList
|
186
|
+
: reqBody.orderItems.map(oi => {
|
187
|
+
return oi.order_item_id
|
188
|
+
})
|
189
|
+
} || {}
|
190
|
+
|
191
|
+
responseBody.package = newOrderPackage
|
192
|
+
}
|
193
|
+
responseBody.response_code = 'E0'
|
194
|
+
responseBody.message = 'Success'
|
195
|
+
}
|
145
196
|
|
146
|
-
|
147
|
-
accessKey: store.shop.credential.consumer_key,
|
148
|
-
accessSecret: store.shop.credential.consumer_secret,
|
149
|
-
storeURL: store.shop.credential.store_url,
|
150
|
-
platform: PLATFORM[`${store.shop.org_prefix}`]
|
151
|
-
}
|
197
|
+
responseBody.time = Math.floor(new Date(new Date().toUTCString()).getTime() / 1000)
|
152
198
|
|
153
|
-
|
199
|
+
context.type = 'application/json'
|
200
|
+
context.status = 200
|
201
|
+
context.body = responseBody
|
154
202
|
|
155
|
-
|
156
|
-
|
203
|
+
await next()
|
204
|
+
} catch (e) {
|
205
|
+
responseBody.response_code = 'E1'
|
206
|
+
responseBody.message = e.message
|
157
207
|
|
158
|
-
|
208
|
+
context.type = 'application/json'
|
209
|
+
context.status = 500
|
210
|
+
context.body = responseBody
|
211
|
+
}
|
212
|
+
} catch (e) {}
|
159
213
|
})
|
160
214
|
|
161
215
|
sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (context, next) => {
|
162
|
-
const
|
163
|
-
|
216
|
+
const requestBody = context.request.body
|
217
|
+
let mappedStore: any = await getShop(context, requestBody.channel_id, requestBody.shop_id)
|
164
218
|
|
165
|
-
|
219
|
+
let { product_sku: productSku, native_product_id: itemId, variants } = requestBody
|
166
220
|
|
167
|
-
|
221
|
+
variants.map(variant => {
|
222
|
+
let { variant_sku: variantSku, native_variant_id: variantId, attributes } = variant
|
168
223
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
224
|
+
attributes.map(attribute => {
|
225
|
+
let { native_attribute_id: id, attribute_key: name, attribute_value: value } = attribute
|
226
|
+
|
227
|
+
return {
|
228
|
+
id,
|
229
|
+
name,
|
230
|
+
value
|
231
|
+
}
|
232
|
+
})
|
233
|
+
|
234
|
+
return {
|
235
|
+
variantSku,
|
236
|
+
variantId,
|
237
|
+
attributes
|
180
238
|
}
|
181
239
|
})
|
182
|
-
if (response.ok) {
|
183
|
-
store = await response.json()
|
184
|
-
}
|
185
240
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
241
|
+
for (var i = 0; i < variants.length; i++) {
|
242
|
+
try {
|
243
|
+
let variant = variants[i]
|
244
|
+
await StoreAPI.updateProductAttribute(mappedStore, {
|
245
|
+
productSku,
|
246
|
+
itemId,
|
247
|
+
variant,
|
248
|
+
context: { state: { domain: null } }
|
249
|
+
})
|
250
|
+
context.type = 'application/json'
|
251
|
+
context.status = 200
|
252
|
+
context.body = 'Succeeded'
|
253
|
+
} catch (e) {
|
254
|
+
context.type = 'application/json'
|
255
|
+
context.status = 500
|
256
|
+
context.body = e.message
|
257
|
+
}
|
191
258
|
}
|
259
|
+
})
|
260
|
+
|
261
|
+
function unmapOrderItems(orderItems) {
|
262
|
+
let itemsList = []
|
263
|
+
let res = orderItems.map(e => {
|
264
|
+
return e.split('-')[0]
|
265
|
+
})
|
266
|
+
|
267
|
+
for (let item of res) {
|
268
|
+
let count = 0
|
192
269
|
|
193
|
-
|
194
|
-
|
195
|
-
|
270
|
+
res.forEach(element => {
|
271
|
+
if (element === item) {
|
272
|
+
count += 1
|
273
|
+
}
|
274
|
+
})
|
196
275
|
|
197
|
-
|
276
|
+
itemsList.push({
|
277
|
+
order_item_id: item,
|
278
|
+
qty: count
|
198
279
|
})
|
199
|
-
|
280
|
+
}
|
200
281
|
|
201
|
-
|
202
|
-
|
282
|
+
itemsList = itemsList.filter(
|
283
|
+
(value, index, self) => index === self.findIndex(t => t.order_item_id === value.order_item_id)
|
284
|
+
)
|
285
|
+
return itemsList
|
286
|
+
}
|
package/server/service/index.ts
CHANGED
@@ -3,10 +3,12 @@ export * from './sellercraft/sellercraft'
|
|
3
3
|
|
4
4
|
/* IMPORT ENTITIES AND RESOLVERS */
|
5
5
|
import { entities as SellercraftEntities, resolvers as SellercraftResolvers } from './sellercraft'
|
6
|
+
import { entities as MarketplaceChannelEntities, resolvers as MarketplaceSellercraftResolvers } from './marketplace-channel'
|
6
7
|
|
7
8
|
export const entities = [
|
8
9
|
/* ENTITIES */
|
9
10
|
...SellercraftEntities,
|
11
|
+
...MarketplaceChannelEntities
|
10
12
|
]
|
11
13
|
|
12
14
|
|
@@ -14,5 +16,8 @@ export const schema = {
|
|
14
16
|
resolverClasses: [
|
15
17
|
/* RESOLVER CLASSES */
|
16
18
|
...SellercraftResolvers,
|
17
|
-
|
19
|
+
...MarketplaceSellercraftResolvers
|
20
|
+
]
|
18
21
|
}
|
22
|
+
|
23
|
+
export { MarketplaceSellercraftResolvers }
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { MarketplaceChannel } from './marketplace-channel'
|
2
|
+
import { MarketplaceChannelOrderMutation } from './marketplace-channel-order-mutation'
|
3
|
+
import { MarketplaceChannelProductMutation } from './marketplace-channel-product-mutation'
|
4
|
+
|
5
|
+
export const entities = [MarketplaceChannel]
|
6
|
+
export const resolvers = [MarketplaceChannelOrderMutation, MarketplaceChannelProductMutation]
|