Ordering products by custom field

Posted by Community Admin on 04-Aug-2018 15:01

Ordering products by custom field

All Replies

Posted by Community Admin on 20-Mar-2013 00:00

I'm sure this is possible but I'm struggling to get it working. I have a custom field ("Ordinal") created in each of my product types. In my product select query I'm trying to order the products by this value using:

catManager.GetProducts().Where(p => p.GetValue<TrackedList<Guid>>("Department").Contains(Department.Id) && p.IsActive).OrderBy(p => p.GetValue<decimal?>("Ordinal"));

Unfortunately I only get this error:

Database mapped field does not exist.
Parameter name: methodCallExpression
Actual value was p.FieldValue("Ordinal").

What's the correct syntax for implementing this ordering?

thanks

Posted by Community Admin on 23-Mar-2013 00:00

Hi Nick,

I have answered you in your support ticket.

Kind regards,
Randy Hodge
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 12-Apr-2013 00:00

For everyone else who experiences this here is the outcome. This is bug, a workaround is to include .ToList() in the statement, e.g.

var products = catalogMgr.GetProducts().Where(p => p.IsActive).ToList().OrderBy(p =>
p.GetValue<Decimal>("NumberField1"));

Also, it's in PITS to vote and track here: www.telerik.com/.../pits.aspx

Posted by Community Admin on 02-May-2014 00:00

Is this bug resolved yet? Because this means you have to materialize the collection before you can filter it, which is a major performance issue if you have large quantities of data.

Posted by Community Admin on 02-May-2014 00:00

I would cry from happiness if there is a proper solution for this

Posted by Community Admin on 07-May-2014 00:00

Hello,

In order to make this work you have to specify on which product type this custom field is. For example: CatalogManager.GetManager("catalogProvider15").GetProducts("Telerik.Sitefinity.DynamicTypes.Model.sf_ec_prdct_testproducttype").Where(p => p.OriginalContentId != Guid.Empty && p.GetValue<string>("customFieldString") != "string1").OrderBy(p => p.GetValue<DateTime?>("testDate")).ToList();

This way, you do not have to load the whole collection before doing it. 

I hope this helps.

Regards,
Atanas Valchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 07-May-2014 00:00

That may work for a single product type, but in our situation we needed products from multiple product types, and to order them using a custom field that exists for every product type.

Posted by Community Admin on 07-May-2014 00:00

We only have one type of product in our site so this solution saved me!! Thanks

This thread is closed