events.js wixStores_onNewOrder not working

So I have a database, orders and I am trying to insert into that data with the wix stores onNewOrder event.

The does not seem to be firing off on my live site?

Below is my code could anyone please assist me. Thanks in advance

import wixData from 'wix-data';
import wixStores from 'wix-stores-backend';

export function wixStores_onNewOrder(event) {

 let orderNumber = event.number;
 let billingEmail = event.billingInfo.email;
 let buyername = event.buyerInfo.firstName + " " + event.buyerInfo.lastName;
 let toInsert = {
 "number": orderNumber,
 "buyerName": billingEmail,
 "billingEmail": buyername
    };
    wixData.insert("orders", toInsert)
    .then( (results) => {
 let item = results; //see item below
        } )
        .catch( (err) => {
 let errorMsg = err;
        } );
}

I also had similar issue but with another event. Later it started working automatically. Not sure why. But I noticed the event triggered few seconds after it happened from my site monitoring tool. Maybe check the live database again after few seconds.

Thanks @thrishtilabs

Also check the database permission.if it’s allowed to insert by anyone or just by admin.

@thrishtilabs I though the same i have set it to anyone :slight_smile:

Then try debugging the events.js code with “add to cart” event and the site monitoring tool. This will be easier to test than the on new order event.

@wix Anyone got a solution? As I am working with deadlines and cant wait for the events to start working when they feel like it?

I place this code under Backend/events.js, and not working as well.

import wixData from ‘wix-data’ ;
import wixStores from ‘wix-stores-backend’ ;

export function wixStores_onCartCreated(event) {
console.log( “wixStores_onCartCreated” );
let total = event.totals.total;
let cartId = event.cartId;
wixData.insert( “Logs” , { ‘cartId’ : cartId});
}

event does not work with preview mode, try on published site,

I am trying to get OrderLine Items for custom fulfilment . As this feature is not available in Wix, I tried to code it in OnNewOrder event. The event does not have the line items. So,I tried querying the Orders table to get the line items and Insert the line items to another table - OrderItems for custom fulfilment.
I tested the event code with a dummy event on site preview mode it worked perfectly . and Lineitems were inserted in the OtherItems Table
I published the site and tried placing an order in the release candidate. There were no records inseted in the OrderItems table, I could not see any error message either.

Somone please suggest way to get the order line Item in OnNewOrder event.

let DBOptions = {"suppressAuth": true};
let OrderId = event.orderId;
let OrderResult = await wixData.query("Stores/Orders",DBOptions)
                        .eq("_id",OrderId)
                        .find();
let OrderlineItems = OrderResult.items[0].lineItems;

for (var i = 0; i < OrderlineItems.length; i++) { 
let lineItem = OrderlineItems[i];                   
//Process line items in for 
// send triggered mail 
//Calculate custom points
}

hi i am also facing same issue do you also get any solution?