Order Details & Promo Code on Thank You Page

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?

https://www.wix.com/corvid/reference/$w.ThankYouPage.html

@givemeawhisky I see there are order details but I don’t see any details for promo code! Can you please point out this info? Or any other link?

@aamirshahzadropstam

If you want to show coupons etc, then look at using Wix Stores Backend instead.
https://www.wix.com/corvid/reference/wix-stores-backend.html

@givemeawhisky It seems that there’s no direct way to get current order’s coupon code on thank you page. So I’m going to store coupon codes in the DB as I have mentioned in my 1st comment and read order details on thank you page as you have mentioned in the link (few comments above). I’m going to compare DB record data with order data on thank you page with event.buyerInfo.id and get coupon codes data. Let me know if you think there’s any other better way.

@givemeawhisky This seems not possible. I’m inserting coupon code to OSI DB but thank you page code is executing before back-end code in wixStores_onCartCompleted(). So I can’t read coupon code added to the DB. Is there any way to ensure that back-end would execute before thank you page code?

Any suggestion/solution/link?