Developer forum

Forum » Ecommerce - Standard features » Get all Products ID's from product list

Get all Products ID's from product list

Mario Santos
Reply

Hi,

I have a product list with 30 pages, is that possible (using the API maybe?) to get all Products ID's of all 30 pages when viewing a single page?

I need this to query the database for some values I can't get out of the index or product list, but it requires the entire list.

Thank you, Mário


Replies

 
Nicolai Pedersen
Reply

No, that is not possible. We only retrieve a subset of the results - so we just know how many there is. So if you query the index and you pagesize is 20, we get only 20 IDs from the index (or database if not using an index).

Using the Notifications.eCommerce.Querying.AfterQuery notification (if you use the new index), you get an argument object where you have a Settings property of type Dynamicweb.Querying.QuerySettings

Create a notification subscriber, and change the Settings.Take to i.e. 1000 (or how many you want) and set the Settings.Skip to 0 (will always be 0 on page 1) and execute the search on the index again:

Dim result As Dynamicweb.Querying.IQueryResult = ServiceLocator.Current.GetInstance(Of Querying.IQueryService)().Query(query, querySetting)

Now the result should give you the product auto ids:

Dim autoIDs As New List(Of Int64)
For Each element In result.QueryResult
    Dim dict = DirectCast(element, Dictionary(Of String, Object))
    Dim autoId = DirectCast(dict("AutoID"), Int64)
    autoIDs.Add(autoId)
Next

 

 

You must be logged in to post in the forum