Component builder for: List - detail - Udlejning

Vejledende udsalgspris ex moms

Error executing template "Designs/Swift/Paragraph/Swift_ProductAddToCart_Custom.cshtml"
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at CompiledRazorTemplates.Dynamic.RazorEngine_0ae39800b16542ef8b27147fc293bc1c.Execute() in D:\dynamicweb.net\Solutions\Co3\itools.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\Paragraph\Swift_ProductAddToCart_Custom.cshtml:line 59
   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 ProductViewModel product = new ProductViewModel(); 7 8 ProductViewModelSettings productSetting = new ProductViewModelSettings 9 { 10 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID, 11 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code, 12 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2, 13 ShopId = Pageview.Area.EcomShopId 14 }; 15 16 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 17 { 18 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 19 } else if (Pageview.Item["DummyProduct"] != null) { 20 21 string dummyProductId = ""; 22 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page); 23 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel(); 24 if (productList.Products != null) 25 { 26 foreach (var p in productList.Products) { dummyProductId = p.Id; } 27 ProductViewModel dummyProduct = dummyProductId != "" ? ViewModelFactory.CreateView(productSetting, dummyProductId) : new ProductViewModel(); 28 product = dummyProduct; 29 } else { 30 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 31 } 32 } else if (Pageview.Item["DummyProduct"] == null) { 33 product = ViewModelFactory.CreateView(productSetting, Dynamicweb.Ecommerce.Services.Products.GetLastActiveProducts(1, Dynamicweb.Ecommerce.Common.Context.LanguageID, false).FirstOrDefault().Id); 34 } 35 36 string horizontalAlign = Model.Item.GetRawValueString("HorizontalAlignment", ""); 37 horizontalAlign = horizontalAlign == "center" ? "justify-content-center" : horizontalAlign; 38 horizontalAlign = horizontalAlign == "end" ? "justify-content-end" : horizontalAlign; 39 horizontalAlign = horizontalAlign == "full" ? "" : horizontalAlign; 40 41 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", ""); 42 bool anonymousUser = Pageview.User == null; 43 bool isErpConnectionDown = !Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 44 bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHideAddToCart") && isErpConnectionDown; 45 hideAddToCart = Pageview.IsVisualEditorMode ? false : hideAddToCart; 46 bool favoritesSelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowAddToFavorites")) ? Model.Item.GetBoolean("ShowAddToFavorites") : false; 47 bool quantitySelector = !string.IsNullOrEmpty(Model.Item.GetString("ShowQuantitySelector")) ? Model.Item.GetBoolean("ShowQuantitySelector") : false; 48 bool hideInventory = !string.IsNullOrEmpty(Model.Item.GetString("HideInventory")) ? Model.Item.GetBoolean("HideInventory") : false; 49 bool hideStockState = !string.IsNullOrEmpty(Model.Item.GetString("HideStockState")) ? Model.Item.GetBoolean("HideStockState") : false; 50 51 string buttonSize = Model.Item.GetRawValueString("ButtonSize", "regular"); 52 buttonSize = buttonSize == "small" ? " btn-sm" : buttonSize; 53 buttonSize = buttonSize == "regular" ? string.Empty : buttonSize; 54 buttonSize = buttonSize == "large" ? " btn-lg" : buttonSize; 55 56 bool askForPrice = bool.Parse(product.ProductFields["AskForPrice"].ToString()); 57 var askForPriceParagraph = Pageview.Area.Item["AskForPriceParagraph"] != null ? Pageview.Area.Item["AskForPriceParagraph"].ToString() : string.Empty; 58 var askForPriceParagraphSplit = askForPriceParagraph.Split('#'); 59 int askForPriceParagraphId = int.Parse(askForPriceParagraphSplit[1]); 60 } 61 62 63 @if (!hideAddToCart && product.Id != null) { 64 string iconPath = "/Files/icons/"; 65 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService")); 66 if (!url.Contains("LayoutTemplate")) 67 { 68 url += url.Contains("?") ? "&LayoutTemplate=Swift_MiniCart.cshtml" : "?LayoutTemplate=Swift_MiniCart.cshtml"; 69 } 70 71 string disableAddToCart = (product.StockLevel <= 0) ? "disabled" : ""; 72 bool isNeverOutOfStock = product.NeverOutOfstock; 73 disableAddToCart = isNeverOutOfStock ? "" : disableAddToCart; 74 75 string whenVariantsExist = Model.Item.GetRawValueString("WhenVariantsExist", "hide"); 76 77 string flexFill = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "flex-fill" : ""; 78 string fullWidth = Model.Item.GetRawValueString("HorizontalAlignment", "") == "full" ? "w-100" : ""; 79 string addToCartIcon = Model.Item.GetRawValueString("Icon", iconPath + "shopping-cart.svg"); 80 string addToCartLabel = !addToCartIcon.Contains("_none") ? "<span class=\"icon-2 me-2\">" + ReadFile(addToCartIcon) + "</span>" : ""; 81 addToCartLabel += !addToCartIcon.Contains("_none") && !Model.Item.GetBoolean("HideButtonText") ? " " : ""; 82 addToCartLabel += !Model.Item.GetBoolean("HideButtonText") ? Translate("Add to cart") : ""; 83 84 if (product.VariantInfo.VariantInfo == null || whenVariantsExist == "disable") { 85 string minQty = product.PurchaseMinimumQuantity != 1 ? "min=\"" + product.PurchaseMinimumQuantity.ToString() + "\"" : "min=\"1\""; 86 string stepQty = product.PurchaseQuantityStep > 1 ? product.PurchaseQuantityStep.ToString() : "1"; 87 string valueQty = product.PurchaseMinimumQuantity > product.PurchaseQuantityStep ? product.PurchaseMinimumQuantity.ToString() : stepQty; 88 string qtyValidCheck = stepQty != "1" ? "onkeyup=\"swift.Cart.QuantityValidate(event)\"" : ""; 89 disableAddToCart = product.VariantInfo.VariantInfo != null && string.IsNullOrEmpty(product.VariantId) ? "disabled" : disableAddToCart; 90 string dbNumber = Co3.iTools.Services.ProductService.Instance.GetProductFieldValue(product, "ProductTUN") as string; 91 92 93 <div class="d-flex @horizontalAlign @fullWidth item_@Model.Item.SystemName.ToLower()"> 94 <form method="post" action="@url" class="@fullWidth" style="z-index: 1"> 95 <input type="hidden" name="redirect" value="false" /> 96 <input type="hidden" name="ProductId" value="@product.Id" /> 97 <input type="hidden" name="ProductName" value="@product.Name" /> 98 <input type="hidden" name="ProductVariantName" value="@product.VariantName" /> 99 <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code" /> 100 <input type="hidden" name="ProductPrice" value="@product.Price.Price" /> 101 <input type="hidden" name="ProductReferer" value="component_ProductAddToCart" /> 102 <input type="hidden" name="cartcmd" value="add" /> 103 @if (string.IsNullOrEmpty(dbNumber) == false) 104 { 105 <input type="hidden" name="EcomOrderLineFieldInput_DbNumber" value="@dbNumber"/> 106 } 107 108 @if (!string.IsNullOrEmpty(product.VariantId)) { 109 <input type="hidden" name="VariantId" value="@product.VariantId" /> 110 } 111 112 @if (!askForPrice) 113 { 114 if (quantitySelector || (!anonymousUser && favoritesSelector && product.VariantInfo.VariantInfo == null)) 115 { 116 <div class="d-flex flex-row w-100"> 117 @if (!anonymousUser && favoritesSelector && product.VariantInfo.VariantInfo == null) 118 { 119 @RenderPartial("Components/ToggleFavorite.cshtml", product) 120 } 121 122 <div class="input-group input-primary-button-group flex-nowrap"> 123 <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@valueQty" step="@stepQty" @minQty class="form-control" style="min-width: 60px; max-width: 100px; z-index: 1" type="number" onkeydown="swift.Cart.UpdateOnEnterKey(event)"> 124 <button type="button" onclick="swift.Cart.Update(event)" class="d-inline-flex align-items-center justify-content-center gap-2 btn btn-primary @(buttonSize) @flexFill js-add-to-cart-button" style="white-space: nowrap" @disableAddToCart title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID">@addToCartLabel</button> 125 @if (stepQty != "1") 126 { 127 <div class="invalid-feedback d-none"> 128 @Translate("Please select a quantity that is dividable by") @stepQty 129 </div> 130 } 131 </div> 132 </div> 133 } 134 else 135 { 136 <div class="d-flex flex-row w-100" style="z-index: 1;"> 137 @if (!anonymousUser && favoritesSelector && product.VariantInfo.VariantInfo == null) 138 { 139 @RenderPartial("Components/ToggleFavorite.cshtml", product) 140 } 141 <input id="Quantity_@(product.Id)_@product.VariantId" name="Quantity" value="@valueQty" type="hidden"> 142 <button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary@(buttonSize) @flexFill js-add-to-cart-button" @disableAddToCart title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID"> 143 <span class="text-nowrap d-flex align-items-center justify-content-center"> 144 @addToCartLabel 145 </span> 146 </button> 147 </div> 148 } 149 } 150 else 151 { 152 <button type="button" id="askforprice" class="btn btn-primary@(buttonSize) @flexFill" @disableAddToCart data-product-id="@product.Id" title="@Translate("Ask for price")" data-bs-toggle="modal" data-bs-target="#askForPriceModal"> 153 <span class="text-nowrap d-flex align-items-center justify-content-center"> 154 @Translate("Ask for price") 155 </span> 156 </button> 157 } 158 </form> 159 </div> 160 161 <div class="modal fade" id="askForPriceModal" tabindex="-1" role="dialog" aria-labelledby="askForPriceModalLabel" aria-hidden="true" data-bs-backdrop="true" data-productnumber="@product.Number"> 162 <div class="modal-dialog modal-dialog-centered modal-xl"> 163 <div class="modal-content"> 164 <div class="modal-header"> 165 <h5 class="modal-title"></h5> 166 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 167 </div> 168 <div class="modal-body p-2 p-lg-3 h-100"> 169 @RenderParagraphContent(askForPriceParagraphId) 170 </div> 171 </div> 172 </div> 173 </div> 174 175 } else if (whenVariantsExist == "modal") { 176 string buttonText = Translate("Select"); 177 178 string variantSelectorServicePageId = !string.IsNullOrEmpty(Model.Item.GetString("VariantSelectorServicePageId")) ? Model.Item.GetLink("VariantSelectorServicePageId").PageId.ToString() : ""; 179 variantSelectorServicePageId = variantSelectorServicePageId != "" ? variantSelectorServicePageId : GetPageIdByNavigationTag("VariantSelectorService").ToString(); 180 181 <div class="d-flex @horizontalAlign w-100 item_@Model.Item.SystemName.ToLower()"> 182 <form action="/Default.aspx?ID=@variantSelectorServicePageId" data-response-target-element="DynamicModalContent" data-preloader="inline" style="z-index: 1" class="@fullWidth"> 183 <input type="hidden" name="ProductID" value="@product.Id" /> 184 <input type="hidden" name="QuantitySelector" value="@quantitySelector.ToString()" /> 185 <input type="hidden" name="HideInventory" value="@hideInventory.ToString()" /> 186 <input type="hidden" name="HideStockState" value="@hideStockState.ToString()" /> 187 <input type="hidden" name="VariantSelectorServicePage" value="@variantSelectorServicePageId" /> 188 <input type="hidden" name="ViewType" value="ModalContent" /> 189 <button type="button" onclick="swift.PageUpdater.Update(event)" class="btn btn-primary @fullWidth" title="@Translate("Select")" data-bs-toggle="modal" data-bs-target="#DynamicModal" id="OpenVariantSelectorModal@(product.Id)_@Pageview.CurrentParagraph.ID">@buttonText</button> 190 </form> 191 </div> 192 } 193 } else if (Pageview.IsVisualEditorMode) { 194 <div class="alert alert-dark m-0">@Translate("No products available")</div> 195 } 196

Du skal have et login for at bestille online