ProductDataSource.LoadForCategory - Valid Sortstring?

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
Odettes
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 102
Joined: Wed Apr 02, 2008 11:00 am
Location: Stockholm, Sweden
Contact:

ProductDataSource.LoadForCategory - Valid Sortstring?

Post by Odettes » Tue Dec 15, 2015 4:55 am

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?
Sincerely,
Thomas Berglund

https://traileronline.se
AbleCommerce Gold R11 Custom

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5082
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: ProductDataSource.LoadForCategory - Valid Sortstring?

Post by mazhar » Tue Dec 15, 2015 5:55 am

All ac_Products table column names can be used for sorting.

Odettes
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 102
Joined: Wed Apr 02, 2008 11:00 am
Location: Stockholm, Sweden
Contact:

Re: ProductDataSource.LoadForCategory - Valid Sortstring?

Post by Odettes » Tue Dec 15, 2015 6:07 am

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.
Sincerely,
Thomas Berglund

https://traileronline.se
AbleCommerce Gold R11 Custom

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5082
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: ProductDataSource.LoadForCategory - Valid Sortstring?

Post by mazhar » Tue Dec 15, 2015 6:44 am

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.

Odettes
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 102
Joined: Wed Apr 02, 2008 11:00 am
Location: Stockholm, Sweden
Contact:

Re: ProductDataSource.LoadForCategory - Valid Sortstring?

Post by Odettes » Tue Dec 15, 2015 11:47 am

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!
Sincerely,
Thomas Berglund

https://traileronline.se
AbleCommerce Gold R11 Custom

Post Reply