top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
![feature fixed.png](https://static.wixstatic.com/media/3bfa8a_f845e1016b8a49758acdd6edd6610c3b~mv2.png/v1/crop/x_0,y_2,w_852,h_508/fill/w_104,h_62,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/feature%20fixed.png)
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
I've tried again to add related products by wix code and still do not work
please inform me what's wrong and what can I do
Hi, I'm a beginner in Wix Code and I was wondering how I add more than 1 related products.I checked the tutorials and my related products are working, but I only have one of them and I would love to have three related products. Can someone tell me what I have to add?This is the product part in my Javascript at the productpage right now:
// Find related products in the relationship collection by querying for related products in both relation directions. 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() ]); // Merge related products found from both sides of the relationship collection. let relatedProducts = [ ...relatedByTable[0].items.map(_ => _.productB), ...relatedByTable[1].items.map(_ => _.productA) ];
Thank you.
I'm having the same problem as Andrew. Does anyone know what we might be doing wrong?
I'm having trouble with getting related products to change when I select one. Say I select Product 1 in the store, and Products 2-4 have been related. If i click Product 2, it takes me to that page and then I get Products 2-4 as related again. I have tried playing around with the database with no change.
I have a question. If you're using the <prev | next > on the product page - how when you select the 'next' or 'previous' page do you get the related item to follow? Or have I set something up wrong?
Hi Ahmed Bakr
The error in $w('# productPage'). getproduct does not prevent the code from working, in the API reference has this function. Now for the loadRelatedProduct I would need to see your code to understand where the error is. Contact me through my email so I can help you better raphakatz1985@gmail.com
when i write loadrelatedproducts, it shows error that its not defined, even though i added the collection page related products in the database
@raphaela katz,
I am kind of new to wix code, and it seems like i cant get the code to work... when i write in the get product line it tells shows error!
Hello,
This line let product = await $ w ('# productPage'). GetProduct () says:
take the product that is currently being displayed on the product page and name the variable product
and then lookup the code in the related product table that you created, if you have any related product that needs to be added manually
if there is no related product in the table the code goes to the Store / Products collection where all your products are and search for products 20% cheaper and 20% more expensive
as you add products may happen the older ones not being in the criterion of 20% more expensive or cheaper
in this case you need to ensure that older products are in the collection of related products to all the products that you display them, only this way you will ensure that everything works correctly
I used this code a few weeks ago to do related products and other things on my site and it worked fine.
Today I noticed that the code has stopped working for older products on my site, but ones I added in the last week the code still works fine.
For the older products it cannot load the product from the product using the line:
let product = await $w('#productPage').getProduct()
But for newer products this line executes as expected.
Has something changed in wix?
Thanks Raphaela, it worked perfectly!
Hi Allan,
I worked the code this way and I believe it got faster.
function relatedItemReady($w, product){
$w("#productImage").src = product.mainMedia;
$w("#productName").text = product.name;
$w("#productPrice").text = product.formattedPrice;
$w('#productImage').onClick(() => {
wixLocation.to("https://yoursiteurl/product-page/" + product.slug);
});
}
Have you tried updating your browser? I use Chrome and it works.
Can't see related items box using google chrome - only white space.
Actually, if you change the example code for function relatedItemReady to the following, it might just work.
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); setTimeout(() => { wixLocation.to(wixLocation.url); }, 200) }) }
I had this problem, have you tried using?
location.reload ();
Hi Pasymart,
The products seem to be missing in the example. The code works though. I have however been recommended to use dataset instead with the following logic,
$w.onReady(function () {
$w("#productPage1").getProduct().then(x => console.log(x.slug)).catch(console.log)
// #productImage is inside a repeater
$w("#productImage").onClick((event, $w) => {
console.log($w("#dataset1").getCurrentItem().slug);
})
});
Not working on view the example !
Many thanks for the example, I was looking for a way to create related products and when entering the wix facebook group and I saw the presentation of your example. Thank you again.
I'm still a programming language student and I still need exmple to develop my code.
With related products would it be possible to also create products RECENTLY VIEWED? If yes, can you create some examples?
I found an example of recipe reviews in the wix code examples. Do you have some other example that works best with wix store?
I saw that you used async / await to improve the page load, could it be used in other elements on the home page to improve loading too?
I hope so!