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?
ProductDataSource.LoadForCategory - Valid Sortstring?
Re: ProductDataSource.LoadForCategory - Valid Sortstring?
All ac_Products table column names can be used for sorting.
-
- Lieutenant Commander (LCDR)
- Posts: 102
- Joined: Wed Apr 02, 2008 11:00 am
- Location: Stockholm, Sweden
- Contact:
Re: ProductDataSource.LoadForCategory - Valid Sortstring?
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.mazhar wrote:All ac_Products table column names can be used for sorting.
Re: ProductDataSource.LoadForCategory - Valid Sortstring?
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
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.
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);
}
}
-
- Lieutenant Commander (LCDR)
- Posts: 102
- Joined: Wed Apr 02, 2008 11:00 am
- Location: Stockholm, Sweden
- Contact:
Re: ProductDataSource.LoadForCategory - Valid Sortstring?
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 codewhere 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.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); } }
Perfect, thank you!