public/vars.js file
// public/vars.js file
import wixLocation from 'wix-location';
export var globalVars = {
srcreferral : "test"
};
export function getUrlQuery() {
let query = wixLocation.query;
if(query) {
globalVars.srcreferral = query["srcreferral"];
}
}
Products Page
// Products Page
// “Hello, World!” Example: https://learn-code.wix.com/en/article/1-hello-world
import {getUrlQuery} from 'public/vars.js';
import {globalVars} from 'public/vars.js';
// ...
$w.onReady(function () {
// Write your JavaScript here
// To select an element by ID use: $w("#elementID")
// Click "Preview" to run your code
getUrlQuery();
});
Backend/events.js
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
import wixData from 'wix-data';
import {globalVars} from 'public/vars.js';
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 newOrder = {
orderId : results.number,
dateCreated : dateCreate,
sharer : globalVars.srcreferral
};
console.log(results.items);
wixData.insert("TestSharer", newOrder);
return results.lineItems
})
.catch((error) => {
// Order not found in the Stores/Orders collection
console.error(error);
});
}