Page 1 of 1

ProductDataSource.LoadForCategory - Valid Sortstring?

Posted: Tue Dec 15, 2015 4:55 am
by Odettes
Hi!

When using ProductDataSource.LoadForCategory, for example:
var products = ProductDataSource.LoadForCategory(true, _Category.Id, false, true, "OrderBy", 50, 0);

What sort strings are valid and can be used?
OrderBy DESC and OrderBy ASC works fine, but I want my products to sort as stored in the database column "ac_CatalogNodes.OrderBy".
How do I do that?

Any ideas?

Re: ProductDataSource.LoadForCategory - Valid Sortstring?

Posted: Tue Dec 15, 2015 5:55 am
by mazhar
All ac_Products table column names can be used for sorting.

Re: ProductDataSource.LoadForCategory - Valid Sortstring?

Posted: Tue Dec 15, 2015 6:07 am
by Odettes
mazhar wrote:All ac_Products table column names can be used for sorting.
Great, but I need to sort it using column OrderBy in table CatalogNodes to get the same order as in the admin interface for my selected category.

Re: ProductDataSource.LoadForCategory - Valid Sortstring?

Posted: Tue Dec 15, 2015 6:44 am
by mazhar
Then you should use CatalogDataSource.LoadForCategory instead. This will return the list of catalog nodes within a category sorted by OrderBy attribute. Node could be of type Product, Category, Webpage or Link. So you will need to check type before you them. Here is the example code

Code: Select all

IList<CatalogNode> nodes = CatalogDataSource.LoadForCategory(CategoryId, publicOnly);
                List<Product> products = new List<Product>();
                foreach (CatalogNode node in nodes)
                {
                    if (node.CatalogNodeType == CatalogNodeType.Product)
                    {
                        products.Add((Product)node.ChildObject);
                    }
                }
where CategoryId will be the id of category you want to load the products from while publicOnly will be Boolean value to flag whether to load public nodes only.

Re: ProductDataSource.LoadForCategory - Valid Sortstring?

Posted: Tue Dec 15, 2015 11:47 am
by Odettes
mazhar wrote:Then you should use CatalogDataSource.LoadForCategory instead. This will return the list of catalog nodes within a category sorted by OrderBy attribute. Node could be of type Product, Category, Webpage or Link. So you will need to check type before you them. Here is the example code

Code: Select all

IList<CatalogNode> nodes = CatalogDataSource.LoadForCategory(CategoryId, publicOnly);
                List<Product> products = new List<Product>();
                foreach (CatalogNode node in nodes)
                {
                    if (node.CatalogNodeType == CatalogNodeType.Product)
                    {
                        products.Add((Product)node.ChildObject);
                    }
                }
where CategoryId will be the id of category you want to load the products from while publicOnly will be Boolean value to flag whether to load public nodes only.

Perfect, thank you!