Skip to content

Commit 75da18c

Browse files
chore(export-order): set tiny id order in metafield
1 parent a9c7026 commit 75da18c

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

functions/lib/integration/export-order.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = ({ appSdk, storeId, auth }, tinyToken, queueEntry, appData, can
2424
return null
2525
}
2626
const tiny = new Tiny(tinyToken)
27+
let { metafields } = order
2728
console.log(`#${storeId} ${orderId} searching order ${order.number}`)
2829
if (getOrderUpdateType(order) === 'fulfillment') {
2930
const fulfillmentStatus = order.fulfillment_status && order.fulfillment_status.current
@@ -89,10 +90,23 @@ module.exports = ({ appSdk, storeId, auth }, tinyToken, queueEntry, appData, can
8990
pedido: {
9091
pedido: tinyOrder
9192
}
92-
}).then(({ status, registros }) => {
93+
}).then(async ({ status, registros }) => {
9394
if (status === 'OK' && registros && registros.registro) {
9495
const idTiny = registros.registro.id
9596
// DO NOT COPY TO v2
97+
if (!metafields) {
98+
metafields = []
99+
}
100+
metafields.push({
101+
_id: ecomUtils.randomObjectId(),
102+
namespace: 'tiny',
103+
field: 'tiny:id',
104+
value: String(idTiny)
105+
})
106+
await appSdk.apiRequest(storeId, `/orders/${orderId}.json`, 'PATCH', {
107+
metafields
108+
}, auth)
109+
.catch(console.error)
96110
getFirestore().doc(`exported_orders/${orderId}`)
97111
.set({
98112
storeId,

0 commit comments

Comments
 (0)