Remove price from kit drop-down menu

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
wave_werks
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 91
Joined: Mon Sep 22, 2008 8:37 pm
Location: Northeast Ohio
Contact:

Remove price from kit drop-down menu

Post by wave_werks » Thu Jan 08, 2009 11:46 am

Howdy folks!

I'm trying to figure out how to prevent the price " - ($0.00)" or " - ($25.00)" from being displayed on the drop-down menus for kitted products. I have used both the options/variants and kits/bundles with many products. All of the options/variants menus are displayed without a price while all of the kit/bundle menus display " - ($x.xx)".

If this cannot be achieved is it then possible to replace the " - " with " + " so that the menu shows that a price is being added rather than appearing to subtract the price?

Thanks, as always, for any help you may provide!
- Jeff
Wave Werks

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

Re: Remove price from kit drop-down menu

Post by mazhar » Fri Jan 09, 2009 6:09 am

Edit your App_Code/ProductHelper.cs file and locate the following function

Code: Select all

public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
and replace its code with following updated one

Code: Select all

public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
    {
        List<int> selectedChoices = new List<int>();
        foreach (ProductKitComponent pkc in product.ProductKitComponents)
        {
            KitComponent component = pkc.KitComponent;
            if (component.InputType != KitInputType.IncludedHidden && component.KitProducts.Count > 0)
            {
                // CREATE A LABEL FOR THE ATTRIBUTE
                phOptions.Controls.Add(new LiteralControl("<tr><th class=\"rowHeader\">" + component.Name + ":</th>"));
                // ADD THE CONTROL TO THE PLACEHOLDER
                phOptions.Controls.Add(new LiteralControl("<td align=\"left\">"));
                WebControl o = component.GetControl();
                
                string tempStr = string.Empty;
                int index = 0;
                if (o != null)
                {
                    Type oType = o.GetType();
                    if (oType.Equals(typeof(RadioButtonList)))
                    {
                        ((RadioButtonList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((RadioButtonList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                            {
                                index = listItem.Text.IndexOf("- ($");
                                tempStr = listItem.Text.Substring(0, index - 1);
                                listItem.Text = tempStr.Trim();
                            }
                        }
                    }
                    else if (oType.Equals(typeof(DropDownList)))
                    {
                        ((DropDownList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((DropDownList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                            {
                                index = listItem.Text.IndexOf("- ($");
                                tempStr = listItem.Text.Substring(0, index - 1);
                                listItem.Text = tempStr.Trim();
                            }
                        }
                    }
                    else if (oType.Equals(typeof(CheckBoxList)))
                    {
                        ((CheckBoxList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((CheckBoxList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                            {
                                index = listItem.Text.IndexOf("- ($");
                                tempStr = listItem.Text.Substring(0, index - 1);
                                listItem.Text = tempStr.Trim();
                            }
                        }
                    }
                    else if (oType.Equals(typeof(BulletedList)))
                    {
                        foreach (ListItem listItem in ((BulletedList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                            {
                                index = listItem.Text.IndexOf("- ($");
                                tempStr = listItem.Text.Substring(0, index - 1);
                                listItem.Text = tempStr.Trim();
                            }
                        }
                    }
                    
                    phOptions.Controls.Add(o);
                    // SEE WHETHER A VALID VALUE FOR THIS FIELD IS PRESENT IN FORM POST
                    List<int> theseOptions = component.GetControlValue(o);
                    selectedChoices.AddRange(theseOptions);
                }
                phOptions.Controls.Add(new LiteralControl("</td></tr>"));
            }
        }
        return selectedChoices;
    }
Here is the screen shot

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Remove price from kit drop-down menu

Post by compunerdy » Fri Jan 09, 2009 10:50 am

This should be a option per kit item

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

Re: Remove price from kit drop-down menu

Post by mazhar » Fri Jan 09, 2009 11:34 am

This should be a option per kit item
Sounds reasonable, I just created an enhancement request for this.

wave_werks
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 91
Joined: Mon Sep 22, 2008 8:37 pm
Location: Northeast Ohio
Contact:

Re: Remove price from kit drop-down menu

Post by wave_werks » Fri Jan 09, 2009 12:45 pm

mazhar wrote:Edit your App_Code/ProductHelper.cs file and locate the following function

Code: Select all

public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
and replace its code with following updated one
I replaced the function with the code you provided and received the following error...

Code: Select all

Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1519: Invalid token '{' in class, struct, or interface member declaration

Source Error:

Line 350:        return selectedChoices;
Line 351:    }
Line 352:    {
Line 353:        List<int> selectedChoices = new List<int>();
Line 354:        foreach (ProductKitComponent pkc in product.ProductKitComponents)

Source File: c:\inetpub\wwwroot\wavewerks\App_Code\ProductHelper.cs    Line: 352 
I am a complete novice with this stuff so I have no idea what to do to resolve the error.
- Jeff
Wave Werks

wave_werks
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 91
Joined: Mon Sep 22, 2008 8:37 pm
Location: Northeast Ohio
Contact:

Re: Remove price from kit drop-down menu

Post by wave_werks » Fri Jan 09, 2009 1:00 pm

For a completely different website is it possible to replace the " - " with " + " so that the menu shows that a price is being added rather than appearing to subtract the price?
- Jeff
Wave Werks

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

Re: Remove price from kit drop-down menu

Post by mazhar » Sat Jan 10, 2009 5:07 am

I replaced the function with the code you provided and received the following error...
It seems that you didn't replaced the things properly and some brace is missing. Revert your changes and then carefully locate

Code: Select all

public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
{
..................................
..................................
..................................
}
and replace it with the above code so that starting function brace must have the ending brace at end.

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

Re: Remove price from kit drop-down menu

Post by mazhar » Sat Jan 10, 2009 5:12 am

For a completely different website is it possible to replace the " - " with " + " so that the menu shows that a price is being added rather than appearing to subtract the price?
Yes it will be very easy. All you need is to replace the desired string instead of removing it. Here is updated code for this change.

Code: Select all

public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
    {
        List<int> selectedChoices = new List<int>();
        foreach (ProductKitComponent pkc in product.ProductKitComponents)
        {
            KitComponent component = pkc.KitComponent;
            if (component.InputType != KitInputType.IncludedHidden && component.KitProducts.Count > 0)
            {
                // CREATE A LABEL FOR THE ATTRIBUTE
                phOptions.Controls.Add(new LiteralControl("<tr><th class=\"rowHeader\">" + component.Name + ":</th>"));
                // ADD THE CONTROL TO THE PLACEHOLDER
                phOptions.Controls.Add(new LiteralControl("<td align=\"left\">"));
                WebControl o = component.GetControl();

                
                int index = 0;
                if (o != null)
                {
                    Type oType = o.GetType();
                    if (oType.Equals(typeof(RadioButtonList)))
                    {
                        ((RadioButtonList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((RadioButtonList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                                listItem.Text = listItem.Text.Replace("- ($", "+ ($");
                        }
                    }
                    else if (oType.Equals(typeof(DropDownList)))
                    {
                        ((DropDownList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((DropDownList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                                listItem.Text = listItem.Text.Replace("- ($", "+ ($");
                        }
                    }
                    else if (oType.Equals(typeof(CheckBoxList)))
                    {
                        ((CheckBoxList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((CheckBoxList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                                listItem.Text = listItem.Text.Replace("- ($", "+ ($");
                        }
                    }
                    else if (oType.Equals(typeof(BulletedList)))
                    {
                        foreach (ListItem listItem in ((BulletedList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                                listItem.Text = listItem.Text.Replace("- ($", "+ ($");
                        }
                    }

                    phOptions.Controls.Add(o);
                    // SEE WHETHER A VALID VALUE FOR THIS FIELD IS PRESENT IN FORM POST
                    List<int> theseOptions = component.GetControlValue(o);
                    selectedChoices.AddRange(theseOptions);
                }
                phOptions.Controls.Add(new LiteralControl("</td></tr>"));
            }
        }
        return selectedChoices;
    }

wave_werks
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 91
Joined: Mon Sep 22, 2008 8:37 pm
Location: Northeast Ohio
Contact:

Re: Remove price from kit drop-down menu

Post by wave_werks » Sat Jan 10, 2009 9:37 am

Rookie mistake. I replaced only the one line you mentioned with all of the code. For some reason I didn't thing to replace the whole "function" as you stated in your instructions. Works perfectly now.

Thanks!!!
- Jeff
Wave Werks

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

Re: Remove price from kit drop-down menu

Post by mazhar » Thu Oct 01, 2009 6:58 am

Here is the code to trim price off items in a component marked as included shown

Code: Select all

public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
    {
        List<int> selectedChoices = new List<int>();
        foreach (ProductKitComponent pkc in product.ProductKitComponents)
        {
            KitComponent component = pkc.KitComponent;
            if (component.InputType != KitInputType.IncludedHidden && component.KitProducts.Count > 0)
            {
                // CREATE A LABEL FOR THE ATTRIBUTE
                phOptions.Controls.Add(new LiteralControl("<tr><th class=\"rowHeader\">" + component.Name + ":</th>"));
                // ADD THE CONTROL TO THE PLACEHOLDER
                phOptions.Controls.Add(new LiteralControl("<td align=\"left\">"));
                WebControl o = component.GetControl();

               
                int index = 0;
                if (o != null)
                {
                    Type oType = o.GetType();
                    if (oType.Equals(typeof(RadioButtonList)))
                    {
                        ((RadioButtonList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((RadioButtonList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                                listItem.Text = listItem.Text.Replace("- ($", "+ ($");
                        }
                    }
                    else if (oType.Equals(typeof(DropDownList)))
                    {
                        ((DropDownList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((DropDownList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                                listItem.Text = listItem.Text.Replace("- ($", "+ ($");
                        }
                    }
                    else if (oType.Equals(typeof(CheckBoxList)))
                    {
                        ((CheckBoxList)o).AutoPostBack = true;
                        foreach (ListItem listItem in ((CheckBoxList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                                listItem.Text = listItem.Text.Replace("- ($", "+ ($");
                        }
                    }
                    else if (oType.Equals(typeof(BulletedList)))
                    {
                        foreach (ListItem listItem in ((BulletedList)o).Items)
                        {
                            if (listItem.Text.Contains("- ($"))
                                listItem.Text = listItem.Text.Replace("- ($", "+ ($");
                        }
                    }
		    else if (oType.Equals(typeof(Label)))
                    {
                        Label label = (Label)o;
                        label.Text = System.Text.RegularExpressions.Regex.Replace(label.Text, @"- \(.*\)", string.Empty);
                    }

                    phOptions.Controls.Add(o);
                    // SEE WHETHER A VALID VALUE FOR THIS FIELD IS PRESENT IN FORM POST
                    List<int> theseOptions = component.GetControlValue(o);
                    selectedChoices.AddRange(theseOptions);
                }
                phOptions.Controls.Add(new LiteralControl("</td></tr>"));
            }
        }
        return selectedChoices;
    }

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Remove price from kit drop-down menu

Post by compunerdy » Mon Feb 21, 2011 3:53 pm

I see this was never added as a option per kit item.

How can I remove the price only if it is a bulleted list of kit items?

Post Reply