Stores/order Hooks not Working

@adas-bradauskas

It is not working for me…

Use the same code you provided in a live publish site:

import wixData from ‘wix-data’;
import wixStores from ‘wix-stores-backend’;

export function wixStores_onCartCreated(event) {
let total = event.totals.total;
wixData.insert(‘Logs’, {‘title’: total})
}

export function wixStores_onNewOrder(event) {
let newOrderId = event.orderId;
wixData.insert(‘Logs’, {‘orders’: newOrderId})
}

Still does not work…any ideia what could be wrong ?

@jcampos Did you set your table / collections permission for everyone? And you are looking at your live data vs sandbox data?

@johnsonsflorists

Yes…collection permissions are set for everyone…

Looking at live data…no records found…frustrating…(:

@jcampos and your doing this in the published site version? You also try to hit the sync button, maybe the table it self is not really in live?

@adas-bradauskas Thanks ! Working for me.

@johnsonsflorists I tested my code running on my published site and to see the logs I went not to Sandbox version of the collection, but Live. It’s that other tab you see in your collection.

@adas-bradauskas Could you make a live conference so you can take a look at my publish site ?

Steps by step:
Created Log Collection
Sync to live data
Set all permissions to Anyone

Placed the correct code in the event.js file.

Publish Site
Run from publish site
Added an item to the shopping car
Check live Logs Collection
Still no data on live Logs Collection


It is strange that works on Brayan Oduro site and not in my site…

@jcampos Try to rename your file eventS.js , should works !

@oduroagency Thanks Brayan…now it is working, but had to publish after sync to live collection to work…

@oduroagency

Now I need to get the order info togheter with the cart info (shipping address, etc to send it to our other system ( integration ) using fetch…

I queried the Stores/Orders collection on wixStores_onNewOrder event, but how can I join the two information ( cart info and order info) since there is no field that keeps the correlation between the shopping cart and placed Order ( one to one relationship).

The NewOrderEvent does not contain any reference to the CartCompletedEvent or vice-versa…

Because events are asynchronous, I could query the Order collection and get the wrong Order collection result for a given cart, on multiple clients acessing our site at the same time making purchases…

How to garantee that the Order correspond to the Shopping Cart ?

@jcampos So iyou need cart info + order info together ? I dont understand, what’s info you need from cart you can"t get it from the order ??

@oduroagency Order Shipping Info Address returned information (shippingInfo.shipmentDetails.address.formatted) is different from the Cart Shipping info Shipping Address ( shippingInfo.shippingAddress.address ).

Cart Shipping Info returns the complete correct Shipping Address…Order Shipping Info does not contain the complete Shipping Address…so we need to get the Shipping Address from the Card.

A simple correction from Wix returning the complete correct address on the returned address in shippingInfo.shippmentDetails.address.formatted should solve the problem…

@adas-bradauskas Just to make it clear. Should I create a file name ‘events.js’ and put it under the section called ‘Site Structure\backend’ or such file is already exist? if it exist, where can I find it?

@jcampos , You could use buyer id? or any of the buyer info? But I think your talking about the OnCartCreated and the NewOrderEvent? The only thing there is total price. I need this linkage too and was trying to see if there is a way to push data from backend up to frontend, but not sure there is a way. So I was going to create a web service to query my table from view cart page and then pass cartid using session data to thank you page. Then using location you can link the two together. The initial query is not hundred percent but you could cross reference it against the cartcompleted one. That still doesn’t help I guess on the invalid case…:). The stupid thing is that buyer id changes which we could have totally used that if it was the same for that session? Not sure why it even changes. Sounds like a bug?

@johnsonsflorists For me it is a bug or something Wix Developers didn’t take into acount…

@jcampos So I think for what you want to do you can use the buyer id right? This will link cart and order together. My problem is that I still need to link with other front-end data that I manually entering. Or are you doing that too as well?

@ronenin , no, you need to create it manually. Just make sure you create .js file, not .jsw.

Adas can you ask the developers to urgent fix the shippingInfo collumn to return the complete address info in the Stores/Orders collection.

This would solve the problems we are talking about allowing us to integrate the orders with an external system passing only the Order collection information that would contain all complete information of the purchase…

Also, So lets say you could use the order events to fix the shipping info problem. How are you updating the Stores/Orders?
Thanks,
Tom

@johnsonsflorists We can’t fix the shipping info problem using the NewOrderEvent…it is a API response problem…Wix has to fix it…

We can’t add new fields to the Stores/Orders collection or write in any of the fields using Update…Stores/Orders is a ead only collection.

All we can do is to read the Cart CartCompletedEvent object and get the address information, then on NewOrderEvent get the order id and query the order collection to get order addition information. Then send the collected information to an external API using fetch…

But at the risk of reading the wrong Order for a given Cart CartCompletedEvent…

Unless Adas has a way of doing this…Adas ?