Hooks on Wix-store 'Orders'

Hi,
I’m trying to capture some of the data in in ‘Orders’ collection transaction (Wix Store) ,as it occur, by using the ‘After Insert’ hook on the ‘Orders’ collection.

My wish is to capture 4-5 fields from the transaction and insert it in to a collection (“order status”) I have created (The field that I need are ‘number’,orderDate, ‘fulfillmentStatus’, ‘paymentStatus’).

I tried to understand wixData and hooks (I’m not experienced with web development) and here what I thought will work in the Hook:

import wixData from ‘wix-data’;

export function Stores$Orders_afterInsert(item, context) {
let CurrenRecord=wixData.currentData;

let toInsert = {
“title”: CurrenRecord(‘number’),
“age”: CurrenRecord(‘_dateCreated’),
“orderStatus”: CurrenRecord(‘fulfillmentStatus’),
“paymentStatus”: CurrenRecord(‘paymentStatus’)
};
wixData.insert(“Order_Management”, toInsert)
.then( (results) => {
let parit = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
} );

}

I also tried this:

import wixData from ‘wix-data’;

export function Stores$Orders_afterInsert(item, context) {
let CurrenRecord=wixData.currentData;
let toInsert = {
“title”: item.number,
“age”: item.dateCreated,
“orderStatus”: item.fulfillmentStatus,
“paymentStatus”: item.paymentStatus
};

/let toInsert = {
“title”: CurrenRecord(‘number’),
“age”: CurrenRecord(‘_dateCreated’),
“orderStatus”: CurrenRecord(‘fulfillmentStatus’),
“paymentStatus”: CurrenRecord(‘paymentStatus’)
};;
/
wixData.insert(“Order_Management”, toInsert)
.then( (results) => {
let parit = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
} )

}

What did I do wrong and how can I debug the code with Chrome dev tools?

Thanks for your effort

ROnen

Hi, hooks does not work with Stores/Orders Collection.

Follow this post…Wix has implemented some events that solves this problem:

https://www.wix.com/corvid/forum/community-discussion/stores-order-hooks-not-working%3Fpage%3D1%26dl%3D5cd5dac8f7808900178f7c61%252F5cd2048b070f88048b71edcb%252F4

Hi jcampos,
Thanks for your help.
I already find this tread but somehow I can’t catch the onNewOrder even.
I added an events.js file to my website site structure\backend but its is not loading on new order event. I did exactly what is written in his post
I’m probably missing something but I’m working on it