Hi, I’m really an amateur, I’ve been learning to compose a website for 6 months, I’ve gone through a lot of snags. I’m currently solving a problem with a broken code on a published website. I’ve read something about it, but I still don’t know how to solve this problem. Is the code only working on the test site URL, or is it a free version? I’m sending the code, it’s a review on a product page created through wix stores.
Have any of you been able to resolve this, could I ask for advice? Thank you very much!
import wixData from ‘wix-data’ ;
import wixWindow from ‘wix-window’ ;
import wixLocation from ‘wix-location’ ;
let product ;
$w . onReady ( async function () {
product = await $w ( ‘#productPage1’ ). getProduct ();
initReviews ();
wixLocation . onChange ( async ( location ) => {
product = await $w ( ‘#productPage1’ ). getProduct ();
initReviews ();
})
})
async function initReviews () {
await $w ( ‘#Reviews’ ). setFilter ( wixData . filter (). eq ( ‘productId’ , product . _id ));
showReviews ();
loadStatistics ();
}
async function loadStatistics () {
const stats = await wixData . get ( ‘review-stats’ , product . _id );
if ( stats ) {
let avgRating = ( Math . round ( stats . rating * 10 / stats . count ) / 10 );
let percentRecommended = Math . round ( stats . recommended / stats . count * 100 );
let ratings = $w ( ‘#generalRatings’ );
ratings . rating = avgRating ;
ratings . numRatings = stats . count ;
$w ( ‘#recoPercent’ ). text = ${ percentRecommended } % Doporučuje tento produkt
;
$w ( ‘#generalRatings’ ). show ();
} else {
$w ( ‘#recoPercent’ ). text = ‘Zatím žádná ohodnocení, budete první?’ ;
$w ( ‘#generalRatings’ ). hide ();
}
$w ( ‘#recoPercent’ ). show ();
}
export function reviewsRepeater_itemReady ( $w , itemData , index ) {
if ( itemData . recommends ) {
$w ( ‘#recommendation’ ). text = “Doporučuje tento produkt.” ;
} else {
$w ( ‘#recommendation’ ). text = “Nedoporučuje tento produkt.” ;
}
$w ( ‘#oneRating’ ). rating = itemData . rating ;
let date = itemData . _createdDate ;
$w ( ‘#submissionTime’ ). text = date . toLocaleString ();
}
export function showReviews () {
if ( $w ( ‘#Reviews’ ). getTotalCount () > 0 ) {
$w ( ‘#reviewsStrip’ ). expand ();
} else {
$w ( ‘#reviewsStrip’ ). collapse ();
}
}
export async function addReview_click ( event , $w ) {
const dataForLightbox = {
productId : product . _id
};
let result = await wixWindow . openLightbox ( ‘Review Box’ , dataForLightbox );
$w ( ‘#Reviews’ ). refresh ();
loadStatistics ();
$w ( ‘#thankYouMessage’ ). show ();
}
export function resultsPages_click ( event , $w ) {
$w ( ‘#Reviews’ ). loadMore ();
}