quick question, is it possible to create a button, wich onClick deletes an Item form the Mini Shopping Cart?
Like the opposite of the addtocart function.
Yes possible if you made your online store fully with Wix Code. I don't know if its possible with the Wix Stores API or not.
See Demonstration in video below (Delete Function at 2:11)
Your Delete Button Code shall look like the below given that you want to delete a particular item entered by the user. For example: The Cart Database can hold hundreds of items but I can only modify or delete the item entered by me which contains my userId.
exportfunction deleteItem_click(event, $w) {
$w("#loader").show(); //a loader to let the user know the deletion is in progress
let user = wixUsers.currentUser;
let userId = user.id;
let currentItem = $w("#dataset1").getCurrentItem();
const itemId = event.context.itemId; // this is the item in the repeater assuming that the button is in the repeater.
wixData.query("Cart") // get the item from the database collection.
.eq("userId", userId)
.find()
.then( (results) => {
let remove = results.items[0]._id; // instead of results.items[0]
deleteCartItem(remove, itemId);
});
}
asyncfunction deleteCartItem(remove, itemId){
let user = wixUsers.currentUser;
let userId = user.id;
await wixData.remove("Cart", itemId); //removes the item
await $w("#dataset1").refresh(); //refresh your cart to remove the item from on screen
wixData.query("Cart")
.eq("userId",userId)
.find()
.then((results) => {
let items = results.items;
checkoutTotal(items); //if you have a total value displayed, update that
$w("#loader").hide(); //hide your loader
});
}
Hi shan, I have a platform where users can input information and the information populates a database collection, that database collection is displayed on a repeater that is connected to the database collection in the user's profile . Please what is code that I can use so that the user can click a delete button on the repeater to delete an item from the repeater. Thanks.
Wishlist Page is the new official platform for requesting new features. You can vote, comment, and track the status of the requested features (requests from this page will be migrated to the new Wishlist soon).
Yes possible if you made your online store fully with Wix Code. I don't know if its possible with the Wix Stores API or not.
See Demonstration in video below (Delete Function at 2:11)
Your Delete Button Code shall look like the below given that you want to delete a particular item entered by the user. For example: The Cart Database can hold hundreds of items but I can only modify or delete the item entered by me which contains my userId.
export function deleteItem_click(event, $w) { $w("#loader").show(); //a loader to let the user know the deletion is in progress let user = wixUsers.currentUser; let userId = user.id; let currentItem = $w("#dataset1").getCurrentItem(); const itemId = event.context.itemId; // this is the item in the repeater assuming that the button is in the repeater. wixData.query("Cart") // get the item from the database collection. .eq("userId", userId) .find() .then( (results) => { let remove = results.items[0]._id; // instead of results.items[0] deleteCartItem(remove, itemId); }); } async function deleteCartItem(remove, itemId){ let user = wixUsers.currentUser; let userId = user.id; await wixData.remove("Cart", itemId); //removes the item await $w("#dataset1").refresh(); //refresh your cart to remove the item from on screen wixData.query("Cart") .eq("userId",userId) .find() .then((results) => { let items = results.items; checkoutTotal(items); //if you have a total value displayed, update that $w("#loader").hide(); //hide your loader }); }
Thank you Mate! You are genious! This little snippet helped me to create a complete workarround on the default Shopping Cart from Wix!
Hi shan, I have a platform where users can input information and the information populates a database collection, that database collection is displayed on a repeater that is connected to the database collection in the user's profile . Please what is code that I can use so that the user can click a delete button on the repeater to delete an item from the repeater. Thanks.
Im having trouble implementing this in my array as well.
can you add some more info about exagtly what “Cart” refers to?