Skip to content

Commit

Permalink
feat(ecom-config): add option to send review after paid as asked by ov
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgnreis authored Apr 3, 2024
1 parent 45f5d26 commit e2c7e3d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 13 additions & 0 deletions functions/ecom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ const app = {
description: 'Escolha a opções correta ou o envio dos pedidos pode não funcionar corretamente.',
},
hide: true
},
send_order_paid: {
schema: {
type: 'boolean',
default: false,
title: 'Enviar pedido para Opiniões Verificadas após aprovação do pedido',
description: 'Caso ativado, o pedido será enviado assim que aprovado e não mais ao mudar status para entregue',
},
hide: true
}
}
}
Expand All @@ -121,6 +130,10 @@ procedures.push({
{
resource: 'orders',
field: 'fulfillment_status',
},
{
resource: 'orders',
field: 'financial_status',
}
],

Expand Down
16 changes: 10 additions & 6 deletions functions/routes/ecom/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ exports.post = async ({ appSdk, admin }, req, res) => {
return appSdk.apiRequest(storeId, `orders/${resourceId}.json`).then(({ response }) => ({ response, configObj }))
}).then(({ response, configObj }) => {
const { data } = response
// skip if not delivered
if (!data.fulfillment_status ||
!data.fulfillment_status.current ||
data.fulfillment_status.current !== 'delivered') {
const sendOrderPaid = configObj.send_order_paid &&
data.financial_status &&
data.financial_status.current === 'paid'

if (sendOrderPaid ||
(data.fulfillment_status && data.fulfillment_status.current === 'delivered')
) {
return sendReviews(storeId, appSdk, data, configObj)
} else {
// skip if not delivered or paid
return res.send(ECHO_SKIP)
}

return sendReviews(storeId, appSdk, data, configObj)
}).then((result) => {
console.log('Pedidos enviados com sucesso', {
result,
Expand Down

0 comments on commit e2c7e3d

Please sign in to comment.