We need to use LoadForCriteria for a certain aspect of our site, but it doesn't support the "default" admin sort order, nor does it support sorting by manufacturer name.
Would be awesome if ProductDataSource.LoadForCriteria had the ability to sort by manufacturer and the catalog node order by.
Alternatively, if ProductDataSource.NarrowSearch had the ability to have criteria specified, that would be equally awesome.
ProductDataSource.LoadForCriteria Add Ability to Sort...
Re: ProductDataSource.LoadForCriteria Add Ability to Sort...
LoadForCriteria method load products according to admin default order. I think may be you provide some sort expression in sortExpression parameter,It should be empty or just pass 'string.empty' as sortExpression like thissweeperq wrote:We need to use LoadForCriteria for a certain aspect of our site, but it doesn't support the "default" admin sort order.
Code: Select all
ProductDataSource.LoadForCriteria("YOUR_SEARCH_CRITERIA", string.Empty)
For sorting by manufacturer you need to write a custom query. ProductDataSource.LoadForCriteria method don't support sorting by manufacturer. To write a custom query have a look at this one http://wiki.ablecommerce.com/index.php/Custom_Queriessweeperq wrote: nor does it support sorting by manufacturer name.
Would be awesome if ProductDataSource.LoadForCriteria had the ability to sort by manufacturer and the catalog node order by.
Using ProductDataSource.NarrowSearch you can sort like thissweeperq wrote: if ProductDataSource.NarrowSearch had the ability to have criteria specified, that would be equally awesome.
Code: Select all
List<Product> products = ProductDataSource.NarrowSearch("YOUR_SEARCH_CRITERIA", 0, 0, 0, 0, "Manufacturer");
hope this helps!
__________________
s_ismail
AbleCommerce Customization
Free Plugins and Add-Ons
AbleCommerce Plugins and Add-Ons
Plugables Blog
__________________
s_ismail
AbleCommerce Customization
Free Plugins and Add-Ons
AbleCommerce Plugins and Add-Ons
Plugables Blog
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: ProductDataSource.LoadForCriteria Add Ability to Sort...
The loadforcriteria produces a sortable collection, so you should be able to add sorting after it loads. If you Google on sortable collection C# you will find some code. You can also follow the pattern of Able's comparer on a page like CategoryGrid4
Code: Select all
private class ManufacturerComparer : IComparer
{
SortDirection _SortDirection;
public ManufacturerComparer(SortDirection sortDirection)
{
_SortDirection = sortDirection;
}
#region IComparer Members
public int Compare(object x, object y)
{
string xMan = string.Empty;
Product pX = null;
if (((CatalogNode)x).CatalogNodeType == CatalogNodeType.Product)
pX = ((Product)((CatalogNode)x).ChildObject);
if ((pX != null) && (pX.Manufacturer != null)) xMan = pX.Manufacturer.Name;
string yMan = string.Empty;
Product pY = null;
if (((CatalogNode)y).CatalogNodeType == CatalogNodeType.Product)
pY = ((Product)((CatalogNode)y).ChildObject);
if ((pY != null) && (pY.Manufacturer != null)) yMan = pY.Manufacturer.Name;
if (_SortDirection == SortDirection.Ascending)
return (xMan.CompareTo(yMan));
return (yMan.CompareTo(xMan));
}
#endregion
}
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: ProductDataSource.LoadForCriteria Add Ability to Sort...
Thanks for the responses. s_ismail, what I'm seeing when passing an empty string for the sort order is that the products are loading by ProductId ASC, not the order that I have assigned them in the Admin. The problem with custom queries is that I have not seen how I can populate a set of objects with them. And for the NarrowSearch, it accepts a search string ("Diabetic Socks"), not boolean SQL criteria ("ProductID IN (5, 9, 10)").
Judy, thanks for going through the trouble of putting together that snippet of code for me. I thought about doing that, but the categories have several products so there is paging involved. If I do as suggested, the query would return a page of products, then I would sort the collection on manufacturer. Problem is that the manufacturer may be represented on pages 1, 2, and 3, so they won't all be sorted together as intended.
Judy, thanks for going through the trouble of putting together that snippet of code for me. I thought about doing that, but the categories have several products so there is paging involved. If I do as suggested, the query would return a page of products, then I would sort the collection on manufacturer. Problem is that the manufacturer may be represented on pages 1, 2, and 3, so they won't all be sorted together as intended.