Some bugs on the site

Hey,
I have some bugs on the site I have attached a video in addition

1.I used this guide https://www.wix.com/code/home/forum/wix-tips-and-updates/new-example-wix-stores-related-products for related products, but in the editor they appear. And on the Live site they do not.

2.I used this guide https://www.wix.com/code/home/forum/wix-tips-and-updates/new-example-wix-stores-wishlist for wishlist - But there are some bugs here.
1. When the user is not connected, the group appears but the text itself does not appear.
2. When connecting, it still does not allow the product to be added to the wish list only after I leave the product and return to it.
3. In the wish list itself it does not show the product its name and price even though everything is set properly.

My site - www.topink.co.il

I would be very happy if someone could help me on these issues thoroughly

it’s urgent

 
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
let product;
let user = wixUsers.currentUser;

$w.onReady(async function () {
    loadRelatedProducts();
    checkWishlist();
    product = await $w('#productPage').getProduct();
    $w('#loginMessage').onClick(loginMessageClick);
});

async function loadRelatedProducts() {
    product = await $w('#productPage').getProduct();
 let relatedProductResults = await Promise.all([
        relatedProductsByTable(product),
        ]);
 if (relatedProductResults[0].length > 0)
        showRelatedProducts(relatedProductResults[0]);
 else
        showRelatedProducts(relatedProductResults[1]);
}

async function relatedProductsByTable(product) {
 let productId = product._id;

 // find related products by relation table
 let relatedByTable = await Promise.all([
        wixData.query('related-products')
        .eq('productA', productId)
        .include('productB')
        .find(),
        wixData.query('related-products')
        .eq('productB', productId)
        .include('productA')
        .find()
    ]);

 let relatedProducts = [
        ...relatedByTable[0].items.map(_ => _.productB),
        ...relatedByTable[1].items.map(_ => _.productA)
    ];
 return relatedProducts;
}


function showRelatedProducts(relatedProducts){
 if(relatedProducts.length > 0){
        relatedProducts.splice(4, relatedProducts.length);
        $w('#relatedItemsRepeater').onItemReady(relatedItemReady);
        $w("#relatedItemsRepeater").data = relatedProducts;
        $w("#relatedItems").expand();
    }
 else {
        $w("#relatedItems").collapse();
    }
}

function relatedItemReady($w, product){
    $w("#productImage").src = product.mainMedia;
    $w("#productName").text = product.name;
    $w("#productPrice").text = product.formattedPrice;
    $w('#productImage').onClick(() => {
        wixLocation.to(product.productPageUrl);
    });
}


export function inWishList_click(event, $w) {
 if (user.loggedIn) 
        removeFromWishlist();
}

export function notInWishList_click(event, $w) {
 if (user.loggedIn) 
        addToWishlist()
 else 
        $w('#loginMessage').show();
}

async function loginMessageClick() {
 let options = {"mode": "login"};
    $w('#loginMessage').hide();
 await wixUsers.promptLogin(options);
}

//Wishlist

async function addToWishlist() {
 let wishListItem = {
        product: product._id, 
        userId: user.id
    };
 
    $w('#notInWishList').hide('fade', {duration: 100});
    $w('#inWishList').show('fade', {duration: 100});
 let result = await wixData.insert("products-wishlist", wishListItem);
}

async function removeFromWishlist() {
 let wishListResult = await wixData.query("products-wishlist")
        .eq("product", product._id)
        .eq("userId", user.id)
        .find();

 if (wishListResult.length > 0) {
        $w('#notInWishList').show('fade', {duration: 100});
        $w('#inWishList').hide('fade', {duration: 100});
 await wixData.remove("products-wishlist", wishListResult.items[0]._id)
    }
}

async function checkWishlist() {
 if (wixUsers.currentUser.loggedIn) {
 let wishListResult = await wixData.query("products-wishlist")
            .eq("product", product._id)
            .eq("userId", user.id)
            .find();

 if(wishListResult.items.length > 0)
            $w('#inWishList').show('fade', {duration: 100});
 else
            $w('#notInWishList').show('fade', {duration: 100}); 
    }
 else {
        $w('#notInWishList').show('fade', {duration: 100});
    }
}


Hi,
Please review the answers below:

  1. I recommend checking the collection’s permissions . Moreover, I recommend checking whether you’ve synced the collection to the live site.
  2. I’m afraid that we cannot debug your entire code… Do you have a more specific question regarding a certain function? I recommending reading this article which explains how to debug your code.

Good luck,
Tal.