my wishlist code is functional in preview but not on the published page, it fails when the heart is clicked on the product page does not delete the item from the wishlist database and begins to repeat appearing Several times later on the wish list page, it only happens on the published page, in preview it works fine.
i really apreciate your help.
//lista favoritos-----------------------------
//-------------Imports-------------//
// Import the wix-data module for working with queries.
import wixData from 'wix-data';
// Import the wix-users module for working with users.
import wixUsers from 'wix-users';
//-------------Global Variables-------------//
// Current product.
let product;
// Current user.
let user = wixUsers.currentUser;
//-------------Page Setup-------------//
$w.onReady(async function () {
// Get the currently displayed product.
product = await $w("#dynamicDataset").getCurrentItem().nombre_emp;
// Check if the current product is in the wishlist and act accordingly.
checkWishlist();
// Set the action that occurs when the login message is clicked to be the loginMessageClick() function.
$w('#loginMessage').onClick(loginMessageClick);
});
// Check if the current product is in the wishlist and act accordingly.
async function checkWishlist() {
// If the current user is logged in:
if (wixUsers.currentUser.loggedIn) {
// Query the "FAVOTITE DB" collection to find if the product was already added to the user's wishlist.
let wishListResult = await wixData.query("Favoritos_DB")
.eq("product", product)
.eq("userId", user.id)
.find();
// If the product was already added to the user's wishlist:
if(wishListResult.items.length > 0)
// Show the "inWishList" image with a fade effect.
$w('#inWishList').show('fade', {duration: 100});
// If the product was not yet added to the user's wishlist:
else
// Show the "notInWishList" image with a fade effect.
$w('#notInWishList').show('fade', {duration: 100});
}
// If the current user is not logged in:
else {
// Show the "notInWishList" image with a fade effect.
$w('#notInWishList').show('fade', {duration: 100});
}
}
//-------------Event Handlers-------------//
// Set the action that occurs when the "inWishList" image is clicked.
export function inWishList_click(event, $w) {
// If the current user is logged in:
if (user.loggedIn)
// Remove the current product from the wishlist.
removeFromWishlist();
}
// Set the action that occurs when the "notInWishList" image is clicked.
export function notInWishList_click(event, $w) {
// If the current user is logged in:
if (user.loggedIn)
// Add the current product to the wishlist.
addToWishlist()
// If the current user is not logged in:
else
// Show the login message.
$w('#loginMessage').show();
}
// Set the action that occurs when the login message is clicked.
async function loginMessageClick() {
// Set the login options.
let options = {"mode": "login"};
// Hide the login message.
$w('#loginMessage').hide();
// Prompt the user to login using the options created above.
await wixUsers.promptLogin(options);
}
//-------------Wishlist Functionality-------------//
// Add the current product to the current user's wishlist and update the page accordingly.
async function addToWishlist() {
// Create the wishlist item relating the current product to the current user.
let wishListItem = {
product: product,
userId: user.id
};
// Hide the "notInWishList" image with a fade effect.
$w('#notInWishList').hide('fade', {duration: 100});
// Show the "inWishList" image with a fade effect.
$w('#inWishList').show('fade', {duration: 100});
// Insert the item created above into the "products-wishlist" collection.
let result = await wixData.insert("Favoritos_DB", wishListItem);
}
// Remove the current product to the current user's wishlist and update the page accordingly.
async function removeFromWishlist() {
// Query the "products-wishlist" collection to find the wishlist item corresponding to the current product and current user.
let wishListResult = await wixData.query("Favoritos_DB")
.eq("product", product)
.eq("userId", user.id)
.find();
// If a wishlist item was found:
if (wishListResult.length > 0) {
// Show the "notInWishList" image with a fade effect.
$w('#notInWishList').show('fade', {duration: 100});
// Hide the "inWishList" image with a fade effect.
$w('#inWishList').hide('fade', {duration: 100});
// Remove the wishlist item from the "products-wishlist" collection.
await wixData.remove("Favoritos_DB", wishListResult.items[0]._id)
}
}
This is the part of the code where the wish list works, there is more code for a gallery, a dynamic page among other things.
here is the rest of code.
//SECCION ACORDEON
export function headerBox1_click() {
if ($w('#fold1').collapsed) {
$w('#fold1').expand();
$w('#arrowDown1').show();
$w('#arrowRight1').hide();
} else {
$w('#fold1').collapse();
$w('#arrowDown1').hide();
$w('#arrowRight1').show();
}
}
export function headerBox2_click() {
if ($w('#fold2').collapsed) {
$w('#fold2').expand();
$w('#arrowDown2').show();
$w('#arrowRight2').hide();
} else {
$w('#fold2').collapse();
$w('#arrowDown2').hide();
$w('#arrowRight2').show();
}
}
export function headerBox3_click() {
if ($w('#fold3').collapsed) {
$w('#fold3').expand();
$w('#arrowDown3').show();
$w('#arrowRight3').hide();
} else {
$w('#fold3').collapse();
$w('#arrowDown3').hide();
$w('#arrowRight3').show();
}
}
export function headerBox4_click() {
if ($w('#fold4').collapsed) {
$w('#fold4').expand();
$w('#arrowDown4').show();
$w('#arrowRight4').hide();
} else {
$w('#fold4').collapse();
$w('#arrowDown4').hide();
$w('#arrowRight4').show();
}
}
//INTEGRACION MAPS A BASE DE DATOS
$w.onReady(function () {
$w("#dynamicDataset").onReady(() => {
let currentItem = $w("#dynamicDataset").getCurrentItem();
$w("#googleMaps1").location = {
"latitude": currentItem.latitude,
"longitude": currentItem.longitude,
"description": currentItem.nombre_emp,
};
});
});
//INTEGRACION GALERIA CON FOTOS DE BASE DE DATOS
$w.onReady(function () {
let item = $w("#dynamicDataset").getCurrentItem();
$w("#gallery1").items = [
{ src: item.gal_1 },
{ src: item.gal_2 },
{ src: item.gal_3 },
{ src: item.gal_4 }
];
});
//BOTON DINAMICO LLAMADAS - WHATS APP
import wixLocation from 'wix-location';
export function celButton_click(event) {
wixLocation.to("tel:" + $w("#input1").value);
}
export function whatsButton_click(event) {
wixLocation.to("https://wa.me/57" + $w("#input1").value + "?text=Hola,%20encontre%20tu%20servicio%20con%20LOTENGO%20APP!");
}
//wixLocation.to("https://wa.me/57" + $w ("#input1").value);//
//TEXTO DINAMICO PARA HORARIO
$w.onReady(() => {
$w("#dynamicDataset").onReady(() => {
let description = $w("#dynamicDataset").getCurrentItem().horaInicio; //text is the field you want to get its text
let description2 = $w("#dynamicDataset").getCurrentItem().horafin; //text is the field you want to get its text
let description3 = $w("#dynamicDataset").getCurrentItem().diaInicial; //text is the field you want to get its text
let description4 = $w("#dynamicDataset").getCurrentItem().diaFinal; //text is the field you want to get its text
let description5 = $w("#dynamicDataset").getCurrentItem().amPmInicio; //text is the field you want to get its text
let description6 = $w("#dynamicDataset").getCurrentItem().ampmFin; //text is the field you want to get its text
$w("#horario").text = "De " + description3 + " a " + description4 + " de " + description + " " + description5 + " a " + description2 + " " + description6 + ".";
});
});
please help…
So to get this straight you only have the error on the Wix Stores wishlist page which is on your Wix Stores Product page and none of the other code is actually on your Wix Stores Product page too and are all on their own seperate pages?
As you have used the code for Wishlist in Wix Stores.
https://support.wix.com/en/article/corvid-tutorial-adding-a-wishlist-to-a-wix-stores-site
So we don’t need to refer to any tutorial pages for your other pages like the collapsing and expanding elements or location using Google Maps API or showing pics in a gallery on a dynamic page etc, etc.
What is the actual error message that you are getting when you run your code on your live site?
With regards to the code itself…
From the Wix Editor example code.
$w.onReady(async function () {
// Get the currently displayed product.
product = await $w('#productPage1').getProduct();
From the tutorial code.
$w.onReady(async function () {
product = await $w('#productPage1').getProduct();
});
And Yours.
$w.onReady(async function () {
// Get the currently displayed product.
product = await $w("#dynamicDataset").getCurrentItem().nombre_emp;
So, the tutorial is checking the product on the actual product page as stated in the tutorial understanding the code example.
Lines 7-9: Get the current product from the Product page.
Yes you can modify it to suit by changing #productPage1 and wishlist, however it should really be another page and not a dataset as you have used.
Plus, as it states on the example page too that you don’t have to use the Wix Stores collections for your products and can use your own dataset collection, however it should still really be a page that you are using here and not a dataset.
For this example, you’ll need some products stored in a collection. We added Wix Stores to our site, which automatically adds a Stores/Products collection to our site, but you can also create your own collection of products without Wix Stores.
Also, further down.
Wix Editor Code.
// Query the "products-wishlist" collection to find if the product was already added to the user's wishlist.
letwishListResult = await wixData.query("products-wishlist")
.eq("product", product._id)
.eq("userId", user.id)
.find();
Your Code.
// Query the "FAVOTITE DB" collection to find if the product was already added to the user's wishlist.
letwishListResult = await wixData.query("Favoritos_DB")
.eq("product",product) // You are missing _id here //
.eq("userId",user.id)
.find();
Also, further down.
Wix Editor Code.
async function addToWishlist() {
// Create the wishlist item relating the current product to the current user.
letwishListItem = {
product: product._id,
userId: user.id
Your Code.
async function addToWishlist() {
// Create the wishlist item relating the current product to the current user.
letwishListItem = {
product:product, // You are missing _id here //
userId:user.id
};
Also, further down.
Wix Editor Code.
async functionremoveFromWishlist() {
// Query the "products-wishlist" collection to find the wishlist item corresponding to the current product and current user.
letwishListResult = await wixData.query("products-wishlist")
.eq("product", product._id)
.eq("userId", user.id)
.find();
Your Code.
async function removeFromWishlist() {
// Query the "products-wishlist" collection to find the wishlist item corresponding to the current product and current user.
letwishListResult = await wixData.query("Favoritos_DB")
.eq("product",product) // You are missing _id here //
.eq("userId",user.id)
.find();
You have to use product_id as the tutorial is built using the product_id and the current users ID.
Create the addToWishList function. Build the wishListItem object. This object contains the product ID for the current product and the ID of the current user.
Especially when you are removing the item through your remove function line with _id too
// Remove the wishlist item from the "products-wishlist" collection.
await wixData.remove("Favoritos_DB",wishListResult.items[0]._id)
}
Finally, as you are using a seperate dataset, instead of the Wix Stores collection, as you have been working in the preview mode and added all your info into your Favoritos_DB whilst there which would have been in the sandbox version of your dataset.
Just to check, have you made sure that you have synced this dataset from sandbox to live?
I thank you in advance for paying attention to this publication The code works fine but only works well in the preview, it does not work on the published page, I understand that there is a sandbox database and a live database. I test the functionality in the live bone database on the published page and it does not delete the item from the wish list when the filled heart icon is pressed. What should happen is that you delete the item from a database from a user because it would no longer be your wish but it does not happen. As I was saying it works perfect in preview but it fails on the page already published.
the project is about a directory of services that will end up embedded as an android application by webview
This is the url: https://lotengomobile.wixsite.com/lotengo
The design is still poor because I work on the functionality first.
If you can help me, I would be infinitely grateful.
By the way the code changes in the part where you suggest ._id because in the database it is identified differently, so it is not the same but as I said it is functional. Only it works in preview and not on the published page.
I managed to solve the problem, it was a permission in the database “only the administrator can delete data from this collection” to be activated in this way did not allow deleting when publishing and repeating the item because if it allowed to record in the database , this happened when I left the editing mode because in the editing mode I am an administrator. I thank everyone for their collaboration and patience, again forgive my bad English.
Well done for solving it, always ends up being something little mucking it all up!
As for bad English, you have got no worries with that, yours is much better than some English people I know with their own unique accents or before they even touch a drink