Skip to content

Commit 887479b

Browse files
chore: update current metafield with new id
1 parent 8f05e41 commit 887479b

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

functions/lib/integration/export-order.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,17 @@ module.exports = ({ appSdk, storeId, auth }, tinyToken, queueEntry, appData, can
9999
if (!metafields) {
100100
metafields = []
101101
}
102-
metafields.push({
103-
_id: ecomUtils.randomObjectId(),
104-
namespace: 'tiny',
105-
field: 'tiny:id',
106-
value: String(idTiny)
107-
})
102+
const tinyIdIndex = metafields.findIndex(({field}) => field === 'tiny:id')
103+
if (tinyIdIndex > -1) {
104+
metafields[tinyIdIndex].value = String(idTiny)
105+
} else {
106+
metafields.push({
107+
_id: ecomUtils.randomObjectId(),
108+
namespace: 'tiny',
109+
field: 'tiny:id',
110+
value: String(idTiny)
111+
})
112+
}
108113
if (appData.tiny_order_data && appData.tiny_order_data.id_ecommerce) {
109114
metafields.push({
110115
_id: ecomUtils.randomObjectId(),

0 commit comments

Comments
 (0)