The last product I was in

hey,

I try to show the max 4 last product I was in, when I get to another page.

//product page 
let product;

$w.onReady(async function () {
 // Set the global product variable to the currently displayed product.
    product = await $w('#productPage1').getProduct(); 
    session.setItem("ProductW", product)// Load the current product's reviews using the initReviews() function.
    initReviews(); 
    loadRelatedProducts();
 

});
//Another page

import wixLocation from 'wix-location';
import {local, session} from 'wix-storage';
import wixData from 'wix-data';

$w.onReady(function () {
    $w('#repeater1').onItemReady(($w, itemData, index) => {
        $w('#image27').src = itemData.mainMedia;
        $w('#image27').link = itemData.productPageUrl;
        $w('#image27').alt = itemData.name;
 
        $w('#text149').text = itemData.name;
        $w('#text148').text = itemData.formattedDiscountedPrice;
 //$w('#addToCartIcon').onClick(()=>{$w('#shoppingCartIcon1').addToCart(itemData._id);});

   })
 var product = session.getItem("ProductW");
 
    wixData.query("Stores/Products")
    .limit(4)
    .contains('name', product)
    .find()
    .then(res => {
            $w('#repeater1').data = res.items;
 let items = res.items;
 let firstItem = items[0];
 let totalCount = res.totalCount;
 let pageSize = res.pageSize;
 let currentPage = res.currentPage;
 let totalPages = res.totalPages;
 let hasNext = res.hasNext();
 let hasPrev = res.hasPrev();
 let length = res.length;
 let query = res.query;
        })
        .catch(err => {
            console.log('err', err)
        })//TODO: write your page related code here...

});

thank

?

Hi,

product = await $w('#productPage1').getProduct();
session.setItem("ProductW", product)

product is an object and setItem method is expecting a string.
For more information:

Roi.

Hi @Roi Bendet,

First of all thank you for answering, appreciate it.
I understood what you were saying
and if I do this

 product = await $w('#productPage1').getProduct(); session.setItem("ProductW", product._id) 

Is it should works?
I am not a code master, I am trying my best to solve this

Thanks and have a good day,
Yair.