In my website I collect the requirement from users using a form. This gets inserted into a database collection. This happens perfectly both in Preview and Live sites.
Once the form is submitted by the user, I use wix-data query to calculate few things based on the user input and insert this into another data collection. When the button is submitted it takes to another page where I display the order details from the second database collection.
This works perfectly in preview site, but it doesn’t work on the Live site.
The site name is - https://urcups.com.au/
Below is code snippet which I am using to populate the second database collection.
Please let me know what is going wrong.
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
$w.onReady(function () {
$w("#dataset1").onBeforeSave( () => {
// Getting the current Item from the user submission
var itemObj = $w(“#dataset1”).getCurrentItem();
console.log(itemObj._id);
// Generating an Order number
var randomString = function (len, bits)
{
bits = bits || 36;
var outStr = "", newStr;
while (outStr.length < len)
{
newStr = Math.random().toString(bits).slice(2);
outStr += newStr.slice(0, Math.min(newStr.length, (len - outStr.length)));
}
return outStr.toUpperCase();
};
var OrderNumber=randomString(6,16);
// Retreiving the User id
var UserId = wixUsers.currentUser.id;
//Retrieving the customer choice which happens in the previous page
wixData.query("CustomerChoice")
.eq("customerId", UserId)
.or (wixData.query("CustomerChoice")
.eq("customerId","00000000000a") //default record on Customer choice
)
.ne("designUrl","OwnLogo")
.descending("_updatedDate")
.descending("customerId")
.descending("designUrl")
.limit(1)
.find()
.then( (results) => {
let items = results.items;
var Order = items[0];
var Design = Order.designUrl;
console.log(Design);
// Querying the price of the cup based on the customer choice
wixData.query("Cups")
.eq("title",Design)
.descending("_updatedDate")
.limit(1)
.find()
.then( (results) => {
let items2 = results.items;
var Cup = items2[0];
var DesignImage = Cup.image;
var EozSwPrice = Number(Cup.eswPrice.slice(1,3));
var TozSwPrice = Number(Cup.tswPrice.slice(1,3));
var SozSwPrice = Number(Cup.sswPrice.slice(1,3));
var EozDwPrice = Number(Cup.edwPrice.slice(1,3));
var TozDwPrice = Number(Cup.tdwPrice.slice(1,3));
var SozDwPrice = Number(Cup.sdwPrice.slice(1,3));
console.log(DesignImage);
console.log(EozSwPrice);
console.log(TozSwPrice);
console.log(SozSwPrice);
console.log(EozDwPrice);
console.log(TozDwPrice);
console.log(SozDwPrice);
console.log(itemObj);
if (itemObj.eozSel === true) {
if (itemObj.eozType === 'SingleWall') {
var EozAmt = Number(itemObj.eozQty)*Number(EozSwPrice)/500;
}
else if (itemObj.eozType === 'DoubleWall') {
var EozAmt = Number(itemObj.eozQty)*Number(EozDwPrice)/500;
}
}
else {
var EozAmt = 0;
}
if (itemObj.tozSel === true) {
if (itemObj.tozType === 'SingleWall') {
var TozAmt = Number(itemObj.tozQty)*Number(TozSwPrice)/500;
}
else if (itemObj.tozType === 'DoubleWall') {
var TozAmt = Number(itemObj.tozQty)*Number(TozDwPrice)/500;
}
}
else {
var TozAmt = 0;
}
if (itemObj.sozSel === true) {
if (itemObj.sozType === 'SingleWall') {
var SozAmt = Number(itemObj.sozQty)*Number(SozSwPrice)/500;
}
else if (itemObj.sozType === 'DoubleWall') {
var SozAmt = Number(itemObj.sozQty)*Number(SozDwPrice)/500;
}
}
else {
var SozAmt = 0;
}
console.log (EozAmt);
console.log (TozAmt);
console.log (SozAmt);
var SubTotAmt = Number(EozAmt+TozAmt+SozAmt);
var GSTAmt = Number(SubTotAmt/10);
var TotAmtNum = Number(SubTotAmt+GSTAmt);
console.log (SubTotAmt);
console.log (GSTAmt);
console.log (TotAmtNum);
let CurrSymbol = 'AU$ ';
let EozAmtStr = String(EozAmt);
var dEozAmt = CurrSymbol.concat(EozAmtStr);
let TozAmtStr = String(TozAmt);
var dTozAmt = CurrSymbol.concat(TozAmtStr);
let SozAmtStr = String(SozAmt);
var dSozAmt = CurrSymbol.concat(SozAmtStr);
let SubTotAmtStr = String(SubTotAmt);
var OSubTotAmt = CurrSymbol.concat(SubTotAmtStr);
var OShippingAmt = 'AU$ 0';
var GSTAmtStr = String(GSTAmt);
var OGSTAmt = CurrSymbol.concat(GSTAmtStr);
let TotAmtStr = String(TotAmtNum);
var OTotAmt = CurrSymbol.concat(TotAmtStr);
if (itemObj.eozSel === true) {
var OeozType = itemObj.eozType;
var OeozQty = String(itemObj.eozQty);
var OeozAmt = dEozAmt;
}
else {
var OeozType = '';
var OeozQty = '';
var OeozAmt = '';
}
if (itemObj.tozSel === true) {
var OtozType = itemObj.tozType;
var OtozQty = String(itemObj.tozQty);
var OtozAmt = dTozAmt;
}
else {
var OtozType = '';
var OtozQty = '';
var OtozAmt = '';
}
if (itemObj.sozSel === true) {
var OsozType = itemObj.sozType;
var OsozQty = String(itemObj.sozQty);
var OsozAmt = dSozAmt;
}
else {
var OsozType = '';
var OsozQty = '';
var OsozAmt = '';
}
let toInsert2 = {
"title": OrderNumber
,"customerId": UserId
,"design":Design
,"designImage":DesignImage
,"customerName":itemObj.contactName
,"eozType":OeozType
,"eozQty":OeozQty
,"eozAmt":OeozAmt
,"tozType":OtozType
,"tozQty":OtozQty
,"tozAmt":OtozAmt
,"sozType":OsozType
,"sozQty":OsozQty
,"sozAmt":OsozAmt
,"subTotAmt":OSubTotAmt
,"shippingAmt":OShippingAmt
,"gstAmt":OGSTAmt
,"totAmt":OTotAmt
};
console.log(toInsert2);
wixData.insert("test",toInsert2);
} );
} );
} );
});