Making Customer Fields Required for Product Template?
Making Customer Fields Required for Product Template?
Is there a way to make it a requirement for a customer to enter text into a field? For instance you have a product template that has two customer fields where they can enter a personalization like a monogram for example. Is there anyway to require the customer enter something in that field before adding it to the cart?
Thanks in advance!
Thanks in advance!
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Making Customer Fields Required for Product Template?
Literally 5 sec ago I ran into the same issue.
- m_plugables
- Commander (CMDR)
- Posts: 149
- Joined: Tue Mar 11, 2008 12:44 am
- Contact:
Re: Making Customer Fields Required for Product Template?
Edit the App_Code/ProductHelper.cs file and locate the following function
and make it look like
Code: Select all
public static void BuildProductChoices(Product product, PlaceHolder phChoices)
Code: Select all
public static void BuildProductChoices(Product product, PlaceHolder phChoices)
{
// ADD IN THE PRODUCT TEMPLATE CHOICES
ProductTemplate template = product.ProductTemplate;
if (template != null)
{
foreach (InputField input in template.InputFields)
{
if (!input.IsMerchantField)
{
// ADD THE CONTROL TO THE PLACEHOLDER
phChoices.Controls.Add(new LiteralControl("<tr><td colspan=\"2\">"));
phChoices.Controls.Add(new LiteralControl((input.UserPrompt + "<br />")));
WebControl o = input.GetControl();
if (o != null)
{
phChoices.Controls.Add(o);
if (input.InputType == InputType.TextBox)
{
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv" + input.InputFieldId.ToString();
rfv.ControlToValidate = o.ID;
rfv.Text = "*";
rfv.ValidationGroup = "AddToBasket";
phChoices.Controls.Add(rfv);
}
}
phChoices.Controls.Add(new LiteralControl("</td></tr>"));
}
}
}
}
Visit the links below to Download Plugins for your AC7 Store
http://www.plugables.com
http://blog.plugables.com
Re: Making Customer Fields Required for Product Template?
Thank you so much... That worked perfectly!
Re: Making Customer Fields Required for Product Template?
Hi Mazhar,
Have you been making any progress with your Paypal button? I am sure lots of people would like to thank you monetarily for all the great advice that you have been providing the Able users. You're a great asset to community.
-Charles
Have you been making any progress with your Paypal button? I am sure lots of people would like to thank you monetarily for all the great advice that you have been providing the Able users. You're a great asset to community.
-Charles
Able Customer Since 1999 Currently Running on GOLD R12 SR1 and PCI Certified.
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Making Customer Fields Required for Product Template?
Here is his Paypal email address --- change at to @ plugablesatgmail.com.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: Making Customer Fields Required for Product Template?
Thank you for the help with making the information required. I also added a message to left the user know why their item was not submitted to their basket. It is as follows:
public static void BuildProductChoices(Product product, PlaceHolder phChoices)
{
// ADD IN THE PRODUCT TEMPLATE CHOICES
ProductTemplate template = product.ProductTemplate;
if (template != null)
{
foreach (InputField input in template.InputFields)
{
if (!input.IsMerchantField)
{
// ADD THE CONTROL TO THE PLACEHOLDER
phChoices.Controls.Add(new LiteralControl("<tr><td colspan=\"2\">")); phChoices.Controls.Add(new LiteralControl((input.UserPrompt + "<br />")));
WebControl o = input.GetControl();
if (o != null)
{
phChoices.Controls.Add(o);
if (input.InputType == InputType.TextBox)
{
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv" + input.InputFieldId.ToString();
rfv.ControlToValidate = o.ID;
rfv.Text = "*";
rfv.ValidationGroup = "AddToBasket";
rfv.ErrorMessage = "Please enter " + input.Name ;
phChoices.Controls.Add(rfv);
}
}
phChoices.Controls.Add(new LiteralControl("</td></tr>"));
}
}
}
}
I was wondering how hard it would be to modify the code where the Product Templates are set up to indicate if the items is required or not and then have this information passed to this subroutine?
Thanks for any help.
public static void BuildProductChoices(Product product, PlaceHolder phChoices)
{
// ADD IN THE PRODUCT TEMPLATE CHOICES
ProductTemplate template = product.ProductTemplate;
if (template != null)
{
foreach (InputField input in template.InputFields)
{
if (!input.IsMerchantField)
{
// ADD THE CONTROL TO THE PLACEHOLDER
phChoices.Controls.Add(new LiteralControl("<tr><td colspan=\"2\">")); phChoices.Controls.Add(new LiteralControl((input.UserPrompt + "<br />")));
WebControl o = input.GetControl();
if (o != null)
{
phChoices.Controls.Add(o);
if (input.InputType == InputType.TextBox)
{
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv" + input.InputFieldId.ToString();
rfv.ControlToValidate = o.ID;
rfv.Text = "*";
rfv.ValidationGroup = "AddToBasket";
rfv.ErrorMessage = "Please enter " + input.Name ;
phChoices.Controls.Add(rfv);
}
}
phChoices.Controls.Add(new LiteralControl("</td></tr>"));
}
}
}
}
I was wondering how hard it would be to modify the code where the Product Templates are set up to indicate if the items is required or not and then have this information passed to this subroutine?
Thanks for any help.
- voir
- Lieutenant, Jr. Grade (LT JG)
- Posts: 24
- Joined: Mon Jun 09, 2008 4:25 pm
- Location: Belingham, WA US
Re: Making Customer Fields Required for Product Template?
After some trial and error: Create a Merchant field named RequiredFieldsList of type CheckBoxList with the choices being the Product Template Customer field names.dnoell wrote: I was wondering how hard it would be to modify the code where the Product Templates are set up to indicate if the items is required or not and then have this information passed to this subroutine?
Thanks for any help.
Prepend a second loop to get the Required Fields, I use ArrayList so I had to add
Code: Select all
using System.Collections;
Code: Select all
public static void BuildProductChoices(Product product, PlaceHolder phChoices)
{
// ADD IN THE PRODUCT TEMPLATE CHOICES
ProductTemplate template = product.ProductTemplate;
if (template != null)
{
ArrayList requiredFieldsList = new ArrayList();
//To use ArrayList add using System.Collections; in the using area
if (product != null)
{
foreach (ProductTemplateField tf in product.TemplateFields)
{
if (!string.IsNullOrEmpty(tf.InputValue) && tf.InputField.IsMerchantField && tf.InputField.Name == "RequiredFieldsList")
{
foreach (string fn in tf.InputValue.Split(",".ToCharArray()))
{
requiredFieldsList.Add(fn);
}
}
}
}
foreach (InputField input in template.InputFields)
{
if (!input.IsMerchantField)
{
// ADD THE CONTROL TO THE PLACEHOLDER
// I changed these lines to make these input field prompts match the "real" ones
phChoices.Controls.Add(new LiteralControl("<tr><th class=\"rowHeader\" valign=\"top\">"));
phChoices.Controls.Add(new LiteralControl((input.UserPrompt + "</th><td>")));
WebControl o = input.GetControl();
if (o != null)
{
phChoices.Controls.Add(o);
if (requiredFieldsList.Contains(input.Name))
{
//Add Required Control
if (input.InputType == InputType.TextBox)
{
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv" + input.InputFieldId.ToString();
rfv.ControlToValidate = o.ID;
rfv.Text = "*";
rfv.ValidationGroup = "AddToBasket";
rfv.ErrorMessage = "Please enter " + input.Name;
phChoices.Controls.Add(rfv);
}
}
}
phChoices.Controls.Add(new LiteralControl("</td></tr>"));
}
}
}
}
Last edited by voir on Mon Aug 25, 2008 7:06 pm, edited 2 times in total.
- voir
- Lieutenant, Jr. Grade (LT JG)
- Posts: 24
- Joined: Mon Jun 09, 2008 4:25 pm
- Location: Belingham, WA US
Re: Making Customer Fields Required for Product Template?
(example usage:
Create a Product Template name ExReq
in Merchant Fields add
Name=RequiredFieldsList
Type=Check Box List
Next to add choices
Name=BuildNumber
Value="" (blank)
selected=Checked
Name=BuildDate
Value="" (blank)
selected=
In Customer Fields add
Name=BuildNumber
Type=Textbox
Name=BuildDate
Type=Textbox
Add/Edit a product, go to the Template section and select ExReq
Select which fields are required for this product
Create a Product Template name ExReq
in Merchant Fields add
Name=RequiredFieldsList
Type=Check Box List
Next to add choices
Name=BuildNumber
Value="" (blank)
selected=Checked
Name=BuildDate
Value="" (blank)
selected=
In Customer Fields add
Name=BuildNumber
Type=Textbox
Name=BuildDate
Type=Textbox
Add/Edit a product, go to the Template section and select ExReq
Select which fields are required for this product
- voir
- Lieutenant, Jr. Grade (LT JG)
- Posts: 24
- Joined: Mon Jun 09, 2008 4:25 pm
- Location: Belingham, WA US
Re: Making Customer Fields Required for Product Template?
It seems that Merchant Fields show up in the darndest place and perhaps RequiredFieldsList should be eliminated... So in ~/ConLib/Utility/OrderItemDetail.aspx.cs and (for me) in ~/Admin/UserControls/OrderItemDetail.aspx.cs Above
I Added
And Modified the //Show Inputs area
Code: Select all
OrderItem _OrderItem;
Code: Select all
OrderItemInputCollection _oiic = new OrderItemInputCollection();
Code: Select all
//SHOW INPUTS
if (_OrderItem.Inputs.Count > 0)
{
foreach (OrderItemInput oii in _OrderItem.Inputs)
{
if (oii.Name != "RequiredFieldsList")
{
_oiic.Add(oii);
}
}
InputList.DataSource = _oiic;
InputList.DataBind();
}
Re: Making Customer Fields Required for Product Template?
Also note that if you are using merchant fields as part of your custom product templates, you will need to change ProductCustomFieldsDialog if ShowCustomFields is set to "True".
Re: Making Customer Fields Required for Product Template?
I've created a customization to validate customer fields with a regular expression validators. See this post:
viewtopic.php?f=42&t=11004
It also includes a variation on the required fields code above. My variation makes all text fields required by default and lets you easily make all fields optional.
viewtopic.php?f=42&t=11004
It also includes a variation on the required fields code above. My variation makes all text fields required by default and lets you easily make all fields optional.
Re: Making Customer Fields Required for Product Template?
If you're using the vendor notification email template, you'll also probably want to suppress these special fields using something like the following:
I think this would apply to all of these templates:
Code: Select all
#if ($orderItem.Inputs.Count > 0)
#foreach( $input in $orderItem.Inputs )
#if(!$input.Name.StartsWith("Regex") && $input.Name.Replace(" ", "") != "RequiredFieldsList")
<strong>$input.Name</strong><strong>:</strong>
$input.InputValue
#end
#end
#end
- Customer Order Notification
- Vendor Notification
- Gift Certificate Validated
- Order Shipped Partial
- Order Shipped
- ESD file is activated
- License key is fulfilled
Re: Making Customer Fields Required for Product Template?
voir, you may want to look at your wishlists - it will show up there as well.voir wrote:It seems that Merchant Fields show up in the darndest place and perhaps RequiredFieldsList should be eliminated...