@things-factory/integration-marketplace 3.7.11 → 3.8.11
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/controllers/lazada/apis/get-store-order-item-transaction-details.js +88 -0
- package/dist-server/controllers/lazada/apis/get-store-order-item-transaction-details.js.map +1 -0
- package/dist-server/controllers/lazada/apis/get-store-order-items.js +39 -7
- package/dist-server/controllers/lazada/apis/get-store-order-items.js.map +1 -1
- package/dist-server/controllers/lazada/apis/get-store-order.js +1 -0
- package/dist-server/controllers/lazada/apis/get-store-order.js.map +1 -1
- package/dist-server/controllers/lazada/apis/get-store-orders.js +2 -1
- package/dist-server/controllers/lazada/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/lazada/apis/index.js +1 -1
- package/dist-server/controllers/lazada/apis/index.js.map +1 -1
- package/dist-server/controllers/lazada/client/lazada.js +24 -4
- package/dist-server/controllers/lazada/client/lazada.js.map +1 -1
- package/dist-server/controllers/lazada/platform-action.js +18 -3
- package/dist-server/controllers/lazada/platform-action.js.map +1 -1
- package/dist-server/controllers/shopee/apis/get-store-order.js +2 -1
- package/dist-server/controllers/shopee/apis/get-store-order.js.map +1 -1
- package/dist-server/controllers/store-api/index.js +28 -0
- package/dist-server/controllers/store-api/index.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/get-store-order.js +21 -0
- package/dist-server/controllers/woocommerce/apis/get-store-order.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/get-store-orders.js +18 -5
- package/dist-server/controllers/woocommerce/apis/get-store-orders.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/get-store-product-categories.js +8 -44
- package/dist-server/controllers/woocommerce/apis/get-store-product-categories.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/index.js +10 -0
- package/dist-server/controllers/woocommerce/apis/index.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/update-order.js +37 -0
- package/dist-server/controllers/woocommerce/apis/update-order.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-product-attribute.js +20 -0
- package/dist-server/controllers/woocommerce/apis/update-product-attribute.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-price.js +23 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-price.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-stock.js +2 -2
- package/dist-server/controllers/woocommerce/apis/update-store-product-stock.js.map +1 -1
- package/dist-server/controllers/woocommerce/apis/update-store-product-variant-price.js +20 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variant-price.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variant-stock.js +20 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variant-stock.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js +23 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-price.js.map +1 -0
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-stock.js +3 -3
- package/dist-server/controllers/woocommerce/apis/update-store-product-variation-stock.js.map +1 -1
- package/dist-server/controllers/woocommerce/woocommerce.js +6 -2
- package/dist-server/controllers/woocommerce/woocommerce.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-setting/update-marketplace-setting.js +1 -1
- package/dist-server/graphql/resolvers/marketplace-setting/update-marketplace-setting.js.map +1 -1
- package/dist-server/routers/shopify-install-public-router.js +14 -4
- package/dist-server/routers/shopify-install-public-router.js.map +1 -1
- package/package.json +14 -14
- package/server/controllers/lazada/apis/get-store-order-item-transaction-details.ts +65 -0
- package/server/controllers/lazada/apis/get-store-order-items.ts +74 -6
- package/server/controllers/lazada/apis/get-store-order.ts +1 -0
- package/server/controllers/lazada/apis/get-store-orders.ts +2 -1
- package/server/controllers/lazada/apis/index.ts +1 -1
- package/server/controllers/lazada/client/lazada.ts +42 -12
- package/server/controllers/lazada/platform-action.ts +20 -1
- package/server/controllers/shopee/apis/get-store-order.ts +2 -1
- package/server/controllers/store-api/index.ts +15 -2
- package/server/controllers/woocommerce/apis/get-store-order.ts +17 -0
- package/server/controllers/woocommerce/apis/get-store-orders.ts +23 -5
- package/server/controllers/woocommerce/apis/get-store-product-categories.ts +6 -48
- package/server/controllers/woocommerce/apis/index.ts +10 -0
- package/server/controllers/woocommerce/apis/update-order.ts +36 -0
- package/server/controllers/woocommerce/apis/update-product-attribute.ts +17 -0
- package/server/controllers/woocommerce/apis/update-store-product-price.ts +20 -0
- package/server/controllers/woocommerce/apis/update-store-product-stock.ts +2 -2
- package/server/controllers/woocommerce/apis/update-store-product-variant-price.ts +17 -0
- package/server/controllers/woocommerce/apis/update-store-product-variant-stock.ts +18 -0
- package/server/controllers/woocommerce/apis/update-store-product-variation-price.ts +20 -0
- package/server/controllers/woocommerce/apis/update-store-product-variation-stock.ts +3 -3
- package/server/controllers/woocommerce/woocommerce.ts +6 -2
- package/server/graphql/resolvers/marketplace-setting/update-marketplace-setting.ts +1 -1
- package/server/routers/shopify-install-public-router.ts +18 -5
- package/dist-server/controllers/lazada/apis/get-store-order-item-payment-fee.js +0 -35
- package/dist-server/controllers/lazada/apis/get-store-order-item-payment-fee.js.map +0 -1
- package/server/controllers/lazada/apis/get-store-order-item-payment-fee.ts +0 -34
|
@@ -20,8 +20,11 @@ export function getStoreOrderItems() {
|
|
|
20
20
|
orderItemId: item.order_item_id,
|
|
21
21
|
orderCreatedAt: item.created_at
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
res[i]
|
|
23
|
+
let transactionDetails = await StoreAPI.getStoreOrderItemTransactionDetails(store, req)
|
|
24
|
+
res[i] = {
|
|
25
|
+
...res[i],
|
|
26
|
+
...transactionDetails
|
|
27
|
+
}
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
let results = res
|
|
@@ -41,12 +44,28 @@ export function getStoreOrderItems() {
|
|
|
41
44
|
paid_price: item.paid_price,
|
|
42
45
|
item_price: item.item_price,
|
|
43
46
|
payment_fee: item.payment_fee,
|
|
47
|
+
commission_fee: item.commission_fee,
|
|
48
|
+
promotional_charges: item.promotional_charges,
|
|
49
|
+
shipping_fee_paid_by_customer: item.shipping_fee_paid_by_customer,
|
|
50
|
+
item_price_credit: item.item_price_credit,
|
|
51
|
+
orders_marketplace_fees_total: item.orders_marketplace_fees_total,
|
|
52
|
+
orders_sales_total: item.orders_sales_total,
|
|
53
|
+
orders_marketing_fees_total: item.orders_marketing_fees_total,
|
|
54
|
+
orders_logistics_total: item.orders_logistics_total,
|
|
44
55
|
qty: 1,
|
|
45
56
|
shipment_provider: item.shipment_provider,
|
|
46
57
|
tracking_code: JSON.stringify(
|
|
47
58
|
item.tracking_code ? [{ order_item_id: item.order_item_id, tracking_code: item.tracking_code }] : []
|
|
48
59
|
),
|
|
49
|
-
status: item.status
|
|
60
|
+
status: item.status,
|
|
61
|
+
voucher_platform_lpi: item.voucher_platform_lpi,
|
|
62
|
+
voucher_seller_lpi: item.voucher_seller_lpi,
|
|
63
|
+
shipping_fee_discount_platform: item.shipping_fee_discount_platform,
|
|
64
|
+
shipping_fee_discount_seller: item.shipping_fee_discount_seller,
|
|
65
|
+
promotional_charges_flexi_combo: item.promotional_charges_flexi_combo,
|
|
66
|
+
auto_shipping_subsidy_marketplace: item.auto_shipping_subsidy_marketplace,
|
|
67
|
+
shipping_fee_original: item.shipping_fee_original,
|
|
68
|
+
tax_amount: item.tax_amount
|
|
50
69
|
}
|
|
51
70
|
|
|
52
71
|
newItem.push(data)
|
|
@@ -58,12 +77,29 @@ export function getStoreOrderItems() {
|
|
|
58
77
|
qty: existingItem.qty + 1,
|
|
59
78
|
paid_price: item.paid_price + existingItem.paid_price,
|
|
60
79
|
item_price: item.item_price + existingItem.item_price,
|
|
80
|
+
payment_fee: item.payment_fee + existingItem.payment_fee,
|
|
81
|
+
commission_fee: item.commission_fee + existingItem.commission_fee,
|
|
82
|
+
promotional_charges: item.promotional_charges + existingItem.promotional_charges,
|
|
83
|
+
shipping_fee_paid_by_customer: item.shipping_fee_paid_by_customer + existingItem.shipping_fee_paid_by_customer,
|
|
84
|
+
item_price_credit: item.item_price_credit + existingItem.item_price_credit,
|
|
85
|
+
orders_marketplace_fees_total: item.orders_marketplace_fees_total + existingItem.orders_marketplace_fees_total,
|
|
86
|
+
orders_sales_total: item.orders_sales_total + existingItem.orders_sales_total,
|
|
87
|
+
orders_marketing_fees_total: item.orders_marketing_fees_total + existingItem.orders_marketing_fees_total,
|
|
88
|
+
orders_logistics_total: item.orders_logistics_total + existingItem.orders_logistics_total,
|
|
61
89
|
tracking_code: item.tracking_code
|
|
62
90
|
? JSON.stringify([
|
|
63
91
|
...JSON.parse(existingItem.tracking_code),
|
|
64
92
|
{ order_item_id: item.order_item_id, tracking_code: item.tracking_code }
|
|
65
93
|
])
|
|
66
|
-
: existingItem.tracking_code
|
|
94
|
+
: existingItem.tracking_code,
|
|
95
|
+
voucher_platform_lpi: item.voucher_platform_lpi + existingItem.voucher_platform_lpi,
|
|
96
|
+
voucher_seller_lpi: item.voucher_seller_lpi + existingItem.voucher_seller_lpi,
|
|
97
|
+
shipping_fee_discount_platform: item.shipping_fee_discount_platform + existingItem.shipping_fee_discount_platform,
|
|
98
|
+
shipping_fee_discount_seller: item.shipping_fee_discount_seller + existingItem.shipping_fee_discount_seller,
|
|
99
|
+
promotional_charges_flexi_combo: item.promotional_charges_flexi_combo + existingItem.promotional_charges_flexi_combo,
|
|
100
|
+
auto_shipping_subsidy_marketplace: item.auto_shipping_subsidy_marketplace + existingItem.auto_shipping_subsidy_marketplace,
|
|
101
|
+
shipping_fee_original: item.shipping_fee_original + existingItem.shipping_fee_original,
|
|
102
|
+
tax_amount: item.tax_amount + existingItem.tax_amount
|
|
67
103
|
}
|
|
68
104
|
}
|
|
69
105
|
return newItem
|
|
@@ -83,7 +119,23 @@ export function getStoreOrderItems() {
|
|
|
83
119
|
tracking_code,
|
|
84
120
|
status,
|
|
85
121
|
item_price: originalPrice,
|
|
86
|
-
payment_fee: paymentFee
|
|
122
|
+
payment_fee: paymentFee,
|
|
123
|
+
commission_fee: commissionFee,
|
|
124
|
+
promotional_charges: promotionalCharges,
|
|
125
|
+
shipping_fee_paid_by_customer: shippingFeePaidByCustomer,
|
|
126
|
+
item_price_credit: itemPriceCredit,
|
|
127
|
+
orders_marketplace_fees_total: ordersMarketplaceFeesTotal,
|
|
128
|
+
orders_sales_total: ordersSalesTotal,
|
|
129
|
+
orders_marketing_fees_total: ordersMarketingFeesTotal,
|
|
130
|
+
orders_logistics_total: ordersLogisticsTotal,
|
|
131
|
+
voucher_platform_lpi: marketplaceBonus,
|
|
132
|
+
voucher_seller_lpi: marketplaceBonusSeller,
|
|
133
|
+
shipping_fee_discount_platform: shippingFeeDiscountMarketplace,
|
|
134
|
+
shipping_fee_discount_seller: shippingFeeDiscountSeller,
|
|
135
|
+
promotional_charges_flexi_combo: promotionalChargesFlexiCombo,
|
|
136
|
+
auto_shipping_subsidy_marketplace: autoShippingSubsidyMarketplace,
|
|
137
|
+
shipping_fee_original: originalShippingFee,
|
|
138
|
+
tax_amount: taxAmount
|
|
87
139
|
} = orderItem
|
|
88
140
|
var trackingNo = tracking_code === '' ? null : tracking_code
|
|
89
141
|
|
|
@@ -101,7 +153,23 @@ export function getStoreOrderItems() {
|
|
|
101
153
|
trackingNo,
|
|
102
154
|
status,
|
|
103
155
|
originalPrice,
|
|
104
|
-
paymentFee
|
|
156
|
+
paymentFee,
|
|
157
|
+
commissionFee,
|
|
158
|
+
promotionalCharges,
|
|
159
|
+
shippingFeePaidByCustomer,
|
|
160
|
+
itemPriceCredit,
|
|
161
|
+
ordersMarketplaceFeesTotal,
|
|
162
|
+
ordersSalesTotal,
|
|
163
|
+
ordersMarketingFeesTotal,
|
|
164
|
+
ordersLogisticsTotal,
|
|
165
|
+
marketplaceBonus,
|
|
166
|
+
marketplaceBonusSeller,
|
|
167
|
+
shippingFeeDiscountMarketplace,
|
|
168
|
+
shippingFeeDiscountSeller,
|
|
169
|
+
promotionalChargesFlexiCombo,
|
|
170
|
+
autoShippingSubsidyMarketplace,
|
|
171
|
+
originalShippingFee,
|
|
172
|
+
taxAmount
|
|
105
173
|
}
|
|
106
174
|
})
|
|
107
175
|
|
|
@@ -21,4 +21,4 @@ export * from './update-store-product-stock'
|
|
|
21
21
|
export * from './update-store-product-variation-stock'
|
|
22
22
|
export * from './update-store-product'
|
|
23
23
|
export * from './get-store-refund-orders'
|
|
24
|
-
export * from './get-store-order-item-
|
|
24
|
+
export * from './get-store-order-item-transaction-details'
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import FormData from 'form-data'
|
|
1
2
|
import fetch from 'node-fetch'
|
|
2
|
-
import {
|
|
3
|
+
import { getRepository } from 'typeorm'
|
|
4
|
+
|
|
5
|
+
import { MarketplaceStore } from '../../../entities'
|
|
3
6
|
import { makeSystemParameters } from './signature'
|
|
7
|
+
import { Endpoint, Parameter } from './types'
|
|
4
8
|
import { xmlize } from './xml'
|
|
5
|
-
import FormData from 'form-data'
|
|
6
9
|
|
|
7
10
|
export class Lazada {
|
|
8
11
|
endpoint: string
|
|
@@ -38,13 +41,13 @@ export class Lazada {
|
|
|
38
41
|
return await response.json()
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
async refreshAccessToken(payload: { refresh_token: string }) {
|
|
44
|
+
public static async refreshAccessToken(payload: { refresh_token: string }, appKey, appSecret, storeId) {
|
|
42
45
|
/* CONFIRM-ME not qualified */
|
|
43
46
|
const apiPath = '/auth/token/refresh'
|
|
44
47
|
|
|
45
48
|
const body = {
|
|
46
49
|
...payload,
|
|
47
|
-
...makeSystemParameters(
|
|
50
|
+
...makeSystemParameters(appKey, appSecret, apiPath, undefined, payload)
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
const response = await fetch(Endpoint.auth + apiPath, {
|
|
@@ -55,6 +58,25 @@ export class Lazada {
|
|
|
55
58
|
body: JSON.stringify(body)
|
|
56
59
|
})
|
|
57
60
|
|
|
61
|
+
const repository = getRepository(MarketplaceStore)
|
|
62
|
+
const store: MarketplaceStore = await repository.findOne({
|
|
63
|
+
where: { id: storeId }
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const refreshTokenInfo = await response.json()
|
|
67
|
+
const { access_token, refresh_token } = refreshTokenInfo
|
|
68
|
+
|
|
69
|
+
var patch = {
|
|
70
|
+
accessToken: access_token,
|
|
71
|
+
refreshToken: refresh_token,
|
|
72
|
+
accessInfo: JSON.stringify(refreshTokenInfo, null, 2)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await repository.save({
|
|
76
|
+
...store,
|
|
77
|
+
...patch
|
|
78
|
+
})
|
|
79
|
+
|
|
58
80
|
return await response.json()
|
|
59
81
|
}
|
|
60
82
|
|
|
@@ -72,6 +94,10 @@ export class Lazada {
|
|
|
72
94
|
}
|
|
73
95
|
})
|
|
74
96
|
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
throw response
|
|
99
|
+
}
|
|
100
|
+
|
|
75
101
|
return await response.json()
|
|
76
102
|
}
|
|
77
103
|
|
|
@@ -80,13 +106,13 @@ export class Lazada {
|
|
|
80
106
|
params.payload = xmlize(params.payload)
|
|
81
107
|
}
|
|
82
108
|
|
|
83
|
-
const {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
const { app_key, timestamp, access_token, sign_method, sign } = makeSystemParameters(
|
|
110
|
+
this.appKey,
|
|
111
|
+
this.appSecret,
|
|
112
|
+
path,
|
|
113
|
+
accessToken || this.accessToken,
|
|
114
|
+
params
|
|
115
|
+
)
|
|
90
116
|
|
|
91
117
|
const body = new FormData()
|
|
92
118
|
|
|
@@ -96,7 +122,7 @@ export class Lazada {
|
|
|
96
122
|
body.append('sign_method', sign_method)
|
|
97
123
|
body.append('sign', sign)
|
|
98
124
|
|
|
99
|
-
for(let key in params) {
|
|
125
|
+
for (let key in params) {
|
|
100
126
|
body.append(key, params[key])
|
|
101
127
|
}
|
|
102
128
|
|
|
@@ -106,6 +132,10 @@ export class Lazada {
|
|
|
106
132
|
body
|
|
107
133
|
})
|
|
108
134
|
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
throw response
|
|
137
|
+
}
|
|
138
|
+
|
|
109
139
|
return await response.json()
|
|
110
140
|
}
|
|
111
141
|
}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
+
import { config } from '@things-factory/env'
|
|
2
|
+
|
|
1
3
|
import { Lazada } from './client'
|
|
2
4
|
|
|
3
|
-
import { config } from '@things-factory/env'
|
|
4
5
|
const lazadaConfig = config.get('marketplaceIntegrationLazada', {})
|
|
5
6
|
const { appKey, appSecret } = lazadaConfig
|
|
6
7
|
|
|
7
8
|
export const action = async ({ store, method = 'get', path, request }) => {
|
|
9
|
+
try {
|
|
10
|
+
return await _action({ store, method, path, request })
|
|
11
|
+
} catch (ex) {
|
|
12
|
+
if (ex.code === 'IllegalAccessToken') {
|
|
13
|
+
var refreshStore = await Lazada.refreshAccessToken(
|
|
14
|
+
{ refresh_token: store.refreshToken },
|
|
15
|
+
appKey,
|
|
16
|
+
appSecret,
|
|
17
|
+
store.id
|
|
18
|
+
)
|
|
19
|
+
return await _action({ store: refreshStore, method, path, request })
|
|
20
|
+
} else {
|
|
21
|
+
throw ex
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const _action = async ({ store, method = 'get', path, request }) => {
|
|
8
27
|
const client = new Lazada(store.countryCode, appKey, appSecret)
|
|
9
28
|
|
|
10
29
|
var response = await client[method == 'post' ? 'post' : 'get'](path, request, store.accessToken)
|
|
@@ -76,7 +76,7 @@ export function getStoreOrder() {
|
|
|
76
76
|
}
|
|
77
77
|
})
|
|
78
78
|
|
|
79
|
-
const { full_address, zipcode: postCode, phone, country, city, name: attentionTo } = recipient_address
|
|
79
|
+
const { full_address, zipcode: postCode, phone, country, city, name: attentionTo, state } = recipient_address
|
|
80
80
|
|
|
81
81
|
var orderShipping = {
|
|
82
82
|
address1: full_address,
|
|
@@ -88,6 +88,7 @@ export function getStoreOrder() {
|
|
|
88
88
|
phone2: null,
|
|
89
89
|
postCode,
|
|
90
90
|
city,
|
|
91
|
+
state,
|
|
91
92
|
country: country === 'MY' ? 'Malaysia' : country,
|
|
92
93
|
collectionCurrency: null,
|
|
93
94
|
attentionTo,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
2
3
|
import { MarketplaceStore } from '../../entities'
|
|
3
4
|
import { api } from './decorators'
|
|
4
5
|
|
|
@@ -80,6 +81,9 @@ export class StoreAPI {
|
|
|
80
81
|
@api
|
|
81
82
|
static updateStoreProduct(store, req): any {}
|
|
82
83
|
|
|
84
|
+
@api
|
|
85
|
+
static updateOrder(store, req): any {}
|
|
86
|
+
|
|
83
87
|
@api
|
|
84
88
|
static cancelStoreOrder(store, req): any {}
|
|
85
89
|
|
|
@@ -156,14 +160,23 @@ export class StoreAPI {
|
|
|
156
160
|
static getStoreRefundOrders(store, req): any {}
|
|
157
161
|
|
|
158
162
|
@api
|
|
159
|
-
static getStoreRefundOrderDetails(store, req): any{}
|
|
163
|
+
static getStoreRefundOrderDetails(store, req): any {}
|
|
164
|
+
|
|
165
|
+
@api
|
|
166
|
+
static getStoreOrderItemPaymentFee(store, req): any {}
|
|
160
167
|
|
|
161
168
|
@api
|
|
162
|
-
static
|
|
169
|
+
static getStoreOrderItemTransactionDetails(store, req): any {}
|
|
163
170
|
|
|
164
171
|
@api
|
|
165
172
|
static updateProductAttribute(store, req): any {}
|
|
166
173
|
|
|
167
174
|
@api
|
|
168
175
|
static getStoreOrderTransactionDetails(store, req): any {}
|
|
176
|
+
|
|
177
|
+
@api
|
|
178
|
+
static updateStoreProductVariationPrice(store, req): any {}
|
|
179
|
+
|
|
180
|
+
@api
|
|
181
|
+
static updateStoreProductPrice(store, req): any {}
|
|
169
182
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#retrieve-an-order */
|
|
2
|
+
|
|
3
|
+
export function getStoreOrder() {
|
|
4
|
+
return {
|
|
5
|
+
method: 'get',
|
|
6
|
+
path: '/orders/{orderId}',
|
|
7
|
+
denormalize(req) {
|
|
8
|
+
var { orderId } = req
|
|
9
|
+
return {
|
|
10
|
+
resource: { orderId }
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
normalize(res) {
|
|
14
|
+
return res.items
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -17,7 +17,8 @@ export function getStoreOrders() {
|
|
|
17
17
|
|
|
18
18
|
var payload = {
|
|
19
19
|
offset: page * limit,
|
|
20
|
-
limit,
|
|
20
|
+
per_page: limit,
|
|
21
|
+
page: page + 1,
|
|
21
22
|
after,
|
|
22
23
|
before
|
|
23
24
|
}
|
|
@@ -26,9 +27,15 @@ export function getStoreOrders() {
|
|
|
26
27
|
},
|
|
27
28
|
async normalize(res, { store }) {
|
|
28
29
|
// return res.orders
|
|
29
|
-
var { items: orders,
|
|
30
|
+
var { items: orders, link } = res
|
|
30
31
|
let results: any[] = []
|
|
31
32
|
|
|
33
|
+
var more: boolean = false
|
|
34
|
+
|
|
35
|
+
if (link) {
|
|
36
|
+
more = checkNextPage(link)
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
for (var i = 0; i < orders.length; i++) {
|
|
33
40
|
const order = orders[i]
|
|
34
41
|
|
|
@@ -48,8 +55,8 @@ export function getStoreOrders() {
|
|
|
48
55
|
} = order
|
|
49
56
|
|
|
50
57
|
let docRefNo = orderNo
|
|
51
|
-
var orderCreatedAt = new Date(date_created_gmt)
|
|
52
|
-
var orderUpdatedAt = new Date(date_modified_gmt)
|
|
58
|
+
var orderCreatedAt = new Date(date_created_gmt)
|
|
59
|
+
var orderUpdatedAt = new Date(date_modified_gmt)
|
|
53
60
|
|
|
54
61
|
let orderItems = line_items.map(item => {
|
|
55
62
|
var { id: name, product_id, variation_id, quantity: qty, price } = item
|
|
@@ -132,7 +139,18 @@ export function getStoreOrders() {
|
|
|
132
139
|
})
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
return { results }
|
|
142
|
+
return { results, more }
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
145
|
}
|
|
146
|
+
|
|
147
|
+
function checkNextPage(link) {
|
|
148
|
+
let nextPage: boolean = false
|
|
149
|
+
|
|
150
|
+
// If there's a previous link, remove the first part of the string entirely
|
|
151
|
+
if (link.indexOf(`rel="next"`) > -1) {
|
|
152
|
+
nextPage = true
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return nextPage
|
|
156
|
+
}
|
|
@@ -1,58 +1,16 @@
|
|
|
1
1
|
/* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#list-all-products /wp-json/wc/v3/categoriess */
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function getStoreProductCategories() {
|
|
4
4
|
return {
|
|
5
5
|
method: 'get',
|
|
6
|
-
path: '/categories',
|
|
6
|
+
path: '/products/categories',
|
|
7
7
|
denormalize(req) {
|
|
8
|
-
|
|
9
|
-
var { page, limit } = pagination || { page: 0, limit: 100 }
|
|
10
|
-
|
|
11
|
-
var payload: any = {
|
|
12
|
-
per_page: limit,
|
|
13
|
-
offset: page * limit
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return { payload }
|
|
8
|
+
return { payload: {} }
|
|
17
9
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let results: any[] = []
|
|
22
|
-
const totalProducts = res.totalProducts
|
|
23
|
-
|
|
24
|
-
for (var i = 0; i < res.products.length; i++) {
|
|
25
|
-
const product: any = res.products[i]
|
|
26
|
-
const productVariations: any[] = product.variations
|
|
27
|
-
|
|
28
|
-
const result = {
|
|
29
|
-
itemId: product.id,
|
|
30
|
-
name: product.name,
|
|
31
|
-
type: product.type,
|
|
32
|
-
description: product.description,
|
|
33
|
-
hasVariation: true,
|
|
34
|
-
categoryId: product?.categories.length > 0 ? product.categories[0].id : null,
|
|
35
|
-
attributes: [],
|
|
36
|
-
variations: productVariations.map(variant => {
|
|
37
|
-
return {
|
|
38
|
-
variationId: variant.id,
|
|
39
|
-
variationSku: variant.sku,
|
|
40
|
-
channelSku: variant.sku,
|
|
41
|
-
name: product.name + ' (' + variant.attributes[0].options + ')',
|
|
42
|
-
qty: variant.stock_quantity,
|
|
43
|
-
primaryUnit: 'N/A',
|
|
44
|
-
primaryUnitValue: variant.weight,
|
|
45
|
-
costPrice: variant.price,
|
|
46
|
-
sellPrice: variant.sale_price,
|
|
47
|
-
attributes: variant.attributes
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
results.push({ ...result })
|
|
53
|
-
}
|
|
10
|
+
normalize(res, { store }) {
|
|
11
|
+
const { items, totalItems } = res
|
|
54
12
|
|
|
55
|
-
return { results, total:
|
|
13
|
+
return { results: items, total: totalItems }
|
|
56
14
|
}
|
|
57
15
|
}
|
|
58
16
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
export * from './echo'
|
|
2
2
|
export * from './create-order-note'
|
|
3
|
+
export * from './get-store-product-categories'
|
|
3
4
|
export * from './get-store-products'
|
|
4
5
|
export * from './get-store-product-variations'
|
|
5
6
|
export * from './get-store-orders'
|
|
6
7
|
export * from './update-store-product-stock'
|
|
7
8
|
export * from './update-store-product-variation-stock'
|
|
9
|
+
export * from './get-store-product-categories'
|
|
10
|
+
export * from './update-order'
|
|
11
|
+
export * from './update-product-attribute'
|
|
12
|
+
export * from './update-store-product-price'
|
|
13
|
+
export * from './update-store-product-variation-price'
|
|
14
|
+
export * from './get-store-order'
|
|
15
|
+
export * from './update-store-product-price'
|
|
16
|
+
export * from './update-store-product-variant-stock'
|
|
17
|
+
export * from './update-store-product-variant-price'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* https://woocommerce.github.io/woocommerce-rest-api-docs/#update-an-order */
|
|
2
|
+
/* /wp-json/wc/v3/orders/<id> */
|
|
3
|
+
|
|
4
|
+
import { StoreAPI } from '../../store-api'
|
|
5
|
+
|
|
6
|
+
export function updateOrder(req) {
|
|
7
|
+
return {
|
|
8
|
+
method: 'put',
|
|
9
|
+
path: '/orders/{orderId}',
|
|
10
|
+
async denormalize(req, { store }) {
|
|
11
|
+
var { status, orderId } = req || {}
|
|
12
|
+
|
|
13
|
+
const order = await StoreAPI.getStoreOrder(store, { orderId })
|
|
14
|
+
|
|
15
|
+
let orderStatus = status
|
|
16
|
+
if (orderStatus == 'PACKED') {
|
|
17
|
+
if (order.status == 'pending') {
|
|
18
|
+
orderStatus = 'on-hold'
|
|
19
|
+
} else {
|
|
20
|
+
orderStatus = order.status
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (orderStatus == 'READY_TO_SHIP') {
|
|
24
|
+
orderStatus = 'completed'
|
|
25
|
+
}
|
|
26
|
+
if (orderStatus == 'CANCELLED') {
|
|
27
|
+
orderStatus = 'cancelled'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { resource: { orderId: orderId }, payload: { status: orderStatus } }
|
|
31
|
+
},
|
|
32
|
+
normalize(res) {
|
|
33
|
+
return res.items
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* https://woocommerce.github.io/woocommerce-rest-api-docs/#update-a-product-attribute */
|
|
2
|
+
/* /wp-json/wc/v3/attributes/<id> */
|
|
3
|
+
|
|
4
|
+
export function updateProductAttribute(req) {
|
|
5
|
+
return {
|
|
6
|
+
method: 'put',
|
|
7
|
+
path: '/products/attributes/{attributeId}',
|
|
8
|
+
denormalize(req) {
|
|
9
|
+
var { name, attributeId } = req || {}
|
|
10
|
+
|
|
11
|
+
return { resource: { attributeId: attributeId }, payload: { name } }
|
|
12
|
+
},
|
|
13
|
+
normalize(res) {
|
|
14
|
+
return res
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product */
|
|
2
|
+
/* /wp-json/wc/v3/products/<id> */
|
|
3
|
+
|
|
4
|
+
export function updateStoreProductPrice(req) {
|
|
5
|
+
return {
|
|
6
|
+
method: 'put',
|
|
7
|
+
path: '/products/{itemId}',
|
|
8
|
+
denormalize(req) {
|
|
9
|
+
var { costPrice, sellPrice, productId } = req || {}
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
resource: { itemId: parseInt(productId) },
|
|
13
|
+
payload: { regular_price: costPrice?.toString(), sale_price: sellPrice?.toString() }
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
normalize(res) {
|
|
17
|
+
return res
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -6,12 +6,12 @@ export function updateStoreProductStock(req) {
|
|
|
6
6
|
method: 'put',
|
|
7
7
|
path: '/products/{itemId}',
|
|
8
8
|
denormalize(req) {
|
|
9
|
-
var { qty, itemId } = req
|
|
9
|
+
var { qty, itemId } = req || {}
|
|
10
10
|
|
|
11
11
|
return { resource: { itemId: parseInt(itemId) }, payload: { stock_quantity: qty, manage_stock: true } }
|
|
12
12
|
},
|
|
13
13
|
normalize(res) {
|
|
14
|
-
return res
|
|
14
|
+
return res
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
|
|
2
|
+
/* /wp-json/wc/v3/products/<product_id>/variations/<id> */
|
|
3
|
+
|
|
4
|
+
export function updateStoreProductVariantPrice(req) {
|
|
5
|
+
return {
|
|
6
|
+
method: 'put',
|
|
7
|
+
path: '/products/{itemId}/variations/{variantId}',
|
|
8
|
+
denormalize(req) {
|
|
9
|
+
var { cost_price, sell_price, product_id, variant_id } = req[0] || {}
|
|
10
|
+
|
|
11
|
+
return { resource: { itemId: parseInt(product_id), variantId: parseInt(variant_id) }, payload: { price: cost_price, sale_price: sell_price } }
|
|
12
|
+
},
|
|
13
|
+
normalize(res) {
|
|
14
|
+
return res.items
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
|
|
2
|
+
/* /wp-json/wc/v3/products/<product_id>/variations/<id> */
|
|
3
|
+
|
|
4
|
+
export function updateStoreProductVariantStock(req) {
|
|
5
|
+
return {
|
|
6
|
+
method: 'put',
|
|
7
|
+
path: '/products/{itemId}/variations/{variantId}',
|
|
8
|
+
denormalize(req) {
|
|
9
|
+
var { qty, product_id, variant_id } = req[0] || {}
|
|
10
|
+
|
|
11
|
+
return { resource: { itemId: parseInt(product_id), variantId: parseInt(variant_id) }, payload: { stock_quantity: qty, manage_stock: true } }
|
|
12
|
+
},
|
|
13
|
+
normalize(res) {
|
|
14
|
+
return res.items
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#update-a-product-variation */
|
|
2
|
+
/* /wp-json/wc/v3/products/<product_id>/variations/<id> */
|
|
3
|
+
|
|
4
|
+
export function updateStoreProductVariationPrice(req) {
|
|
5
|
+
return {
|
|
6
|
+
method: 'put',
|
|
7
|
+
path: '/products/{itemId}/variations/{variantId}',
|
|
8
|
+
denormalize(req) {
|
|
9
|
+
var { costPrice, sellPrice, productId, variationId } = req || {}
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
resource: { itemId: parseInt(productId), variantId: parseInt(variationId) },
|
|
13
|
+
payload: { regular_price: costPrice?.toString(), sale_price: sellPrice?.toString() }
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
normalize(res) {
|
|
17
|
+
return res
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|