Hello, on the page ProductViewer I am trying to hide certain options under certain circumstances. We are using Hotcakes version 1.10.4 Pro. In _ProductDetails.cshtml, I added logic inside the loop [i]foreach (var opt in Model.LocalProduct.Options)[/i]: [code=csharp]foreach (var opt in Model.LocalProduct.Options) { if (HasStudentOptions(opt) && !ShowStudentPricing()) { RemoveStudentOptions(opt); } <div class="dnnFormItem clearfix"> @if (!opt.NameIsHidden) {@opt.Name} <div class="hc-option"> @Html.Raw(opt.RenderWithSelection(Model.Selections.OptionSelectionList)) </div> </div> }[/code] For RemoveStudentOptions, I tried two approaches: Approach #1 was to remove the unwanted OptionItems from the actual Items list of the product's option: [code=csharp]private void RemoveStudentOptions(Hotcakes.Commerce.Catalog.Option opt) { int i = 0; foreach(var optItem in opt.Items) { if (!optItem.Name.EndsWith("Student")) { //opt.Items.Remove(optItem); opt.Items.RemoveAt(i); } i += 1; } }[/code] However this caused the product viewer to not render at all, producing the error: [quote]InnerMessage:Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. InnerStackTrace: at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) at Hotcakes.Commerce.Dnn.Mvc.MvcRenderingEngine.Render(String controllerName, String actionName, String viewName, Object routeValues) at Hotcakes.Modules.ProductViewer.ProductViewerView.RenderView() at Hotcakes.Commerce.Dnn.Web.HotcakesModuleBase.OnLoad(EventArgs e)[/quote] Approach #2 was to clone the Items list of the product's option, and render it rather than the original: [code=csharp]private Hotcakes.Commerce.Catalog.Option RemoveStudentOptions(Hotcakes.Commerce.Catalog.Option opt) { var newOpt = opt.Clone(); newOpt.Items.Clear(); foreach(var optItem in opt.Items) { if (!optItem.Name.EndsWith("Student")) { newOpt.Items.Add(optItem); } } return newOpt; }[/code] This renders the options as desired on the page, however it produces the error "Please make all selections before adding to cart" as shown in the image attached below. Is there a way to achieve the goal of conditionally hiding certain options? Thanks in advance, Adam [img=https://lh3.googleusercontent.com/ryVwfLcI5gzYT_5Q-vgZggIDQVB-XcXQDPt_1Ur1tBLMIxVFQbR27S_mGDXR00Qd5HyAS1E-hO7dEb6VuUKInLb5RTI7IdiTvamMRmjitHdVZMLjwZbh7xb7wxzBMh8F0CyFtabX278rgNaC9g5DZXArrmTnpGuPVU8BhZbdQ8U1HfkrThpG7jyH8OiL7C33ha2kESgZuCnhQ5YrW56yxqjFlhFAyZUyQAI4lqpo5j4ndynN-CE8JVv6TfOJEMaZkIx_wO5pxtCK16lLSRaxzFleHIvpJzD3OO95Tk3Xbu90G9mRe8Drx5IJOKgRmSRfD7pcmkNTHOvxHxChJAo2FJGT8YFZef9m1fcWsbpp4hM4SvK7pvIn7mQ69zXmt_M4H18OmH7jl_07xsUBZOLO6SpEQeIWAxwvwxQ5q7g48CGDJ7Xz2zeGB1SbZ7QUfjFtfvNzT5GOT7Apt_PemEaErypv9s-zWiWH45ynhYE3Zk6zFlGCFuXxe7xjdyriOfg4WRcstWhBduDRyzmRxbrLjIBiWe5KQ2nVaTxPfZN-k2EOnUUpZOEGITSBHdOtlD1Z8kT2zxRI9oSj-QVajyt_GY7rlb9rzumlZN6tru-_ahA=w1022-h761-no]Error message for approach 2[/img]
|