Remove price from kit drop-down menu
-
- Lieutenant Commander (LCDR)
- Posts: 91
- Joined: Mon Sep 22, 2008 8:37 pm
- Location: Northeast Ohio
- Contact:
Remove price from kit drop-down menu
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!
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
Wave Werks
Re: Remove price from kit drop-down menu
Edit your App_Code/ProductHelper.cs file and locate the following function
and replace its code with following updated one
Here is the screen shot
Code: Select all
public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
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;
}
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Remove price from kit drop-down menu
This should be a option per kit item
Re: Remove price from kit drop-down menu
Sounds reasonable, I just created an enhancement request for this.This should be a option per kit item
-
- 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
I replaced the function with the code you provided and received the following error...mazhar wrote:Edit your App_Code/ProductHelper.cs file and locate the following functionand replace its code with following updated oneCode: Select all
public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
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
- Jeff
Wave Werks
Wave Werks
-
- 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
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
Wave Werks
Re: Remove price from kit drop-down menu
It seems that you didn't replaced the things properly and some brace is missing. Revert your changes and then carefully locateI replaced the function with the code you provided and received the following error...
Code: Select all
public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
{
..................................
..................................
..................................
}
Re: Remove price from kit drop-down menu
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.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?
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;
}
-
- 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
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!!!
Thanks!!!
- Jeff
Wave Werks
Wave Werks
Re: Remove price from kit drop-down menu
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;
}
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Remove price from kit drop-down menu
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?
How can I remove the price only if it is a bulleted list of kit items?