Developer forum

Forum » Development » API ProductList Sorting

API ProductList Sorting

Snaevar Petursson
Snaevar Petursson
Reply

Greetings! 

I'm trying to sort the results from the "/dwapi/ecommerce/products" endpoint using a GroupID without doing it on the client.
Is there a parameter like "sortby" I can use with the API? 
Tried "{CurrentPage: 1, Parameters: { sortby: "price" }}" and couple of variations of it to little success.

Is there a list somewhere of all the parameter options?

 

Kind regards,

Snævar


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Sneavar

That endpoint has 2 paths of execution.

If you specify a repository and a query, a lucene search is conducted and sortby, paging etc. will work for you as it is now. You can combine those 2 parameters with groupid if you have a parameter with an expression on the specified query that reacts to groupid and it will work.

When you use groupid alone, it is a database search. And that path of execution seems to have forgotten SortBy, SortOrder and Paging. I just added it #1844. Will be out for you in a week or so!

Votes for this answer: 1
 
Snaevar Petursson
Snaevar Petursson
Reply

Excellent thank you! 

 
Snaevar Petursson
Snaevar Petursson
Reply

Has this been updated yet? 

Updated to 9.10.11 and can't get it to work with neither of the 2 execution paths.

For the repository and query path of execution do you add it straight into the url or as a data parameter? (Tried both without any success).

Is there a chance you could provide an example request?

Kind regards,

Snævar 

 
Nicolai Pedersen
Reply

Hi Snaevar.

Searching a group using sortby:

It is a combination of querystring and body variables:

In the docs you can see it:

Parameters are the querystring parameters available. The ProductListViewmodelSettings is the post body and is an object that can be send as the body. The object is found in the bottom of the docs page in the "Schemas" section - see below:

As you can see, the post variables that is send, matches this object.

The object can also be send as a json object with values instead.

BR Nicolai

 
Snaevar Petursson
Snaevar Petursson
Reply

Hej Nicolai

Thanks for the detailed reply!

However for some reason this isn't working on my end.
Tried sorting by price, title, price without success.

 

If I post straight to a product app page, everything works fine so I don't think it's data related.
example: http://advaniavefverslun.local.dynamicweb.dk/vorusida?GroupID=GROUP588&SortBy=Price&SortOrder=Asc

Got any ideas what could be going wrong?

 

Best Regards,

Snævar

 
Nicolai Pedersen
Reply

You have sortby=price - should be sortby=productprice

You should get an exception when you use a wrong name in sort by:

 

 
Snaevar Petursson
Snaevar Petursson
Reply

Tried with both "Price" and "ProductPrice" did not seem to make a difference. The strange part is whatever value I put into the sortby query parameter it never returns an error.

So I updated another project to 9.10.11 and tried the request there with the same result. 

This surely feels strange. 

 

 
Nicolai Pedersen
Reply

Where do your prices come from? Product table price field, product prices table or live?

What happens if you include 'created' in your ProductSettings.FilledProperties and change to SortOrder=ProductCreated?

 
Nicolai Pedersen
Reply

And ensure you get the latest Dynamicweb.Ecommerce.webapi from nuget - it might be even newer than the one with the latest service release.

 
Snaevar Petursson
Snaevar Petursson
Reply

Sorry for the late reply.

We are using live prices.


Including "Created" in ProductSettings.FilledProperties and changing SortOrder=ProductCreated with ASC/DESC gave the same result.


 

 
Nicolai Pedersen
Reply

ok - you cannot sort on live prices. Lets say you search 100k products - should we then ask the live integration for all the prices and then sort? The sorting is only based on what is in the index. But that does not seem to be the issue here.

Esnure you upgrade to latest webapi and ecommerce packages. 

If that does not help, we need access to the solution to see what can be wrong. "It works on my machines" does not help you I guess....

 
Snaevar Petursson
Snaevar Petursson
Reply

Ye kind of figured with the live prices, but we have a backup product.field price for that particular store. Client only requires us to sort by name & created so it's fine. 
However i did not get it to work either after upgrading the Dynamicweb.Ecommerce.webapi dll from nuget.
Who do I contact with access information to our solution?

 
Nicolai Pedersen
Reply

If the solution has a public URL, you can send it to me.

If not, you have to make a copy of the solution and have our support download and install it on our test servers...

BR Nicolai

 
Khaing May Thaw
Reply

Hi Nicolai,

Good morning.

 

May I know can the product be sorted on the Live stock also?

We are also facing the same sorting issue. We don't use the Live price integration but had using the Live stock integration.

Kindly advise.

Thanks.

 

Best Regards,

Khaing May Thaw.

 
Nicolai Pedersen
Reply

Hi

No - live stock cannot be used for sorting.

I need a URL to your solution and the parameters that you have used for sorting so we can look into it.

BR Nicolai

 

You must be logged in to post in the forum