How to get the product ID from wix product page

Hello,

So I have a dataset with links to create a Direct Debit with a payment system (GoCardless). for multiple products.

Now I have a separate dynamic pages set up with how often the payments to be taken (1 week…2.3.4.5.6…) this dataset has a connections to store . Im wanting to make a link to these pages. But getting the ID to then filter and if null hide elements else show, seems to be very difficult…

What I need to do is apply a filter to #dataset1, column product ref = with the product ID of the product shown on product page.

If the dataset results show >0 it will then expand the #columstrip9 which will have the process on maybe some more selling points etc! but if the dataset show null then this will be kept collapsed.

If you could give me so direction on

  1. how to get the products id from #productPage1
  2. how to take that and filter the #dataset1.
  3. then how to show #columnstrip9 if results >0 else collapse.

How do I get the product ID for each product in my store?

I’ll answer your questions.

1. Get the product ID:

Inside the page $w.onReady() function use these lines.

let product;
$w.onReady(async () => {
    product = await $w('#productPage1').getProduct();

})

2. Filter the dataset with the product ID:

You need to create an onReady() function for the dataset inside the page $w.onReady() function.

$w('#dataset1').setFilter(wixData.filter().eq('productID', product._id));

3. Show the strip if there’s a matching results:

We’ll use the previous filter to get the total matching items, and then expand/show the strip accordingly. Inside the dataset onReady() function ,paste these lines.

let totalCount = $w('#dataset1').getTotalCount()

if (totalCount > 0) {
    $w('#columnstrip9').expand();
} else {
    // Code to run if otherwise
}

That’s it, I hope that it helped.
Ahmad

Didn’t notice that it’s an old post before I finish the answer and post it :joy:
This thread should be closed.

Really appreciate you getting back to me! I’m not very good with the coding… trying to create and upload a csv file for one of the reviews apps and it asks for product ID. Was hoping there was an easier way to access that, maybe in the store products section or something. I may try what you shared. Thanks again!