Page 1 of 1

Remove price from kit drop-down menu

Posted: Thu Jan 08, 2009 11:46 am
by wave_werks
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!

Re: Remove price from kit drop-down menu

Posted: Fri Jan 09, 2009 6:09 am
by mazhar
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

Re: Remove price from kit drop-down menu

Posted: Fri Jan 09, 2009 10:50 am
by compunerdy
This should be a option per kit item

Re: Remove price from kit drop-down menu

Posted: Fri Jan 09, 2009 11:34 am
by mazhar
This should be a option per kit item
Sounds reasonable, I just created an enhancement request for this.

Re: Remove price from kit drop-down menu

Posted: Fri Jan 09, 2009 12:45 pm
by wave_werks
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.

Re: Remove price from kit drop-down menu

Posted: Fri Jan 09, 2009 1:00 pm
by wave_werks
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?

Re: Remove price from kit drop-down menu

Posted: Sat Jan 10, 2009 5:07 am
by mazhar
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.

Re: Remove price from kit drop-down menu

Posted: Sat Jan 10, 2009 5:12 am
by mazhar
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;
    }

Re: Remove price from kit drop-down menu

Posted: Sat Jan 10, 2009 9:37 am
by wave_werks
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!!!

Re: Remove price from kit drop-down menu

Posted: Thu Oct 01, 2009 6:58 am
by mazhar
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;
    }

Re: Remove price from kit drop-down menu

Posted: Mon Feb 21, 2011 3:53 pm
by compunerdy
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?