Need help to get the right data collection for the order "Thank You Page"

Wix support pointed me to the Wix collection name Order . I tried the code below in the “Thank You Page” and got error message:

The Order collection does not exist.

import wixData from 'wix-data'; 

$w.onReady(function () { 

    wixData.get("Order", "billingInfo")
    .then( (results) => {
        let orderData = results;
        console.log(orderData);
    } )
    .catch( (err) => {
        let errorMsg = err;
        console.log(err);} 
    );
}); 

Error: WDE0025: The Order collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor. You Page" and got error message:

The Order collection does not exist.

This link shows the Order collection fields Velo: Wix Stores "Orders" Collection Fields | Help Center | Wix.com

Have you got a dataset on your site that is called ‘Order’?

Otherwise the error is correct, you can’t call an action to happen on a dataset that does not exist.

Plus, Wix Stores already do thank you page:
https://support.wix.com/en/article/adding-wix-stores

This is the Wix Store “Thank You Page”. And the data collection is the Wix App data collection.
I will update my post to make it clear that I am referring to the Wix Store Thank You Page. Wix support probably gave me the wrong name for the Wix App collection.

Wix Support will probably redirect you back to the code forum as you want to use code with it. However, yes go through Wix Support as it is a Wix app,

As for Wix Stores, look in your site structure on the left hand side of your editor and it should list your datasets for Wix Stores there and so you should be able to see easily the names of your datasets.

You can track sales through your thank you page:
https://support.wix.com/en/article/tracking-sales-in-wix-stores-using-your-thank-you-page-url

Other ways of tracking:
https://support.wix.com/en/article/tracking-sales-in-wix-stores-with-a-facebook-conversion-pixel
https://support.wix.com/en/article/about-store-analytics
https://support.wix.com/en/article/adding-a-tracking-number-to-an-order-in-wix-stores

If you want to get info about an order, then you can set it up so that you get an email confirmation on each purchase: https://support.wix.com/en/wix-stores/managing-store-emails

Think I have sorted out your issue here.

Try the dataset name as ‘Orders’ and not ‘Order’.

See here for more info about the collection:
https://support.wix.com/en/article/corvid-wix-stores-orders-collection-fields

Wix Stores api info:
https://www.wix.com/corvid/reference/wix-stores.html
https://www.wix.com/corvid/reference/wix-stores-backend.html

Thanks! I was able to bypass that issue.

wixData.get("Stores/Orders", "billingInfo")

But, now I get below error:

Error: {“message”:“id with value "billingInfo" is not a valid GUID”,“details”:{“validationError”:{“fieldViolations”:[{“field”:“id”,“description”:“value "billingInfo" is not a valid GUID”}]}}}

Ah yes I forgot about the /Stores part in front of it, same as when you use the PrivateMembersData collection it needs the /Members in front of it.

You might not be able to simply just do that get data call on the field, seems you can only filter it as it states on the collection info page:

Billing Info (billingInfo)

Description : Billing information as a JSON object.
Type : JSON
Can connect to data : No
Can use in dynamic page URL : No
Can be sorted : No
Can be filtered:billingInfo.address.fullName : eq, ne, hasSome, lt, lte, gt, gte
Read-only : Yes

https://support.wix.com/en/article/corvid-wix-stores-orders-collection-fields#billing-info-billinginfo

Also, note that this will give you a json reply, so you need to be able to convert it to string to be able to read/use it as text.

Something like this I think, if it is possible like that.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
https://www.w3schools.com/js/js_json_parse.asp

let jsonObject = JSON.parse(jsonString);

Thanks @givemeawhisky . I tried a few things and I can’t seem to get the data that I expect.
here is what I see when I did a “View frame source” below. I would want get the data for orderData:

  • orderId

  • buyerMail

 ...
 function initClientData() 
 {var RECOVERY_KEY = 'eComRecovery;
var isRecoveryAttempt = location.search.substr(1).split('&').indexOf(RECOVERY_KEY) >= 0;
if (typeof(eCom) === 'object') {eCom.eComAppConfig('thankYouPageApplication', {"appData":{"storeId":"00000000-000000-000000-000000000000","orderData":{"orderId":10000,"orderGuid":"0","buyerName":"Buyer Name","buyerMail":"buyer@email.com","totals":{"total":"$10.00","formattedTotal":"$10.00","value":10,"currency":"USD"},"shippingAddress":{"name":"Address","country":"USA","subdivision":"US-NY","addressLine1":"Address","city":"City","zipCode":"Zip"},"itemsTypes":["physical"],"digitalItems":[],"status":"paid","deliveryInfo":{"title":"Standard Delivery","deliveryTime":"3-5 Business Days","deliveryAddress":{"country":"USA","subdivision":"US-NY","addressLine":"Address","city":"City","zipCode":"Zip"},"deliveryType":"SHIPPING"},"items":[],"paymentMethod":"paypal-express","paymentStatus":"paid"},"sellerMail":"seller@email.com","emailToBuyerEnabled":true,"facebookPixelId":""},"topology":{"commonExecutionUrl":"//ecom.wix.com/_api/wix-ecommerce-renderer-web/store-manager/executeCommonCommands","advertiserCommandsUrl":"//ecom.wix.com/_api/wix-ecommerce-renderer-web/store-manager/wca/{commandName}","getDynamicPaymentMethodsUrl":"//ecom.wix.com/_api/wix-ecommerce-renderer-web/store-manager/get-payment-methods","frogUrl":"//frog.wix.com/","getStoreManagerTaxRules":"//ecom.wix.com/_api/wix-ecommerce-renderer-web/store-manager/taxRules","getCategoryUrl":"//ecom.wix.com/_api/wix-ecommerce-renderer-web/store-manager/categories/{categoryId}","getPaymentMethodsUrlForCartUrl":"//ecom.wix.com/_api/wix-ecomme
 

Why not try using the ID field for the orderID.

ID (_id)

Description : The ID of the order. This is a system field and is hidden by default.
Type : Text
Can connect to data : Yes
Can use in dynamic page URL : No
Can be sorted : Yes
Can be filtered : eq, ne, hasSome, contains, startsWith
Read-only : Yes

And then in someway get the buyer to add their email into the buyer note so that you can use the Buyer Note field instead for buyer email.

Buyer Note (buyerNote)

Description : A note added by the buyer on the cart page when creating the order.
Type : Text
Can connect to data : Yes
Can use in dynamic page URL : No
Can be sorted : No
Can be filtered : No
Read-only : Yes

At least both of those fields are simple text type fields and not returned back as json, so should be much easier to use and query data with.

Have a look at this backend feature too which was released a few days ago.

API: onCartCreated and onCartCompleted
The wix-stores-backend API now has two new events, onCartCreated and onCartCompleted . You can now run code when a site visitor creates a cart or completes a cart purchase.

https://www.wix.com/corvid/reference/wix-stores-backend.Events.html#onCartCompleted

Or use this one instead.
https://www.wix.com/corvid/reference/wix-stores-backend.Events.html#onNewOrder

THANKS! I will look into it.

I looked at the wixStores_onNewOrder function:

export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
let totalPrice = event.totals.total ;
}

I am not familiar with this aspect of events. How do I get the data back into the main script or do I just need to put the code for what I want to be accomplished in this function.

So could I write a function that would be called within wixStores_onNewOrder? It would set the data in fields on the “Thank You Page” some visible and hidden as necessary or write the data to a database and retrieve.

export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
let totalPrice = event.totals.total ;

// my function to set  

setMyThankYouPageValues(newOrderId);

... 

}

@ givemeawhisky , I tried a few things, including importing the wixStores_onNewOrder functiion to the main script on my Thank You Page, but wasn’t successful.

export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
let totalPrice = event.totals.total ;

}

If anyone has used them before, I would like to see an example of them being used instead of the snippet provided by Corvid. Has anyone actually used these events functions in the backend file to create data for the frontend form elements?