Sort products by the "News" field

When adding the “News” field on a product, and setting the date, I still can’t sort by the “New products” sorting. The problem is that nothing is sorted by that field. Not sure what more to do here, am I missing something?

Litium version: 7.6.2

What is the Id of your News field?
And what exact Litium version are you running?

I use the already defined field “News” in the product area, on the base products.

Sorry, 7.6.2

I have tried on a 7.6.2 Accelerator and it works.
The field should be connected to the variant and you should give it a date in the same culture of the channel.
I get the latest 3 month to work but Latest Months seems not to work maybe some Accelerator code changes needed.

Ok, it seems to be wrong translation on the Accelerator, first checkbox should be Latest Month and the second is Last 3 months and they both work properly.
If you need to change the interval then you can do it in FilterAggregator.cs.

If you only mean Sorting from the Dropdown then that also works correctly.

Are you using Elasticsearch?

Sorry, forgot to mention, yes I use elasticsearch.

I refer to sorting by the dropdown on the category page.

You can report a bug on this please.

Seems like the issue is with indexing the value for the News field, it’s not taking culture into account.

In ProductIndexDocumentBuilder, can try you changing PopulateNewsDate to

private void PopulateNewsDate(ProductDocument model, BaseProduct baseProduct, IList<Variant> variants, bool forBaseProduct, CultureInfo cultureInfo)
{
	const string field = "News";
	model.NewsDate = forBaseProduct
		? (baseProduct.Fields.GetValue<DateTimeOffset?>(field, cultureInfo) ?? variants.Select(x => x.Fields.GetValue<DateTimeOffset?>(field, cultureInfo)).Where(x => x.HasValue).FirstOrDefault())?.UtcDateTime
		: (variants.Select(x => x.Fields.GetValue<DateTimeOffset?>(field, cultureInfo)).Where(x => x.HasValue).FirstOrDefault() ?? baseProduct.Fields.GetValue<DateTimeOffset?>(field, cultureInfo))?.UtcDateTime;
}

And it’s reference to

PopulateNewsDate(model, context.BaseProduct, variants, forBaseProduct, cultureInfo);

Created a bug: https://docs.litium.com/support/bugs/bug_details?id=57486

2 Likes