Skip to content

Commit a3e6a21

Browse files
committed
ProductOptionAsRadiobuttons
1 parent 7b088ef commit a3e6a21

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

render/NBrightBuyRazorTokens.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,102 @@ public IEncodedString ProductOptions(ProductData productdata, String attributes
435435
return new RawString(strOut);
436436
}
437437

438+
public IEncodedString ProductOptionAsRadiobuttons(ProductData productdata, int index, String attributes = "", Boolean required = false)
439+
{
440+
var strOut = "";
441+
442+
var objL = productdata.Options;
443+
444+
if (objL.Count > index)
445+
{
446+
var requiredattr = "";
447+
var obj = objL[index];
448+
var optid = obj.GetXmlProperty("genxml/hidden/optionid");
449+
var optvalList = productdata.GetOptionValuesById(optid);
450+
if (obj.GetXmlPropertyBool("genxml/checkbox/optrequired")) required = true;
451+
452+
strOut += "<div class='option option" + (index + 1) + "' " + attributes + ">";
453+
strOut += "<span class='optionname optionname" + (index + 1) + "'>" + obj.GetXmlProperty("genxml/lang/genxml/textbox/txtoptiondesc") + "</span>";
454+
strOut += "<span class='optionvalue optionvalue" + (index + 1) + "'>";
455+
456+
if (optvalList.Count > 1)
457+
{
458+
if (required) requiredattr = " required='' name='optionddl" + (index + 1) + "'"; // name also needs to be added for JQuery Validation to work correctly
459+
460+
var cnt = 0;
461+
462+
foreach (var optval in optvalList)
463+
{
464+
var addcost = optval.GetXmlPropertyDouble("genxml/textbox/txtaddedcost");
465+
var addedcostdisplay = "";
466+
//put a span around it, so at least we can hide with css...
467+
if (addcost > 0)
468+
{
469+
addedcostdisplay = " <span class='addcst addcs" + (index + 1) + "'>(+" + NBrightBuyUtils.FormatToStoreCurrency(addcost) + ")</span>";
470+
}
471+
472+
var selected = "";
473+
if ((cnt == 0) && required)
474+
{
475+
selected = "checked='checked'";
476+
}
477+
cnt += 1;
478+
479+
strOut += "<input type='checkbox' id='optionrb" + (index + 1) + "' name='optionrb" + (index + 1) + "' " + selected + " value='" + optval.GetXmlProperty("genxml/hidden/optionvalueid") + "'>";
480+
strOut += "<label for='optionrb" + (index + 1) + "'>" + optval.GetXmlProperty("genxml/lang/genxml/textbox/txtoptionvaluedesc") + addedcostdisplay + "</label>";
481+
}
482+
483+
}
484+
485+
if (optvalList.Count == 1)
486+
{
487+
//checkbox
488+
foreach (var optval in optvalList)
489+
{
490+
var addcost = optval.GetXmlPropertyDouble("genxml/textbox/txtaddedcost");
491+
var addedcostdisplay = "";
492+
if (addcost > 0)
493+
{
494+
addedcostdisplay = " (+" + NBrightBuyUtils.FormatToStoreCurrency(addcost) + ")";
495+
}
496+
497+
strOut += " <input id='optionchk" + (index + 1) + "' type='checkbox' " + attributes + " update='save' /><label>" + optval.GetXmlProperty("genxml/lang/genxml/textbox/txtoptionvaluedesc") + addedcostdisplay + "</label>";
498+
}
499+
}
500+
501+
if (optvalList.Count == 0)
502+
{
503+
// textbox
504+
if (required) requiredattr = " required='' name='optiontxt" + (index + 1) + "'"; // name also needs to be added for JQuery Validation to work correctly
505+
strOut += "<input id='optiontxt" + (index + 1) + "' " + requiredattr + " update='save' type='text' />";
506+
}
507+
508+
strOut += "<input id='optionid" + (index + 1) + "' update='save' type='hidden' value='" + optid + "' />";
509+
strOut += "</span>";
510+
strOut += "</div>";
511+
512+
}
513+
514+
515+
return new RawString(strOut);
516+
}
517+
518+
public IEncodedString ProductOptionsAsRadiobuttons(ProductData productdata, String attributes = "")
519+
{
520+
var strOut = "";
521+
522+
var objL = productdata.Options;
523+
var c = objL.Count;
524+
for (int i = 0; i < c; i++)
525+
{
526+
strOut += ProductOptionAsRadiobuttons(productdata, i, attributes);
527+
}
528+
529+
return new RawString(strOut);
530+
}
531+
532+
533+
438534
#endregion
439535

440536
#region "categories"

0 commit comments

Comments
 (0)