I would, please, need help with a problem I am having.
I created my own cart(I don’t use the WIX one). Everything works (calculations, addition, deletion, updating of totals, etc.) except clicking on the “+” button or the “-” button: I would like that :
1/ the quantity, field No. 2 in the screenshot, is increased (or decreased) and modifies the field in the table.
2/ the total, field No. 3 in the screenshot, is calculated automatically and the data in the database is also modified)
Actually, i made a query based on the name of the customer and the name of article (in my “Panier” Database. i think it would be better to do this query with the ID? but how?
I am attaching my code as well as a screenshot of my cart.
I was able to make progress in partially resolving the problem.
From now on, it selects the right item (from its ._id) and it increments the quantity, and the total, as well as the Total cart.
My new problem: it only works once. If I click a second time on the “+” or “-” button “-”, nothing more happens. I
in fact, i noticed that if the starting quantity (for example is at 4), when i click on “+” button, it increases of course (5). But it’s still 4 in memory. (and modified to 5 in the database) so when i click a second time, it adds again 1 to 4 (always). It doesn’t take car of the new value (5), so he always adds from the starting value. How to refresh with the new value?
Thanks for your help
//****************************
//HERE THE CODE
//****************************
const AjoutQuantite = () =>{
return wixData.query('Monpanier')
.eq("_id",itemData._id)
.find()
.then(async(results) => {
// Mise a jour du champ Quantite et total
console.log(results.items[0]);
const MAJQteTotal = results.items.map(item => ({ ...item, quantite: itemData.quantite+1,total:itemData.prix*(itemData.quantite+1),TotalFormate:String(parseFloat(Number(itemData.quantite+1)*itemData.prix).toFixed(2))+" €" }))
//const MAJQteTotal = results.items.map(item => ({ ...item, quantite: itemData.quantite+1}))
await wixData.bulkUpdate('Monpanier', MAJQteTotal);
$w('#Panier').setFilter(wixData.filter()
.eq("mailClt", $w('#MailClt').value))
.then(updateitem)
.then(CalculTotalPanier)
.then(result3)
.then((results) => {
console.log(results);
})
})
Wait let me activate my 7th sense, ohhhhhh, yes now i can see something…
Your REPEATER is maybe connected to a → DATASET ?
Where do i find the code for feeding/updating your repeater? → something like
a) $w(‘#myRepeater’).data = [here your data you want to feed your repeater with]
b) But if you are using a dataset → REFRESH? maybe you forgot to refresh your dataset, sice you have changed your DATABASE, because your dataset is connected to your database???
Ohhhh, now i even found your → DATASET
$w(‘#Panier’).setFilter(wixData.filter() <— isn’t it a → DATASET ?
What about → $w(‘#Panier’).refresh(); ???
Your REPEATER is connected to a DATASET, right?
What about —> $w(‘#Panier’).onReady() ← did you use it?
You will surely have more code, which you do not show, am i right ?
Always the same issues when mixing → WIX-DATA ← & → DATASETS <—
async function CalculTotalPanier(){
let calcul =await wixData.aggregate(“Monpanier”).sum(“total”,“TotalTTC”).filter(filtre).count().run();
let TotalTTC= calcul.items[0].TotalTTC
let QtePanier=calcul.items[0].count;
$w(‘#QtePanier’).value=QtePanier
//if (QtePanier> 0) {
if ((QtePanier) !== undefined) {
console.log (TotalTTC)
console.log (“Nombre d’articles : “+QtePanier+” Pour un Total Panier = “+TotalTTC+” €”)
$w(‘#TotalTTC2’).value=String(parseFloat(Number(TotalTTC).toFixed(2)))+" €"
$w(‘#TotalTTC’).value=String(Number(TotalTTC))
let SessionMailClt
SessionMailClt=session.getItem('MailClt');
$w('#Panier').setFilter(wixData.filter()
.eq("mailClt", SessionMailClt))
.then (Refresh)
} else {
let SessionMailClt
SessionMailClt=session.getItem('MailClt');
console.log("Pas d'articles dans le panier pour "+SessionMailClt)
$w('#TotalTTC2').value="0,00€"
$w('#TotalTTC').value="0"
$w('#Panier').setFilter(wixData.filter()
.eq("mailClt", SessionMailClt))
.then (Refresh)
}
}
And finally, I created this function:
//4°/ Rafraichir les datasets
function Refresh() {
$w(‘#Panier’).refresh()
}
I’m sorry, but I’m a beginner. And totally self-taught, so I try …