Stores/order Hooks are not Working. We need it to get the orders and send it to another server integration…
Any one ?
Stores/order Hooks are not Working. We need it to get the orders and send it to another server integration…
Any one ?
It is Stores/Orders (S at the end). But I guess that doesn’t solve your problem? I’m having the same issue…
Hey jcampos,
Unfortunately, you encountered a bug with Hooks functionality. We unintentionally exposed this option for Stores, but we currently don’t support it.
What might really help you is onNewOrder() . Mind that this event should be added to your backend file.
Hey @adas-bradauskas , thans for clarifying! But when I look on onNewOrder() doc :
https://www.wix.com/corvid/reference/wix-stores-backend.Events.html#onNewOrder
I don’t see WHAT was bought. How can we retrieve the product info like SKU-code?
Hey Adas,
I placed the following code in the event.js in the backend . The backEndLog collection is to check if the onNewOrder(event) is working, but it is not working…it should insert a record at the backEndlog Collection when an event on wix-stores occurs…
//event.js code
import wixData from ‘wix-data’;
import wixStores from ‘wix-stores-backend’;
export function wixStores_onNewOrder(event) {
console.log(“New Order”);
let newOrderId = event.orderId;
let totalPrice = event.totals.total;
let toInsert = {
“title”: “newOrderEvent.”,
“order”: event
};
wixData.insert(“backEndLog”, toInsert)
.then( (results) => {
let item = results; //see item below
console.log(‘item’+ JSON.stringify(item));
} )
. catch ( (err) => {
let errorMsg = err;
} );
}
export function wixStores_onCartCreated(event) {
let total = event.totals.total;
let toInsert = {
“title”: “onCartCreated.”,
“order”: event
};
wixData.insert(“backEndLog”, toInsert)
.then( (results) => {
let item = results; //see item below
console.log(‘item’+ JSON.stringify(item));
} )
. catch ( (err) => {
let errorMsg = err;
} );
}
export function wixStores_onCartCompleted(event) {
let total = event.totals.total;
let toInsert = {
“title”: “onCartCompleted.”,
“order”: event
};
wixData.insert(“backEndLog”, toInsert)
.then( (results) => {
let item = results; //see item below
console.log(‘item’+ JSON.stringify(item));
} )
. catch ( (err) => {
let errorMsg = err;
} );
}
As you can see not record was inserted on none of the events above…
Hey Tom,
From onNewOrder() you should get orderId :
export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
}
With this orderId, you should query Stores/Orders. There, you’ll find the items purchased.
Are you running this code in Preview? What does the Sandbox database look like? You’re now showing us the Live version of it.
The Sandbox database look the same
If this works, then we must be doing something wrong or missing some directive…
Hey Tom…did you get it to work ?
Hey Tom…did you get it to work ?
Hi @jcampos , did you ever get this working. I don’t see my event ever get fired.
Thanks,
Tom
Hi @adas-bradauskas , have you ever got onNewOrder() working? It seems not be triggered on my site. Could you please provide some instructions to show how you did it? Thank you so much!
Hi @adas-bradauskas , Can you give us an example of backend events.js working?
Thanks,
Tom
Hello @adas-bradauskas , I also need instructions about events trigger…
Tested it with this code in a published site:
import wixData from 'wix-data';
import wixStores from 'wix-stores-backend';
export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
wixData.insert('Logs', {'orders': newOrderId})
}
orders
is a reference field in Logs collection, so it shows me the the order from Stores/Orders collection.
Sure!
import wixData from 'wix-data';
import wixStores from 'wix-stores-backend';
export function wixStores_onCartCreated(event) {
let total = event.totals.total;
wixData.insert('Logs', {'title': total})
}
export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
wixData.insert('Logs', {'orders': newOrderId})
}
Check my answers above.
@adas-bradauskas , Thanks Adas! Will try this. Also is that ‘title’ a typo? Shouldn’t it be something like ‘total’
Thanks,
Tom
@adas-bradauskas , So I put in the above code in events.js file in backend section. I changed collection name to CartInfo, which I created already and have permissions set for everyone? Am I missing something. It just doesn’t seem to work on my site. I think either permission thing or something else possible? I was also able to insert into this table from other areas of site like front end I tested to make sure I can atleast do inserts like below and worked fine. Please Advise.
import wixData from ‘wix-data’;
import wixStores from ‘wix-stores-backend’;
export function wixStores_onCartCreated(event) {
let total = event.totals.total;
wixData.insert(‘CartInfo’, {‘total’: total})
}
export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
wixData.insert(‘CartInfo’, {‘orderid’: newOrderId})
}
@adas-bradauskas , So I think I figured out what is going on, I guess this only works in live period, Even the on cart created, which you can do in preview but won’t work because this feature only seems to work in live. I thought I was sync my table every time, but just realized it was just going one way. So maybe I was over writing live every time? Not sure but if you switch to live on collection, then I can see data being added.
Thanks,
Tom