Skip to content

Commit efb9f23

Browse files
committed
fix: must also receive product update webhooks
1 parent 4c9aa72 commit efb9f23

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

functions/ecom.config.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,15 @@ procedures.push({
249249
resource: 'products',
250250
action: 'create'
251251
},
252-
252+
{
253+
resource: 'products',
254+
field: 'price',
255+
},
256+
{
257+
resource: 'products',
258+
subresource: 'variations',
259+
field: 'price',
260+
},
253261
// Receive notifications when cart is created:
254262
{
255263
resource: 'carts',
@@ -260,19 +268,16 @@ procedures.push({
260268
resource: 'carts',
261269
field: 'completed',
262270
},
263-
264271
// Receive notifications when order change status:
265272
{
266273
resource: 'orders',
267274
field: 'financial_status',
268275
},
269-
270276
// Receive notifications when customer is created:
271277
{
272278
resource: 'customers',
273279
action: 'create',
274280
},
275-
276281
// Feel free to create custom combinations with any Store API resource, subresource, action and field.
277282
],
278283

functions/routes/ecom/webhook.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,22 @@ exports.post = ({ appSdk }, req, res) => {
4545
case 'orders':
4646
const orderId = trigger.inserted_id || trigger.resource_id
4747
if (orderId) {
48-
console.log(`Sending new order ${orderId} for #${storeId}`)
48+
console.log(`Sending order ${orderId} for #${storeId}`)
4949
promise = newOrder(orderId, storeId, appSdk, appData)
5050
}
5151
break
5252
case 'products':
53-
promise = appSdk
54-
.apiRequest(storeId, '/stores/me')
55-
.then(({ response }) => {
56-
const storeData = response.data
57-
const productBody = Object.assign({ _id: trigger.inserted_id }, trigger.body)
58-
return newProduct(productBody, storeData, storeId, appData, appSdk)
59-
})
53+
const productId = trigger.inserted_id || trigger.resource_id
54+
if (productId) {
55+
console.log(`Sending product ${productId} for #${storeId}`)
56+
promise = appSdk
57+
.apiRequest(storeId, '/stores/me')
58+
.then(({ response }) => {
59+
const storeData = response.data
60+
const productBody = Object.assign({ _id: trigger.inserted_id }, trigger.body)
61+
return newProduct(productBody, storeData, storeId, appData, appSdk)
62+
})
63+
}
6064
break
6165
case 'customers':
6266
// const customerBody = Object.assign({ _id: trigger.inserted_id }, trigger.body)

0 commit comments

Comments
 (0)