Component builder for: Publication

Error executing template "Designs/Swift/Paragraph/Swift_ProductDownloadPublication.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_404f9a455a0e460385e01809928b2125.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\T3L.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Paragraph\Swift_ProductDownloadPublication.cshtml:line 23
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using Dynamicweb.Ecommerce.ProductCatalog 3 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites 4 5 6 @{ 7 ProductViewModel product = null; 8 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 9 { 10 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 11 } 12 else if (Pageview.Page.Item["DummyProduct"] != null) 13 { 14 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 15 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 16 17 if (productList?.Products is object) 18 { 19 product = productList.Products[0]; 20 } 21 } 22 23 string uniqueId = $"{product.Id}_{product.VariantId.Replace(".", "_")}_{Pageview.CurrentParagraph.ID}"; 24 25 var selectedCatalogs = Model.Item.GetList("SelectedCatalogs")?.GetRawValue()?.OfType<string>(); 26 int catalogCount = 0; 27 28 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", string.Empty); 29 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 30 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 31 horizontalAlign = horizontalAlign == "full" ? string.Empty : horizontalAlign; 32 33 string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); 34 35 switch (buttonSize) 36 { 37 case "small": 38 buttonSize = " btn-sm"; 39 break; 40 case "regular": 41 buttonSize = string.Empty; 42 break; 43 case "large": 44 buttonSize = " btn-lg"; 45 break; 46 } 47 48 string iconPath = "/Files/icons/"; 49 50 string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : string.Empty; 51 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : string.Empty; 52 string icon = Model.Item.GetRawValueString("Icon", iconPath + "printer.svg"); 53 string label = !icon.Contains("_none") ? $"<span class=\"icon-2\">{ReadFile(icon)}</span>" : string.Empty; 54 label += !icon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : string.Empty; 55 label += !Model.Item.GetBoolean("HideButtonText") && !string.IsNullOrEmpty(Model.Item.GetString("Title")) ? Model.Item.GetString("Title") : string.Empty; 56 } 57 58 @if (product is object && selectedCatalogs != null && selectedCatalogs.Any()) 59 { 60 var ecomLanguages = Dynamicweb.Ecommerce.Services.Languages.GetLanguages(); 61 var currencies = Dynamicweb.Ecommerce.Services.Currencies.GetAllCurrencies(); 62 var languageId = Dynamicweb.Ecommerce.Common.Context.LanguageID; 63 var areaEcomLanguageId = Pageview.Area.EcomLanguageId; 64 var areaEcomCurrencyId = Pageview.Area.EcomCurrencyId; 65 66 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 67 <button type="button" class="btn btn-primary @(buttonSize) @flexFill" data-bs-toggle="modal" data-bs-target="#DownloadPublicationModal@(uniqueId)" style="white-space: nowrap" title="@Model.Item.GetString("Title")" id="DownloadPublication@(uniqueId)"> 68 @if (!Model.Item.GetBoolean("HideButtonText")) 69 { 70 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 71 @label 72 </span> 73 } 74 else 75 { 76 @label 77 } 78 </button> 79 </div> 80 81 <div class="modal fade" id="DownloadPublicationModal@(uniqueId)" tabindex="-1" aria-labelledby="#DownloadPublicationModalLabel@(uniqueId)" aria-hidden="true"> 82 <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable"> 83 <form target="_blank" action="/Default.aspx?ID=@selectedCatalogs.FirstOrDefault()" method="post" class="modal-content" id="DownloadPublicationModalForm@(uniqueId)"> 84 <input type="hidden" name="mainproductid" value="@(product.Id)@(product.VariantId)"> 85 <input type="hidden" name="print" value="true"> 86 87 @if (!string.IsNullOrEmpty(product.VariantId)) 88 { 89 <input type="hidden" name="VariantId" value="@product.VariantId"> 90 } 91 92 <div class="modal-header"> 93 <h1 class="modal-title fs-5" id="DownloadPublicationModalLabel@(uniqueId)">@Translate("Publication for print")</h1> 94 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 95 </div> 96 <div class="modal-body p-0"> 97 <div class="grid gap-0"> 98 <div class="g-col-12 g-col-lg-4 border-end p-3 p-lg-4"> 99 100 @if (Model.Item.GetBoolean("ShowLanguageSelector") && ecomLanguages.Count() > 1) 101 { 102 <div class="mb-4"> 103 <label class="form-label">@Translate("Language")</label> 104 <select name="RequestLanguageID" class="form-select" aria-label="@Translate("Language")"> 105 @foreach (var language in ecomLanguages) 106 { 107 var selected = string.Empty; 108 if (language.LanguageId.Equals(areaEcomLanguageId, StringComparison.OrdinalIgnoreCase)) 109 { 110 selected = "selected"; 111 } 112 <option @selected value="@language.LanguageId">@language.GetDisplayName()</option> 113 } 114 </select> 115 </div> 116 } 117 118 119 @if (Model.Item.GetBoolean("ShowCurrencySelector")) 120 { 121 <div class="mb-4" id="CurrencySelector@(uniqueId)"> 122 <label class="form-label">@Translate("Currency")</label> 123 <select name="RequestCurrencyCode" class="form-select" aria-label="@Translate("Currency")"> 124 @foreach (var currency in currencies) 125 { 126 var selected = string.Empty; 127 if (currency.Code.Equals(areaEcomCurrencyId, StringComparison.OrdinalIgnoreCase)) 128 { 129 selected = "selected"; 130 } 131 <option @selected value="@currency.Code">@currency.GetName(languageId)</option> 132 } 133 </select> 134 </div> 135 } 136 137 @if (Model.Item.GetBoolean("ShowPriceSelector")) 138 { 139 <div class="mb-4"> 140 <label class="form-label">@Translate("Show price")</label> 141 <div class="form-check"> 142 <input class="form-check-input" type="radio" name="hideprice" value="false" id="HidePriceFalse@(uniqueId)" checked onchange="document.querySelector('#CurrencySelector@(uniqueId)').classList.remove('d-none')"> 143 <label class="form-check-label" for="HidePriceFalse@(uniqueId)"> 144 @Translate("Yes") 145 </label> 146 </div> 147 <div class="form-check"> 148 <input class="form-check-input" type="radio" name="hideprice" value="true" id="HidePriceTrue@(uniqueId)" onchange="document.querySelector('#CurrencySelector@(uniqueId)').classList.add('d-none')"> 149 <label class="form-check-label" for="HidePriceTrue@(uniqueId)"> 150 @Translate("No") 151 </label> 152 </div> 153 </div> 154 } 155 156 @if (Model.Item.GetBoolean("ShowCommentField")) 157 { 158 <div class="mb-4"> 159 <label for="DealerComment@(uniqueId)">@Translate("Comment")</label> 160 <textarea name="DealerComment" class="form-control" rows="6" placeholder="@Translate("Leave a comment here")" id="DealerComment@(uniqueId)"></textarea> 161 </div> 162 } 163 </div> 164 <div class="g-col-12 g-col-lg-8 p-3 p-lg-4"> 165 <div class="grid grid-2 grid-lg-3 gap-lg-4"> 166 @foreach (var catalog in selectedCatalogs) 167 { 168 var pageObj = Dynamicweb.Content.Services.Pages.GetPage(Convert.ToInt32(catalog)); 169 170 var selected = catalogCount == 0 ? "checked" : string.Empty; 171 var radioId = $"CatalogCheck_{Model.ID}_{pageObj.ID}"; 172 string imagePath = pageObj.Item["Thumbnail"] != null ? $"/Admin/Public/GetImage.ashx?image={pageObj.Item["Thumbnail"].ToString()}&width=200&format=webp" : $"https://placehold.co/235x300?text={@Translate("Catalog+Image")}"; 173 174 <div class="form-thumb"> 175 <input class="form-thumb-input visually-hidden" type="radio" name="ID" value="@pageObj.ID" id="@radioId" onclick="document.querySelector('#DownloadPublicationModalForm@(uniqueId)').action='/Default.aspx?ID=@(pageObj.ID)'" @selected> 176 <label class="form-thumb-label d-flex flex-column" for="@radioId" role="button"> 177 <span class="d-block p-1"> 178 <img class="rounded-2 w-100" style="object-fit:cover" src="@imagePath" /> 179 </span> 180 <span class="d-grid p-3"> 181 <span class="d-block fw-bold">@pageObj.GetDisplayName()</span> 182 @*<span class="d-block opacity-75 fs-7 lh-sm">@catalog.Name</span> // Descriptive text goes here //*@ 183 </span> 184 </label> 185 </div> 186 187 catalogCount++; 188 } 189 </div> 190 </div> 191 </div> 192 </div> 193 <div class="modal-footer"> 194 <button type="button" onclick="GetPublication(event)" data-bs-dismiss="modal" class="btn btn-primary">@Translate("Print")</button> 195 </div> 196 </form> 197 </div> 198 </div> 199 200 <script> 201 const GetPublication = (e) => { 202 const clickedButton = e.currentTarget; 203 const form = clickedButton.closest('form'); 204 205 form.closest('form').submit(); 206 207 commentField = form.querySelector('textarea[name="DealerComment"]'); 208 commentField.value = ""; 209 }; 210 </script> 211 } 212 else if (Pageview.IsVisualEditorMode) 213 { 214 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 215 <button type="button" class="btn btn-primary @(buttonSize) @flexFill" data-bs-toggle="modal" data-bs-target="#DownloadPublicationModal@(uniqueId)" style="white-space: nowrap" title="@Model.Item.GetString("Title")" id="DownloadPublication@(uniqueId)"> 216 @if (!Model.Item.GetBoolean("HideButtonText")) 217 { 218 <span class="text-nowrap d-flex align-items-center justify-content-center gap-2"> 219 @label 220 </span> 221 } 222 else 223 { 224 @label 225 } 226 </button> 227 </div> 228 } 229
By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing