Hello, I’m trying to pull data saved from a session from a wix’s page into one of my functions in the events.js file (I have wixStores_onNewOrder event in my event.js file).
However, when I include my import of wix-storage and try to pull data, it somehow fails. By fail, I mean no data was pulled at all and my function/event is not working anymore.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
// Place this code in the events.js file
// of your site's Backend section.
import wixData from 'wix-data';
import {session} from 'wix-storage';
export async function wixStores_onNewOrder(event) {
const newOrderId = event.orderId;
const dateCreate = event.dateCreated;
// Get the new order's line items from the Stores/Orders collection
const orderLineItems = await wixData.get("Stores/Orders", newOrderId)
.then((results) => {
let srcReferralVal = session.getItem("srcreferral"); // "value"
let newOrder = {
orderId : results.number,
dateCreated : dateCreate,
buyerName : results.buyerInfo.firstName.concat(" ", results.buyerInfo.lastName),
buyerFName : results.buyerInfo.firstName,
buyerSName : results.buyerInfo.lastName,
buyerEmail : results.buyerInfo.email,
buyerPhone : results.buyerInfo.phone,
orderItems : results.lineItems,
shippingInfo : results.shippingInfo,
shipAddress : results.shippingInfo.shipmentDetails.address.formatted,
shipCountry : results.shippingInfo.shipmentDetails.address.country,
shipProvince : results.shippingInfo.shipmentDetails.address.subdivision,
shipCity : results.shippingInfo.shipmentDetails.address.city,
shipZip : results.shippingInfo.shipmentDetails.address.postalCode,
shipBrgy : results.shippingInfo.shipmentDetails.address.addressLine,
billingInfo : results.billingInfo,
billingAddress : results.billingInfo.address.formatted,
paymentMethod : results.billingInfo.paymentMethod,
totals : results.totals,
shipAmt : results.totals.shipping,
discountAmt : results.totals.discount,
netAmt : results.totals.total,
lastUpdated : results._updatedDate,
paymentStatus : results.paymentStatus,
dbInserted : '0',
sharer : srcReferralVal
};
console.log(results.items);
wixData.insert("TestOrders", newOrder);
return results.lineItems
})
.catch((error) => {
// Order not found in the Stores/Orders collection
console.error(error);
});
}
The session variable ‘srcreferral’ is saved from another page (Products Page).
Please advice. Thank you very much!