How to make a favorites page for users?

Anyone here has an idea how to make a favorites page for users to simply click on a button
and the dynamic page item added to your favorites?

My idea is like this:
The items on the site are all in a list when you open an item from that list and display all the data from it, somewhere on the ietm page add a “send” button in the image format that sends the link of the current item, image link and a text that would be the name,
to a second database set up so only the “content creators see” so no one sees the favorites of others, the page to display this list of favorites is not complicated to do is just use a repeater.

The problem is how to configure this button of image, it is necessary that it take the data and send to another database, as only to connect it to a database at a time it would be necessary to make the sending part connected and the part of data capture of the current page with code, but I do not know anything about programming.

Is anyone there willing to try? I have tried several times without using the code and I could not.

1 Like

Hi @vortex-club !

You’re on the right track.

Say all the items are in the Items collection. Them there’s the second database collection, let’s call it Favorites . In this collection, add a Reference field, named Item , and choose the Items collection as the Referenced Collection.
Also for the Favorites collection permissions , choose Site member author for the Read, Update, Delete roles and Site member for the Create role.

Then create a Favorites page with a repeater. Add a dataset which connects to the Favorites collection and you’ll be able to access the fields from the Items collection as well.

Now the way you add new items to the Favorites collection is pretty straightforward.
Add the onClick event handler to your button in the dynamic item page:

import wixData from 'wix-data';

export function button1_click(event) {
  const item = $w('#dataset1').getCurrentItem();
  wixData.insert('Favorites', { item });
}

Note that with this code, you can add an item to the Favorites multiple times and that is probably not what you want. But first make sure this works.

Good luck,
Vytautas

1 Like

Hi @vytautast thank you very much for the help.
With your help I got it, I got confused in parts because I had mistakenly created the collection hahahaha

Regarding the item being displayed multiple times, I thought about setting it to be hidden when the item is already in the “Favorites” database, I already did this with buttons with a link.
Example, when the button attached to the database does not have the external link, it is hidden.

// Show button if it has a link and does not show if link is missing
    $w.onReady(() => {
        $w("#dynamicDataset").onReady(() => {
 // Gets the current item properties and stores them in a variable called item
 const item = $w("#dynamicDataset").getCurrentItem();
 // Checks if the current item has a value in the "video" field
 if (!item.trailer) {
 // Collapses the video player if there is no value for "video"
                $w("#button13").collapse();
            }
        });
    });

I will try the same code to hide the “add favorites” button to see if this prevents the same item from being repeated in the person list, I do not know if it will work because it is a “reference” item.
I’ll look for a code that displays the “Remove from Favorites” button when the “Add Favorites” button.
I’ll try to match the above code and code below to try to do this before, sort of expecting defeat, but in case I hit even better. haha ha

1 Like

Check this out: Velo Tutorial: Adding a Wishlist to a Wix Stores Site | Help Center | Wix.com

2 Likes

I tried implementing this to a non-store repeater, but I think my get function at step 4 is where I’m going wrong. im still looking for guidance. thanks I’m advance.

Have you had success with a ”toggle to favorites”