How we can get order details (Id, number, totals etc) & promo code of current order on Thank You Page? I don’t know any direct way to get these both on the thank you page code.
Currently I’m getting order details by adding then in new database (named OSI) using onNewOrder() at events.js (under Backend menu) as follow
import wixData from 'wix-data';
export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
let newOrderNumber = event.number;
let totalPrice = event.totals.subtotal - event.totals.discount
let toInsert = {
"title": newOrderId,
"order_total": totalPrice,
"order_number": newOrderNumber
};
let wdi = wixData.insert("OSI", toInsert)
.then( (results) => {
} )
.catch( (err) => {
} );
}
OSI database structure (imported from CSV file) is as follow
"Title","ID","Owner","Created Date","Updated Date","order_total","order_number"
"xyz","b763d84d-e1c0-4839-a952-88543e3c5669","affb50c0-5a78-4c4d-9e88-1e4d4e4dd37e",2019-05-07T19:20:23Z,2019-05-21T15:25:05Z,789,123
"abc","8202ec1d-359f-47e0-88ce-2e77b19e2c87","affb50c0-5a78-4c4d-9e88-1e4d4e4dd37e",2019-05-07T19:20:16Z,2019-05-21T15:25:13Z,123,789
And reading these details on thank you page as follow (I have iframe control name osi on page)
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
let path = wixLocation.path;
let wdq = wixData.query("OSI")
.find()
.then( (results) => {
if (results.items.length > 0) {
for (var v = 0; v < results.length; v++) {
var item = results.items[v];
if (item.title === path[1]) {
$w('#osi').src = "https://PutHereYourSubdomain/sales/salejs/amount:"+item.order_total+"/transaction:" + item.order_number;
wixData.remove("OSI", item._id)
.then( (results_del) => {
} )
.catch( (err_del) => {
} );
break;
}
}
}
} )
.catch( (err) => {
} );
} );
We can get promo code details on onCartCompleted() at events.js (under Backend menu). I have stored these info in my OSI database. Plan was to store promo code info in onCartCompleted() & then store order info on onNewOrder(). event.buyerInfo.id (which is available in both events) was used as ID to store both info in the same OSI database record. The issue I’m facing is that both events seems to be executing on the same time, so it adds record with partial info. Isn’t it supposed to be executed in following sequence; 1st onCartCompleted(), 2nd onNewOrder()?
I know we can improve above mentioned code but I’m not interested in it for now. Please suggest me any workable solution for problem mentioned above. How we can get Order Details & Promo Code on Thank You Page?