adding to the sort dropdown
- ryanstowasser
- Lieutenant Commander (LCDR)
- Posts: 90
- Joined: Tue Oct 30, 2007 4:28 pm
- Contact:
adding to the sort dropdown
I am new to ablecommerce, and I really like it so far. One thing that I have not been able to do is add items to the Sort dropdown on the Category page.
I can add options to the dropdown, but can not connect them to relevent data.
I am running rc1 of 7.0, so I don't have access to the source code of the business objects and I cannot figure out how to define a product attribute that I can then sort by using the dropdown.
The dropdown's options currently include : "Featured", ascending and descending "Price", "Name" and "Manufacturer"
Any help or direction would be greatly appreciated.
thanks,
ryan
I can add options to the dropdown, but can not connect them to relevent data.
I am running rc1 of 7.0, so I don't have access to the source code of the business objects and I cannot figure out how to define a product attribute that I can then sort by using the dropdown.
The dropdown's options currently include : "Featured", ascending and descending "Price", "Name" and "Manufacturer"
Any help or direction would be greatly appreciated.
thanks,
ryan
- Shopping Cart Admin
- AbleCommerce Admin
- Posts: 3055
- Joined: Mon Dec 01, 2003 8:41 pm
- Location: Vancouver, WA
- Contact:
Hello Ryan,
This would require customization as it sits now. I've seen this come a few times since 7.0 release, so it's certainly seems like it should be a feature some day. Not quite sure how to implement it into the software but it does come up.
This would require customization as it sits now. I've seen this come a few times since 7.0 release, so it's certainly seems like it should be a feature some day. Not quite sure how to implement it into the software but it does come up.
Last edited by Shopping Cart Admin on Tue Nov 06, 2007 6:33 pm, edited 1 time in total.
- ryanstowasser
- Lieutenant Commander (LCDR)
- Posts: 90
- Joined: Tue Oct 30, 2007 4:28 pm
- Contact:
customization
I want to customize it myself. How would I go about getting to the code behind in the compiled dlls?
Ryan
Ryan
- Shopping Cart Admin
- AbleCommerce Admin
- Posts: 3055
- Joined: Mon Dec 01, 2003 8:41 pm
- Location: Vancouver, WA
- Contact:
Depending on the page your are using the code for this is in the corresponding control in the ConLib folder.
For example if you are using CategoryGridPage2 for displaying Categories, you will find the corresponding code in Conlib\CategoryGridPage2.ascx
Here is the code from this file that displays the Sort By Drop down...
You can add as many options as you like here.... but you will have to write the corresponding code to handle the even for the new options.
Here is the code from CategoryGridPage2.ascx.cs which is handling the current options. Add your option in the switch case and handle it accordingly...
For example if you are using CategoryGridPage2 for displaying Categories, you will find the corresponding code in Conlib\CategoryGridPage2.ascx
Here is the code from this file that displays the Sort By Drop down...
Code: Select all
<div class="searchSortHeader">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
<td align="left">
<asp:Localize ID="ResultIndexMessage" runat="server" Text="Displaying items {0} - {1} of {2}" EnableViewState="false"></asp:Localize>
</td>
<td align="right">
<asp:Label ID="SortResultsLabel" runat="server" Text="Sort:" SkinID="FieldHeader" EnableViewState="false" AssociatedControlID="SortResults"></asp:Label>
<asp:DropDownList ID="SortResults" runat="server" AutoPostBack="true" CssClass="sorting" EnableViewState="false">
<asp:ListItem Text="By Name (A -> Z)" Value="Name ASC"></asp:ListItem>
<asp:ListItem Text="By Name (Z -> A)" Value="Name DESC"></asp:ListItem>
<asp:ListItem Text="Featured" Value="IsFeatured DESC, Name ASC"></asp:ListItem>
<asp:ListItem Text="By Price (Low to High)" Value="Price ASC"></asp:ListItem>
<asp:ListItem Text="By Price (High to Low)" Value="Price DESC"></asp:ListItem>
<asp:ListItem Text="By Manufacturer (A -> Z)" Value="Manufacturer ASC"></asp:ListItem>
<asp:ListItem Text="By Manufacturer (Z -> A)" Value="Manufacturer DESC"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</div>
You can add as many options as you like here.... but you will have to write the corresponding code to handle the even for the new options.
Here is the code from CategoryGridPage2.ascx.cs which is handling the current options. Add your option in the switch case and handle it accordingly...
Code: Select all
private void BindSearchResultsPanel()
{
Trace.Write(this.GetType().ToString(), "Begin Bind Search Results");
if (_ContentNodes.Count > 0)
{
//SORT THE CATEGORIES ACCORDINGLY
string sortExpression = SortResults.SelectedValue;
if (!string.IsNullOrEmpty(sortExpression))
{
string[] sortTokens = sortExpression.Split(" ".ToCharArray());
SortDirection dir = (sortTokens[1] == "ASC" ? SortDirection.Ascending : SortDirection.Descending);
switch (sortTokens[0])
{
case "Price":
_ContentNodes.Sort(new PriceComparer(dir));
break;
case "Name":
_ContentNodes.Sort(new NameComparer(dir));
break;
case "Manufacturer":
_ContentNodes.Sort(new ManufacturerComparer(dir));
break;
}
}
//INITIALIZE PAGING VARIABLES
InitializePagingVars(false);
//BIND THE RESULT PANE
BindResultHeader();
//BIND THE PAGING CONTROLS FOOTER
BindPagingControls();
}
else
{
//HIDE THE CONTENTS
phCategoryContents.Visible = false;
phEmptyCategory.Visible = (_Category.CatalogNodes.Count == 0);
}
//UPDATE AJAX PANEL
SearchResultsAjaxPanel.Update();
Trace.Write(this.GetType().ToString(), "End Bind Search Results");
}
Last edited by sohaib on Wed Nov 07, 2007 6:22 pm, edited 1 time in total.
- ryanstowasser
- Lieutenant Commander (LCDR)
- Posts: 90
- Joined: Tue Oct 30, 2007 4:28 pm
- Contact:
the trick is the sorting
The trick is the sorting. Adding items to a dropdown is the easy part. Below I have some code that should help out anyone else trying to sort by a relevent product property.
Thanks to Will for pointing me in the right direction. I stumbled through the objects trying to figure out what I could use to set up properties of a product that could use to sort by. Will pointed me at the Product Template objects.
So here is the additional code from the code behind to be able to sort by an InputField as defined by within a Product Template.
The step that is missing from this post is setting up the InputField in the Product Template through the website administration management.
**** This text was edited after the last time it was complied. It may not be 100% ready, but it should give you a big step in the right direction.
Thanks to Will for pointing me in the right direction. I stumbled through the objects trying to figure out what I could use to set up properties of a product that could use to sort by. Will pointed me at the Product Template objects.
So here is the additional code from the code behind to be able to sort by an InputField as defined by within a Product Template.
The step that is missing from this post is setting up the InputField in the Product Template through the website administration management.
Code: Select all
//Add the Comparer to the switch statement in the code behind
switch (sortTokens[0])
{
case "Price":
_ContentNodes.Sort(new PriceComparer(dir));
break;
case "Name":
_ContentNodes.Sort(new NameComparer(dir));
break;
case "Manufacturer":
_ContentNodes.Sort(new ManufacturerComparer(dir));
break;
case "Color":
_ContentNodes.Sort(new ColorComparer(dir));
break;
}
//for a sample I'm going to sort Colors
private class ColorComparer : IComparer
{
//make sure this matches the name of the Input Field you defined
private String InputFieldName = "Color";
SortDirection _SortDirection;
public ColorComparer(SortDirection sortDirection)
{
_SortDirection = sortDirection;
}
#region IComparer Members
public int Compare(object x, object y)
{
//
//compare two ContentNodes By InputField OrderBy Value
//
CatalogNode catalogNodeX = x as CatalogNode;
CatalogNode catalogNodeY = y as CatalogNode;
//
//Set the Order values to MinValue so that it will be obvious if they change
//Also this will sort Nodes that don't have a matching InputField to the bottom of the list
//
Int16 OrderX = Int16.MinValue;
Int16 OrderY = Int16.MinValue;
if (catalogNodeX.CatalogNodeType == CatalogNodeType.Product && catalogNodeY.CatalogNodeType == CatalogNodeType.Product)
{
ProductTemplateField TemplateFieldX = ((Product)catalogNodeX.ChildObject).TemplateFields.Find(delegate(ProductTemplateField f) { if (f.InputField.Name == InputFieldName) return true; return false; });
ProductTemplateField TemplateFieldY = ((Product)catalogNodeY.ChildObject).TemplateFields.Find(delegate(ProductTemplateField f) { if (f.InputField.Name == InputFieldName) return true; return false; });
//make sure you retrieved valid ProductTemplateFields
//some products might not have the InputField related to it
if (TemplateFieldX != null)
OrderX = TemplateFieldX.InputField.OrderBy;
if (TemplateFieldY != null)
OrderY = TemplateFieldY.InputField.OrderBy;
}
if (_SortDirection == SortDirection.Ascending)
{
//if the Order variables were never set sort that ContentNode to the bottom of the page
if (OrderX == Int16.MinValue)
OrderX = Int16.MaxValue;
if (OrderY == Int16.MinValue)
OrderY = Int16.MaxValue;
return (OrderX.CompareTo(OrderY));
}
return (OrderY.CompareTo(OrderX));
}
#endregion
}
Re: adding to the sort dropdown
I am trying to add an additional sort based on CreatedDate to the CategoryGrid, but need some assistance on how to set up the Comparer.
Any advice or assistance would be greatly appreciated.
Thank you.
Any advice or assistance would be greatly appreciated.
Thank you.
Re: adding to the sort dropdown
Read following thread about comparer samplemartinka wrote:I am trying to add an additional sort based on CreatedDate to the CategoryGrid, but need some assistance on how to set up the Comparer.
Any advice or assistance would be greatly appreciated.
Thank you.
viewtopic.php?f=42&t=12443