Component builder for: Productlist Card
Error executing template "Designs/Swift/Paragraph/Rental_ProductList_Information.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_4e2735a99b53480a9d751302440fd192.Execute() in D:\wwwroot\rental.skanska.se\Files\Templates\Designs\Swift\Paragraph\Rental_ProductList_Information.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 Softgear.SkanskaMaskin.Data.Business
4
5
6 @{
7 ProductViewModel product = null;
8 var userLoggedIn = Dynamicweb.Security.UserManagement.User.IsFrontendUserLoggedIn();
9 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
10 {
11 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
12 }
13 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode)
14 {
15 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page);
16 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel();
17
18 if (productList?.Products is object)
19 {
20 product = productList.Products[0];
21 }
22 }
23 var modelCode = product.ProductFields["ModelCode"].ToString() != null ? product.ProductFields["ModelCode"].ToString() : "";
24 bool isMobile = Dynamicweb.Frontend.PageView.Current().Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile;
25 var currentUser = Dynamicweb.Security.UserManagement.User.GetCurrentFrontendUser();
26 bool hasPermissionPrice = PermissionManager.HasPermission(PermissionManager.VIEW_PRICES, currentUser);
27
28 }
29
30 @if (product is object)
31 {
32 var isOffert = product.ProductFields["Offertforfragan"].ToString() != "";
33 <div class="@(isMobile ? "row mt-12" : "row mt-21" )">
34 <div class="@( isMobile ? "d-flex flex-column justify-content-between" : "d-flex gap-15 justify-content-between") ">
35 @if (isMobile)
36 {
37 if (userLoggedIn && !isOffert && hasPermissionPrice)
38 {
39 <p class="@(isMobile ? "paragraph-small color-black fs-18 lh-120" : "paragraph-small color-black fs-24 lh-120" ) ">
40 @product.Price.Price.ToString("F2"):-
41 </p>
42 }
43 else if (userLoggedIn && isOffert && hasPermissionPrice)
44 {
45 <p class="@(isMobile ? "paragraph-small color-black fs-18 lh-120" : "paragraph-small color-black fs-24 lh-120" ) ">
46 Offertförfrågan
47 </p>
48 }
49 if (!isMobile)
50 {
51 <h3> @product.Name </h3>
52 }
53 else
54 {
55 <p class="paragraph-regular color-blue">@product.Name</p>
56
57 }
58 }
59 else
60 {
61
62 if (!isMobile)
63 {
64 <h3>@product.Name</h3>
65 }
66 else
67 {
68 <p class="paragraph-regular color-blue">@product.Name</p>
69
70 }
71 if (userLoggedIn && !isOffert && hasPermissionPrice)
72 {
73 <p class="@(isMobile ? "paragraph-small color-black fs-18 lh-120" : "paragraph-small color-black fs-24 lh-120" ) ">
74 @product.Price.Price.ToString("F2"):-
75 </p>
76 }
77 else if (userLoggedIn && isOffert && hasPermissionPrice)
78 {
79 <p class="@(isMobile ? "paragraph-small color-black fs-18 lh-120" : "paragraph-small color-black fs-24 lh-120" ) ">
80 Offertförfrågan
81 </p>
82 }
83 }
84 </div>
85 </div>
86 <div class="@(isMobile ? "row mb-12" : "row mb-21 mt-21" )">
87 <p class="paragraph-regular">
88 @product.Manufacturer.Name
89 </p>
90 <p class="paragraph-small">
91 @modelCode
92 </p>
93 </div>
94 }
95 else if (Pageview.IsVisualEditorMode)
96 {
97 <div class="alert alert-dark m-0">@Translate("No products available")</div>
98 }
99
Error executing template "Designs/Swift/Paragraph/Rental_ProductList_Buttons.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_88b86854534348238900b1c30a082e79.Execute() in D:\wwwroot\rental.skanska.se\Files\Templates\Designs\Swift\Paragraph\Rental_ProductList_Buttons.cshtml:line 31
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.Core.Encoders
4 @using Dynamicweb.Ecommerce.CustomerExperienceCenter.Favorites
5 @using Softgear.SkanskaMaskin.Data.Business
6 @using Dynamicweb.Frontend.Devices
7
8 @{
9 ProductViewModel product = null;
10 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
11 {
12 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
13 }
14 else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode)
15 {
16 var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page);
17 ProductListViewModel productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel();
18
19 if (productList?.Products is object)
20 {
21 product = productList.Products[0];
22 }
23 }
24
25 string anonymousUsersLimitations = Pageview.AreaSettings.GetRawValueString("AnonymousUsers", "");
26 bool anonymousUser = Pageview.User == null;
27 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Items["IsWebServiceConnectionAvailable"]);
28 bool hideAddToCart = anonymousUsersLimitations.Contains("cart") && anonymousUser || Pageview.AreaSettings.GetBoolean("ErpDownHideAddToCart") && isErpConnectionDown;
29 hideAddToCart = Pageview.IsVisualEditorMode ? false : hideAddToCart;
30
31 var inFavoriteList = WebHelper.IsProductInFavouriteList(product.Id);
32 var currentUser = Dynamicweb.Security.UserManagement.User.GetCurrentFrontendUser();
33 var userIsLoggedIn = Dynamicweb.Security.UserManagement.User.IsFrontendUserLoggedIn();
34 string url = "/Default.aspx?ID=" + (GetPageIdByNavigationTag("CartService"));
35
36 bool isMobile = Dynamicweb.Frontend.PageView.Current().Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile;
37 bool hasPermissionPrice = PermissionManager.HasPermission(PermissionManager.VIEW_PRICES, currentUser);
38 bool hasPermissionToOrder = PermissionManager.HasPermission(PermissionManager.MAKE_PURCHASE, currentUser);
39 }
40
41
42 @if (product is object && !hideAddToCart)
43 {
44 var isOnRent = product.ProductFields["ProductSaleType"].ToString() == "Hyra";
45 var isOffert = product.ProductFields["Offertforfragan"].ToString() != "";
46
47 if (userIsLoggedIn && product.Price.Price != 0)
48 {
49 <div class="@(isMobile ? "d-flex gap-17" :"d-flex")">
50 <div >
51 <form method="post" action="/Default.aspx?ID=7697" style="z-index: 100; position: relative">
52 <input type="hidden" name="redirect" value="false">
53 <input type="hidden" name="ProductId" value="@product.Id">
54 <input type="hidden" name="ProductName" value="@HtmlEncoder.HtmlEncode(product.Name)">
55 <input type="hidden" name="ProductVariantName" value="@product.VariantName">
56 <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code">
57 <input type="hidden" name="ProductPrice" value="@PriceViewModelExtensions.ToStringInvariant(product.Price)">
58 <input type="hidden" name="ProductReferer" value="component_ProductAddToCart">
59 <input type="hidden" name="cartcmd" value="add">
60 <input type="hidden" name="Quantity" value="1" />
61 <input type="hidden" name="rentalperiod" value="@DateTime.Now.ToShortDateString() - @DateTime.Now.ToShortDateString()" />
62 <input type="hidden" name="productlist" value="true">
63 @if (product.Price.Price != 0 && !isOffert && hasPermissionPrice && hasPermissionToOrder)
64 {
65 <button type="button" onclick="swift.Cart.Update(event)" class="btn js-add-to-cart-button addToCartBtn" style="white-space: nowrap" title="@Translate("Add to cart")" id="AddToCartButton@(product.Id)_@Pageview.CurrentParagraph.ID">
66 <span class="icon icon-cart"></span>
67 </button>
68 }
69
70 </form>
71 </div>
72 <button onclick="addProductToFavoriteList('@product.Id', @(inFavoriteList.ToString().ToLower()))" class="bg-transparent" style="z-index:100;">
73 <div class="d-flex">
74 @if (inFavoriteList)
75 {
76 <span class="icon icon-heart-blue-filled ml-7 align-self-center" style="width:20px;height:16px;"></span>
77 }
78 else
79 {
80 <span class="icon icon-heart-shallow ml-7 align-self-center" style="width:20px;height:16px;"></span>
81 }
82 </div>
83 </button>
84 </div>
85 }
86 else
87 {
88 <div class="row">
89 <div class="col-1">
90 <form method="post" action="@url" style="z-index: 100; position: relative">
91 <input type="hidden" name="redirect" value="false">
92 <input type="hidden" name="ProductId" value="@product.Id">
93 <input type="hidden" name="ProductName" value="@HtmlEncoder.HtmlEncode(product.Name)">
94 <input type="hidden" name="ProductVariantName" value="@product.VariantName">
95 <input type="hidden" name="ProductCurrency" value="@Dynamicweb.Ecommerce.Common.Context.Currency.Code">
96 <input type="hidden" name="ProductPrice" value="@PriceViewModelExtensions.ToStringInvariant(product.Price)">
97 <input type="hidden" name="ProductReferer" value="component_ProductAddToCart">
98 <input type="hidden" name="cartcmd" value="add">
99 </form>
100 </div>
101 @if (userIsLoggedIn)
102 {
103 <button onclick="addProductToFavoriteList('@product.Id', @(inFavoriteList.ToString().ToLower()))" class="bg-transparent" style="z-index:100;">
104 <div class="d-flex">
105 @if (inFavoriteList)
106 {
107 <span class="icon icon-heart-blue-filled ml-7 align-self-center" style="width:20px;height:16px;"></span>
108 }
109 else
110 {
111 <span class="icon icon-heart-shallow ml-7 align-self-center" style="width:20px;height:16px;"></span>
112 }
113 </div>
114 </button>
115 }
116 </div>
117 }
118 }
119 else if (Pageview.IsVisualEditorMode)
120 {
121 <div class="alert alert-dark m-0">@Translate("No products available")</div>
122 }
123