Developer forum

Forum » Dynamicweb 10 » Default sort option not working

Default sort option not working

Vincent Gercke
Reply

Hello. We are experiencing that setting a default sort option on a query has no effect. I've tried to debug the source code and here are my findings:

In the case below we have 1 default sort order present in defaultValues, but the value false are always being passed as the third parameter in the method returning the sort info.

As I see it this results in defaultValues never being returned in the case of an empty result:

We can explicitly set the sort order up on each product catalogue app, but we need to be able to control the sort order for a certain query globally.

BR Vincent


Replies

 
Vincent Gercke
Reply

It seems like queryJson is a string with the value "null", which means the check on line 625 returns false.

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Vincent,

How are you specifying the default sorting if you're not using the app settings on the paragraph? I assume it's a notification, but which one?

From the screenshots, it seems like you're trying to change the app settings on the fly. If you need to change sorting, any setting really, for the query execution from the Product Catalog, you should subscribe to the Dynamicweb.Ecommerce.Notification.Ecommerce.Querying.BeforeQuery notification and manipulate the QuerySettings object. That notification is fired after the product catalog has processed the app settings, leaving you free to change it.

Note that if you change to using the Product Catalog for ViewModels app at some point, there is no dedicated BeforeQuery notification for the app to subscribe to. You need subscribe to the general Dynamicweb.Indexing.Notifications.Query.BeforeQuery instead.

If you can provide a little more context, I might be able to help further.

- Jeppe

 
Vincent Gercke
Reply

Hi Jeppe

Thanks for the reply! The sorting is not set in a observer, just on the query it self:


 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Okay, that narrows it down. I was just confused by the statement "We can explicitly set the sort order up on each product catalogue app, but we need to be able to control the sort order for a certain query globally" in your first post.

If you're specifying the sort order on the app, it should work. I have just tested it locally. Which version are you running?

I have seen the values of those app settings being the string "null" previously on standard Swift v1 sites, but it should be set correctly when you change it.

- Jeppe

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

I think the penny finally dropped for me :)

When the app settings has an invalid sort value, like "null", the JSON parsing fails (or produces a null object). This causes the method to return the default sort settings from the query, because result is null. Therefore, with invalid JSON and a default sort specified on the query, it should work as expected, which is also what I'm seeing here.

If you can provide the version you're running, I can look into that. Otherwise, you may have to create a ticket with Care.

- Jeppe

 
Vincent Gercke
Reply

Exactly! The version I'm running is 10.17.3. When I'm debugging it returns "null" or "[ ]" as string and not a null object. Let me know if have time for a quick Teams call this week, then I'll be able to show you :-)

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

I have created a bug report for the issue, #24974. You can track it here: https://doc.dynamicweb.dev/documentation/fundamentals/dw10release/releasenotes/workItemInfo.html

Hopefully, it'll be released next week, but due to summer vacation I cannot guarantee that. In the meantime, you can work around the issue by subscribing to one of the notifications I mentioned in a previous post, allowing you to override the sorting with the one coming from the query.

- Jeppe

Votes for this answer: 1
 
Vincent Gercke
Reply

Great, thanks! :-)

 

You must be logged in to post in the forum