adding to the sort dropdown

Store UI, layout, design, look and feel; Discussion on the customer facing pages of your online store. Cascading Style Sheets, Themes, Scriptlets, NVelocity and the components in the ConLib directory.
Post Reply
User avatar
ryanstowasser
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 90
Joined: Tue Oct 30, 2007 4:28 pm
Contact:

adding to the sort dropdown

Post by ryanstowasser » Tue Nov 06, 2007 12:35 pm

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

User avatar
Shopping Cart Admin
AbleCommerce Admin
AbleCommerce Admin
Posts: 3055
Joined: Mon Dec 01, 2003 8:41 pm
Location: Vancouver, WA
Contact:

Post by Shopping Cart Admin » Tue Nov 06, 2007 5:41 pm

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.
Last edited by Shopping Cart Admin on Tue Nov 06, 2007 6:33 pm, edited 1 time in total.
Thanks for your support

Shopping Cart Guru
AbleCommerce.com
Follow us on Facebook

User avatar
ryanstowasser
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 90
Joined: Tue Oct 30, 2007 4:28 pm
Contact:

customization

Post by ryanstowasser » Tue Nov 06, 2007 6:25 pm

I want to customize it myself. How would I go about getting to the code behind in the compiled dlls?

Ryan

User avatar
Shopping Cart Admin
AbleCommerce Admin
AbleCommerce Admin
Posts: 3055
Joined: Mon Dec 01, 2003 8:41 pm
Location: Vancouver, WA
Contact:

Post by Shopping Cart Admin » Tue Nov 06, 2007 6:36 pm

Hello,

Write it outside of our commercebuilder.dll. You don't need the source for this customization. It's a report of current data, I don't see how the source to the commercebuilder.dll would be needed.
Thanks for your support

Shopping Cart Guru
AbleCommerce.com
Follow us on Facebook

Will
Captain (CAPT)
Captain (CAPT)
Posts: 263
Joined: Fri Oct 05, 2007 8:02 am

Post by Will » Tue Nov 06, 2007 6:50 pm

If you look in the code-behind (ascx.cs) files there's examples of how they're sorting the data on the category screens. You might be able to use those as a starting point.

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Post by sohaib » Wed Nov 07, 2007 5:44 pm

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...

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>&nbsp;
                            <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.

User avatar
ryanstowasser
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 90
Joined: Tue Oct 30, 2007 4:28 pm
Contact:

the trick is the sorting

Post by ryanstowasser » Mon Nov 12, 2007 10:58 am

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.

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
    }
**** 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.

martinka
Ensign (ENS)
Ensign (ENS)
Posts: 3
Joined: Fri Sep 18, 2009 2:55 pm

Re: adding to the sort dropdown

Post by martinka » Thu Oct 01, 2009 9:59 am

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.

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

Re: adding to the sort dropdown

Post by mazhar » Fri Oct 02, 2009 4:03 am

martinka 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.
Read following thread about comparer sample
viewtopic.php?f=42&t=12443

Post Reply