@things-factory/integration-sellercraft 4.1.40 → 4.2.2

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.
Files changed (25) hide show
  1. package/dist-server/constants/order-status-mapping.js +7 -3
  2. package/dist-server/constants/order-status-mapping.js.map +1 -1
  3. package/dist-server/constants/platform.js +2 -1
  4. package/dist-server/constants/platform.js.map +1 -1
  5. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js +17 -21
  6. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +2 -2
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +13 -5
  10. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  11. package/dist-server/routers/sellercraft-router.js +26 -11
  12. package/dist-server/routers/sellercraft-router.js.map +1 -1
  13. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +181 -19
  14. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
  15. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +23 -9
  16. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
  17. package/package.json +3 -3
  18. package/server/constants/order-status-mapping.ts +7 -3
  19. package/server/constants/platform.ts +2 -1
  20. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +17 -21
  21. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +3 -3
  22. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +19 -5
  23. package/server/routers/sellercraft-router.ts +27 -12
  24. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +186 -19
  25. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +24 -9
@@ -43,17 +43,27 @@ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation
43
43
  accessKey: shops[j].credential.consumer_key,
44
44
  accessSecret: shops[j].credential.consumer_secret,
45
45
  storeURL: shops[j].credential.store_url,
46
- platform: channels[i].name
46
+ platform: channels[i].name,
47
+ accessToken: shops[j].credential.access_token // Magento+
47
48
  };
48
49
  let countryCode = shops[j].country_code;
49
50
  let channelCode = shops[j].org_prefix;
50
51
  let organisationId = shops[j].account_id;
51
52
  let channelShopId = shops[j].channel_shop_id;
52
53
  var sellercraftStore = Object.assign(Object.assign({}, store), { platform: 'sellercraftChannelIntegration' });
53
- const productResult = await integration_marketplace_1.StoreAPI.getStoreProducts(store, {});
54
+ const productResult = [];
55
+ let totalPages = 1;
56
+ var limit = 50;
57
+ for (let page = 0; page < totalPages; page++) {
58
+ const { results, total } = await integration_marketplace_1.StoreAPI.getStoreProducts(store, {
59
+ pagination: { page, limit }
60
+ });
61
+ totalPages = Math.ceil(total / limit);
62
+ productResult.push(...results);
63
+ }
54
64
  const categoryResult = await integration_marketplace_1.StoreAPI.getStoreProductCategories(store, {});
55
- let mappedProducts = productResult.results.map(item => {
56
- let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item;
65
+ let mappedProducts = productResult.map(item => {
66
+ let { categoryId, itemId: productId, parentId, name, brand, isVerified, images, attributes, variations } = item;
57
67
  variations = variations.map(variation => {
58
68
  let { variationSku, variationId, name, isEnabled: isEnabled, isEnabled: isSellable, attributes, stockLocked, qty: stockReported, costPrice: fullPrice, sellPrice: priceDiscounted, length, width, height, weight } = variation;
59
69
  return {
@@ -86,7 +96,7 @@ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation
86
96
  ]
87
97
  };
88
98
  });
89
- images = images.map(image => {
99
+ images = images === null || images === void 0 ? void 0 : images.map(image => {
90
100
  return {
91
101
  url: image
92
102
  };
@@ -97,7 +107,7 @@ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation
97
107
  channelCode: channels[i].channelCode,
98
108
  channelCountry: shops[j].country_code,
99
109
  categoryId,
100
- productId,
110
+ productId: parentId || productId,
101
111
  name,
102
112
  brand,
103
113
  isVerified,
@@ -115,11 +125,15 @@ let MarketplaceChannelProductMutation = class MarketplaceChannelProductMutation
115
125
  isLeaf: parent == 0 ? false : true,
116
126
  isActive: isActive || true,
117
127
  channelCode,
118
- countryCode
128
+ countryCode,
129
+ childrenCategories: []
119
130
  };
120
131
  });
121
- mappedCategories.map(category => {
122
- category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId);
132
+ mappedCategories = mappedCategories.map(category => {
133
+ if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
134
+ category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId);
135
+ }
136
+ return category;
123
137
  });
124
138
  await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
125
139
  categories: mappedCategories
@@ -1 +1 @@
1
- {"version":3,"file":"marketplace-channel-product-mutation.js","sourceRoot":"","sources":["../../../server/service/marketplace-channel/marketplace-channel-product-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAsD;AACtD,qCAAuC;AAEvC,+DAA0D;AAE1D,6CAA4C;AAC5C,qFAAkE;AAClE,+GAAwG;AAGxG,IAAa,iCAAiC,GAA9C,MAAa,iCAAiC;IAE5C,KAAK,CAAC,iCAAiC,CAAQ,OAAY;QACzD,MAAM,mCAAmC,GAAG,YAAM,CAAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,CAAC,CAAA;QACjG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,mCAAmC,CAAA;QAE/F,MAAM,QAAQ,GAAyB,MAAM,IAAA,uBAAa,EAAC,wCAAkB,CAAC,CAAC,IAAI,EAAE,CAAA;QAErF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE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,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAA;aAC5G;YAED,OAAO,IAAI,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AA/IC;IADC,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC;IACY,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;0FA8I7C;AAhJU,iCAAiC;IAD7C,IAAA,uBAAQ,GAAE;GACE,iCAAiC,CAiJ7C;AAjJY,8EAAiC"}
1
+ {"version":3,"file":"marketplace-channel-product-mutation.js","sourceRoot":"","sources":["../../../server/service/marketplace-channel/marketplace-channel-product-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAsD;AACtD,qCAAuC;AAEvC,+DAA0D;AAE1D,6CAA4C;AAC5C,qFAAkE;AAClE,+GAAwG;AAGxG,IAAa,iCAAiC,GAA9C,MAAa,iCAAiC;IAE5C,KAAK,CAAC,iCAAiC,CAAQ,OAAY;QACzD,MAAM,mCAAmC,GAAG,YAAM,CAAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,CAAC,CAAA;QACjG,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,qBAAqB,EAAE,GAAG,mCAAmC,CAAA;QAE/F,MAAM,QAAQ,GAAyB,MAAM,IAAA,uBAAa,EAAC,wCAAkB,CAAC,CAAC,IAAI,EAAE,CAAA;QAErF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACxC,IAAI,gBAAgB,GAAG,qBAAqB,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YACrF,MAAM,eAAe,GAAQ,MAAM,KAAK,CAAC,gBAAgB,EAAE;gBACzD,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,WAAW,EAAE,MAAM;iBACpB;aACF,CAAC,CAAA;Y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,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;wBAC5E,QAAQ,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAA;qBAC5F;oBACD,OAAO,QAAQ,CAAA;gBACjB,CAAC,CAAC,CAAA;gBAEF,MAAM,sEAAgC,CAAC,uBAAuB,CAAC,gBAAgB,EAAE;oBAC/E,UAAU,EAAE,gBAAgB;iBAC7B,CAAC,CAAA;gBAEF,MAAM,sEAAgC,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAA;aAC5G;YAED,OAAO,IAAI,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AA9JC;IADC,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC;IACY,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;0FA6J7C;AA/JU,iCAAiC;IAD7C,IAAA,uBAAQ,GAAE;GACE,iCAAiC,CAgK7C;AAhKY,8EAAiC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-sellercraft",
3
- "version": "4.1.40",
3
+ "version": "4.2.2",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -31,7 +31,7 @@
31
31
  "@things-factory/context-ui": "^4.1.40",
32
32
  "@things-factory/grist-ui": "^4.1.40",
33
33
  "@things-factory/i18n-base": "^4.1.40",
34
- "@things-factory/integration-marketplace": "^4.1.40",
34
+ "@things-factory/integration-marketplace": "^4.2.2",
35
35
  "@things-factory/integration-ui": "^4.1.40",
36
36
  "@things-factory/more-ui": "^4.1.40",
37
37
  "@things-factory/resource-ui": "^4.1.40",
@@ -51,5 +51,5 @@
51
51
  "nock": "^13.0.2",
52
52
  "should": "^13.2.3"
53
53
  },
54
- "gitHead": "060b5c664e80a6fcba09598f2c7ceffe067e02bf"
54
+ "gitHead": "29a63a11161cd2b9692f9e9aafbf4d34b17a6a7b"
55
55
  }
@@ -1,6 +1,10 @@
1
1
  export const ORDER_STATUS = {
2
- pending: 'PENDING_PAYMENT',
3
- processing: 'CONFIRMED',
2
+ pending: 'PAYMENT_PENDING',
3
+ processing: 'PROCESSING',
4
4
  completed: 'DELIVERED',
5
- cancelled: 'CANCELLED'
5
+ cancelled: 'CANCELLED',
6
+ canceled: 'CANCELLED',
7
+ refunded: 'REFUND_COMPLETE',
8
+ failed: 'SHIPMENT_LOST_OR_DAMAGED',
9
+ refund: 'REFUND_COMPLETE'
6
10
  }
@@ -1,3 +1,4 @@
1
1
  export const PLATFORM = {
2
- WCM: 'woocommerce'
2
+ WCM: 'woocommerce',
3
+ MGT: 'magento'
3
4
  }
@@ -7,27 +7,7 @@ export function ingestChannelCategories() {
7
7
  denormalize(req) {
8
8
  const { categories } = req
9
9
 
10
- let newCategories = categories.map(category => {
11
- return {
12
- native_category_id: category.categoryId.toString(),
13
- channel_code: category.channelCode,
14
- channel_country: category.countryCode,
15
- category_name: category.categoryName,
16
- is_leaf: category.isLeaf,
17
- is_active: category.isActive,
18
- children_categories: category.childrenCategories.map(childrenCategory => {
19
- return {
20
- native_category_id: category.categoryId.toString(),
21
- channel_code: category.channelCode,
22
- channel_country: category.countryCode,
23
- category_name: childrenCategory.categoryName,
24
- is_leaf: childrenCategory.isLeaf,
25
- is_active: childrenCategory.isActive,
26
- children_categories: []
27
- }
28
- })
29
- }
30
- })
10
+ let newCategories = mapCategories(categories)
31
11
 
32
12
  return {
33
13
  payload: [...newCategories]
@@ -38,3 +18,19 @@ export function ingestChannelCategories() {
38
18
  }
39
19
  }
40
20
  }
21
+
22
+ function mapCategories(categories) {
23
+ if (!categories) return null
24
+ categories = categories.map(category => {
25
+ return {
26
+ native_category_id: category.categoryId.toString(),
27
+ channel_code: category.channelCode,
28
+ channel_country: category.countryCode,
29
+ category_name: category.categoryName,
30
+ is_leaf: category.isLeaf,
31
+ is_active: category.isActive,
32
+ children_categories: mapCategories(category.childrenCategories)
33
+ }
34
+ })
35
+ return categories
36
+ }
@@ -1,4 +1,4 @@
1
- /* https://docs.sellercraft.co/docs/api-integrations/b3A6MTY4NjQxODU-initiate-order-shipment */
1
+ /* https://docs.sellercraft.co/docs/api-integrations/b3A6MjQzODQ4OTg-ingest-channel-order */
2
2
 
3
3
  import { ORDER_STATUS } from '../../../constants'
4
4
 
@@ -49,7 +49,7 @@ export function ingestChannelOrder() {
49
49
  phone_1: order.billPhone1,
50
50
  phone_2: order.billPhone2
51
51
  },
52
- order_items: order.orderItems.map(orderItem => {
52
+ order_items: order.mappedOrderItems.map(orderItem => {
53
53
  return {
54
54
  native_item_id: orderItem.id.toString(),
55
55
  native_variant_id: orderItem.variationId.toString(),
@@ -73,7 +73,7 @@ export function ingestChannelOrder() {
73
73
  })
74
74
 
75
75
  return {
76
- payload: [ ...newOrders ]
76
+ payload: [...newOrders]
77
77
  }
78
78
  },
79
79
  normalize(res) {
@@ -13,9 +13,17 @@ export function ingestChannelProduct() {
13
13
  seller_sku: variant.variationSku,
14
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
18
  is_deleted: false, // default
19
+ variant_attributes: variant?.attributes
20
+ ? variant?.attributes.map(attribute => {
21
+ return {
22
+ ...attribute,
23
+ native_attribute_id: attribute.native_attribute_id.toString()
24
+ }
25
+ })
26
+ : [],
19
27
  stock_locked: variant?.stockLocked ? variant.stockLocked : 0,
20
28
  native_stock_reported: variant?.stockReported ? variant.stockReported : 0,
21
29
  price_full: variant.fullPrice || 0,
@@ -23,7 +31,7 @@ export function ingestChannelProduct() {
23
31
  inventory_products: variant?.inventoryProducts
24
32
  ? variant.inventoryProducts.map(inventoryProduct => {
25
33
  return {
26
- quantity: inventoryProduct.qty || 0,
34
+ quantity: inventoryProduct.qty || 1,
27
35
  name: inventoryProduct.name,
28
36
  inventory_sku: inventoryProduct.sku,
29
37
  product_versions: inventoryProduct?.productVersions
@@ -56,13 +64,19 @@ export function ingestChannelProduct() {
56
64
  native_product_id: product.productId.toString(),
57
65
  label: product.name,
58
66
  brand: product.brand || '',
59
- is_verified: product.isVerified,
67
+ is_verified: product.isVerified || true,
60
68
  flexible_attributes: product.channelCode == 'WCM' ? true : false, // add channels that do not support category_attributes ingestion
61
- images: product.images.map(image => {
69
+ images: product?.images.map(image => {
62
70
  return {
63
71
  file_url: image.url
64
72
  }
65
73
  }),
74
+ product_attributes: product?.attributes.map(attribute => {
75
+ return {
76
+ ...attribute,
77
+ native_attribute_id: attribute.native_attribute_id.toString()
78
+ }
79
+ }),
66
80
  variants: productVariations
67
81
  }
68
82
  })
@@ -39,22 +39,25 @@ sellercraftRouter.post('/sellercraft/store/update-product-price', async (context
39
39
  accessKey: store.shop.credential.consumer_key,
40
40
  accessSecret: store.shop.credential.consumer_secret,
41
41
  storeURL: store.shop.credential.store_url,
42
- platform: PLATFORM[`${store.shop.org_prefix}`]
42
+ platform: PLATFORM[`${store.shop.org_prefix}`],
43
+ accessToken: store.shop.credential.access_token
43
44
  }
44
45
 
45
- if (requestBody[i].native_variant_id) {
46
+ if (requestBody[i].native_variant_id != requestBody[i].native_product_id) {
46
47
  const req = {
47
48
  costPrice: requestBody[i].full_price,
48
49
  sellPrice: requestBody[i].sale_price,
49
50
  productId: requestBody[i].native_product_id,
50
- variationId: requestBody[i].native_variant_id
51
+ variationId: requestBody[i].native_variant_id,
52
+ variationSku: requestBody[i].sku
51
53
  }
52
54
  result = await StoreAPI.updateStoreProductVariationPrice(mappedStore, req)
53
55
  } else {
54
56
  const req = {
55
57
  costPrice: requestBody[i].full_price,
56
58
  sellPrice: requestBody[i].sale_price,
57
- productId: requestBody[i].native_product_id
59
+ productId: requestBody[i].native_product_id,
60
+ variationSku: requestBody[i].sku
58
61
  }
59
62
  result = await StoreAPI.updateStoreProductPrice(mappedStore, req)
60
63
  }
@@ -95,20 +98,25 @@ sellercraftRouter.post('/sellercraft/store/update-product-stock', async (context
95
98
  accessKey: store.shop.credential.consumer_key,
96
99
  accessSecret: store.shop.credential.consumer_secret,
97
100
  storeURL: store.shop.credential.store_url,
98
- platform: PLATFORM[`${store.shop.org_prefix}`]
101
+ platform: PLATFORM[`${store.shop.org_prefix}`],
102
+ accessToken: store.shop.credential.access_token
99
103
  }
100
104
 
101
- if (requestBody[i].native_variant_id) {
105
+ if (requestBody[i].native_variant_id != requestBody[i].native_product_id) {
102
106
  const req = {
103
107
  qty: requestBody[i].stock,
104
108
  itemId: requestBody[i].native_product_id,
105
- variationId: requestBody[i].native_variant_id
109
+ variationId: requestBody[i].native_variant_id,
110
+ distributors: requestBody[i].distributors || [], // for Magento
111
+ variationSku: requestBody[i].sku
106
112
  }
107
113
  result = await StoreAPI.updateStoreProductVariationStock(mappedStore, req)
108
114
  } else {
109
115
  const req = {
110
116
  qty: requestBody[i].stock,
111
- itemId: requestBody[i].native_product_id
117
+ itemId: requestBody[i].native_product_id,
118
+ distributors: requestBody[i].distributors || [], // for Magento
119
+ variationSku: requestBody[i].sku
112
120
  }
113
121
  result = await StoreAPI.updateStoreProductStock(mappedStore, req)
114
122
  }
@@ -147,10 +155,16 @@ sellercraftRouter.post('/sellercraft/store/update-order-status', async (context,
147
155
  accessKey: store.shop.credential.consumer_key,
148
156
  accessSecret: store.shop.credential.consumer_secret,
149
157
  storeURL: store.shop.credential.store_url,
150
- platform: PLATFORM[`${store.shop.org_prefix}`]
158
+ platform: PLATFORM[`${store.shop.org_prefix}`],
159
+ accessToken: store.shop.credential.access_token
151
160
  }
152
161
 
153
- const reqBody = { orderId: requestBody.native_order_id, status: requestBody.order_status }
162
+ const reqBody = {
163
+ orderId: requestBody.native_order_id,
164
+ status: requestBody.order_status,
165
+ carrier: requestBody?.shipper_last_mile,
166
+ trackingNo: requestBody?.tracking_number
167
+ }
154
168
 
155
169
  result = await StoreAPI.updateOrderStatus(mappedStore, reqBody)
156
170
  debug(result)
@@ -186,9 +200,10 @@ sellercraftRouter.post('/sellercraft/store/update-product-attribute', async (con
186
200
  accessKey: store.shop.credential.consumer_key,
187
201
  accessSecret: store.shop.credential.consumer_secret,
188
202
  storeURL: store.shop.credential.store_url,
189
- platform: PLATFORM[`${store.shop.org_prefix}`]
203
+ platform: PLATFORM[`${store.shop.org_prefix}`],
204
+ accessToken: store.shop.credential.access_token
190
205
  }
191
-
206
+
192
207
  let { product_sku: productSku, native_product_id: itemId, variants } = requestBody
193
208
 
194
209
  variants.map(variant => {
@@ -41,13 +41,14 @@ export class MarketplaceChannelOrderMutation {
41
41
  accessKey: shops[j].credential.consumer_key,
42
42
  accessSecret: shops[j].credential.consumer_secret,
43
43
  storeURL: shops[j].credential.store_url,
44
- platform: channels[i].name
44
+ platform: channels[i].name,
45
+ accessToken: shops[j].credential.access_token // Magento+
45
46
  }
46
47
 
47
48
  // let countryCode = shops[j].country_code
48
49
  // let channelCode = shops[j].org_prefix
49
- let organisationId = shops[j].credential.account_id
50
- let channelShopId = shops[j].credential.channel_shop_id
50
+ let organisationId = shops[j].account_id
51
+ let channelShopId = shops[j].channel_shop_id
51
52
 
52
53
  const orderReq = {
53
54
  fromDate: fromDate,
@@ -80,7 +81,7 @@ export class MarketplaceChannelOrderMutation {
80
81
  country: billCountry,
81
82
  phone: billPhone1,
82
83
  phone_2: billPhone2
83
- } = order.billing
84
+ } = order?.billing
84
85
 
85
86
  let {
86
87
  first_name: shipFirstName,
@@ -98,7 +99,7 @@ export class MarketplaceChannelOrderMutation {
98
99
  } = order.shipping
99
100
 
100
101
  let orderItems = order.orderItems.map(item => {
101
- let { name: id, variationId: variationId, slaExpiresAt, total, totalTax, subtotal, subtotalTax } = item
102
+ let { name: id, variationId: variationId, slaExpiresAt, total, totalTax, subtotal, subtotalTax, qty } = item
102
103
 
103
104
  return {
104
105
  id,
@@ -107,18 +108,159 @@ export class MarketplaceChannelOrderMutation {
107
108
  createdAt: order.orderCreatedAt,
108
109
  updatedAt: order.orderUpdatedAt,
109
110
  charges: [
111
+ {
112
+ name: 'CHARGES_MARKETING',
113
+ grossAmount: 0,
114
+ nettAmount: 0
115
+ },
116
+ {
117
+ name: 'CLAIMS_DAMAGE',
118
+ grossAmount: 0,
119
+ nettAmount: 0
120
+ },
121
+ {
122
+ name: 'CLAIMS_LOST',
123
+ grossAmount: 0,
124
+ nettAmount: 0
125
+ },
126
+ {
127
+ name: 'COMMISSION_PLATFORM',
128
+ grossAmount: 0,
129
+ nettAmount: 0
130
+ },
131
+ {
132
+ name: 'DEPOSIT_PRESALE',
133
+ grossAmount: 0,
134
+ nettAmount: 0
135
+ },
136
+ {
137
+ name: 'FEE_MISCELLANEOUS',
138
+ grossAmount: 0,
139
+ nettAmount: 0
140
+ },
141
+ {
142
+ name: 'FEE_TRANSACTION',
143
+ grossAmount: 0,
144
+ nettAmount: 0
145
+ },
110
146
  {
111
147
  name: 'PRICE_NORMAL_SELLING',
112
148
  grossAmount: total,
113
149
  nettAmount: subtotal
114
150
  },
151
+ {
152
+ name: 'PRICE_RECOMMENDED_RETAIL',
153
+ grossAmount: 0,
154
+ nettAmount: 0
155
+ },
156
+ {
157
+ name: 'PROMOTIONS_CUSTOMER_RECEIVED',
158
+ grossAmount: 0,
159
+ nettAmount: 0
160
+ },
161
+ {
162
+ name: 'PROMOTIONS_REBATE_PLATFORM',
163
+ grossAmount: 0,
164
+ nettAmount: 0
165
+ },
166
+ {
167
+ name: 'PROMOTIONS_REBATE_SELLER',
168
+ grossAmount: 0,
169
+ nettAmount: 0
170
+ },
171
+ {
172
+ name: 'REVERSAL_CHARGES_MARKETING',
173
+ grossAmount: 0,
174
+ nettAmount: 0
175
+ },
176
+ {
177
+ name: 'REVERSAL_COMMISSION',
178
+ grossAmount: 0,
179
+ nettAmount: 0
180
+ },
181
+ {
182
+ name: 'REVERSAL_FEE_MISCELLANEOUS',
183
+ grossAmount: 0,
184
+ nettAmount: 0
185
+ },
186
+ {
187
+ name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
188
+ grossAmount: 0,
189
+ nettAmount: 0
190
+ },
191
+ {
192
+ name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
193
+ grossAmount: 0,
194
+ nettAmount: 0
195
+ },
196
+ {
197
+ name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
198
+ grossAmount: 0,
199
+ nettAmount: 0
200
+ },
201
+ {
202
+ name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
203
+ grossAmount: 0,
204
+ nettAmount: 0
205
+ },
206
+ {
207
+ name: 'REVERSAL_SHIPPING_SELLER_PAID',
208
+ grossAmount: 0,
209
+ nettAmount: 0
210
+ },
211
+ {
212
+ name: 'SHIPPING_COST_TOTAL',
213
+ grossAmount: 0,
214
+ nettAmount: 0
215
+ },
216
+ {
217
+ name: 'SHIPPING_CUSTOMER_PAID',
218
+ grossAmount: 0,
219
+ nettAmount: 0
220
+ },
221
+ {
222
+ name: 'SHIPPING_REBATE_PLATFORM',
223
+ grossAmount: 0,
224
+ nettAmount: 0
225
+ },
226
+ {
227
+ name: 'SHIPPING_SELLER_PAID',
228
+ grossAmount: 0,
229
+ nettAmount: 0
230
+ },
115
231
  {
116
232
  name: 'TAXES',
117
233
  grossAmount: totalTax,
118
234
  nettAmount: subtotalTax
235
+ },
236
+ {
237
+ name: 'VOUCHERS_CUSTOMER_RECEIVED',
238
+ grossAmount: 0,
239
+ nettAmount: 0
240
+ },
241
+ {
242
+ name: 'VOUCHERS_REBATE_PLATFORM',
243
+ grossAmount: 0,
244
+ nettAmount: 0
245
+ },
246
+ {
247
+ name: 'VOUCHERS_REBATE_SELLER',
248
+ grossAmount: 0,
249
+ nettAmount: 0
119
250
  }
120
251
  ],
121
- slaExpiresAt
252
+ slaExpiresAt,
253
+ qty
254
+ }
255
+ })
256
+
257
+ let mappedOrderItems = []
258
+ orderItems.map(oi => {
259
+ for (let i = 0; i < oi.qty; i++) {
260
+ mappedOrderItems.push({
261
+ ...oi,
262
+ id: `${oi.id}-${i + 1}`
263
+ })
122
264
  }
123
265
  })
124
266
 
@@ -130,19 +272,19 @@ export class MarketplaceChannelOrderMutation {
130
272
  id,
131
273
  billFirstName,
132
274
  billLastName,
133
- billAddress1,
134
- billAddress2,
135
- billAddress3,
136
- billAddress4,
137
- billAddress5,
138
- billCity,
139
- billPostalCode,
140
- billCountry,
141
- billPhone1,
142
- billPhone2,
275
+ billAddress1: billAddress1.toString() || shipAddress1.toString(),
276
+ billAddress2: billAddress2 || shipAddress2,
277
+ billAddress3: billAddress3 || shipAddress3,
278
+ billAddress4: billAddress4 || shipAddress4,
279
+ billAddress5: billAddress5 || shipAddress5,
280
+ billCity: billCity || shipCity,
281
+ billPostalCode: billPostalCode || shipPostalCode,
282
+ billCountry: billCountry || shipCountry,
283
+ billPhone1: billPhone1 || shipPhone1,
284
+ billPhone2: billPhone2 || shipPhone2,
143
285
  shipFirstName,
144
286
  shipLastName,
145
- shipAddress1,
287
+ shipAddress1: shipAddress1.toString(),
146
288
  shipAddress2,
147
289
  shipAddress3,
148
290
  shipAddress4,
@@ -152,10 +294,11 @@ export class MarketplaceChannelOrderMutation {
152
294
  shipCountry,
153
295
  shipPhone1,
154
296
  shipPhone2,
155
- orderItems,
297
+ mappedOrderItems,
156
298
  channelShopId,
157
299
  organisationId,
158
- status
300
+ status,
301
+ charges: getOrderCharges(mappedOrderItems)
159
302
  }
160
303
  })
161
304
 
@@ -168,3 +311,27 @@ export class MarketplaceChannelOrderMutation {
168
311
  }
169
312
  }
170
313
  }
314
+
315
+ function getOrderCharges(mappedOrderItems) {
316
+ let chargesList = []
317
+
318
+ for (let i = 0; i < mappedOrderItems.length; i++) {
319
+ for (let j = 0; j < mappedOrderItems[i].charges.length; j++) {
320
+ let charge = mappedOrderItems[i].charges[j]
321
+ let foundCharge = chargesList.find(cl => cl.name == charge.name)
322
+ if (foundCharge) {
323
+ foundCharge.grossAmount = foundCharge.grossAmount + charge.grossAmount
324
+ foundCharge.nettAmount = foundCharge.nettAmount + charge.nettAmount
325
+ chargesList = chargesList.filter(cl => cl.name != charge.name)
326
+ } else {
327
+ foundCharge = {
328
+ name: charge.name,
329
+ grossAmount: charge.grossAmount,
330
+ nettAmount: charge.nettAmount
331
+ }
332
+ }
333
+ chargesList.push(foundCharge)
334
+ }
335
+ }
336
+ return chargesList
337
+ }