Error compiling template "Designs/Swift/Swift_Email/Paragraph/Copy of Swift_EmailProductCatalog.cshtml"
Line 102: The name 'RenderProduct' does not exist in the current context
Line 159: The name 'helper' does not exist in the current context
Line 177: The name 'product' does not exist in the current context
Line 177: The name 'product' does not exist in the current context
Line 177: The name 'parms' does not exist in the current context
Line 179: The name 'helper' does not exist in the current context
Line 209: The name 'link' does not exist in the current context
Line 212: The name 'RenderImage' does not exist in the current context
Line 212: The name 'product' does not exist in the current context
Line 212: The name 'theme' does not exist in the current context
Line 240: The name 'link' does not exist in the current context
Line 243: The name 'product' does not exist in the current context
Line 245: The name 'hideProductNumber' does not exist in the current context
Line 252: 'string' does not contain a definition for 'Hex' and no accessible extension method 'Hex' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Line 256: The name 'product' does not exist in the current context
Line 260: The name 'hideProductPrice' does not exist in the current context
Line 271: The name 'product' does not exist in the current context
Line 273: The name 'product' does not exist in the current context
Line 278: 'string' does not contain a definition for 'Hex' and no accessible extension method 'Hex' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Line 282: The name 'product' does not exist in the current context
1 // <auto-generated/>
2 #pragma warning disable 1591
3 namespace CompiledRazorTemplates.Dynamic
4 {
5 #line hidden
6 using System.Threading.Tasks;
7 using System;
8 using System.Collections.Generic;
9 using System.Linq;
10 using Dynamicweb.Ecommerce.ProductCatalog;
11 internal class RazorEngine_b94f95846b3d4f6191b7312ea8bee40f : Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
12 {
13 #pragma warning disable 1998
14 public async override global::System.Threading.Tasks.Task ExecuteAsync()
15 {
16 WriteLiteral("\r\n");
17 WriteLiteral("\r\n");
18
19 string blockType = "productcatalog_block";
20
21 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageID);
22 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
23 var blockId = Model.ID;
24 var block = Model.Item;
25
26 var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
27 var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
28 var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
29
30 var rowId = Pageview.CurrentParagraph.GridRowId;
31 var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
32 var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
33 var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
34 var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
35 var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
36
37 var blockThemeId = block.GetRawValueString("Theme");
38 var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
39 var blockTheme = blockThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph)?.Item : rowTheme is object ? rowTheme : emailContentTheme;
40
41 string backgroundColor = blockTheme != null ? "background-color: " + blockTheme.GetString("BackgroundColor") + ";" : string.Empty;
42 string foregroundColor = blockTheme != null ? "color:" + blockTheme.GetString("ForegroundColor", "inherit") + ";" : string.Empty;
43
44 string title = block.GetString("Title", string.Empty);
45 int padding = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Padding", "0"));
46 int cellSpacing = 8;
47 string align = block.GetRawValueString("Align", "left");
48 string text = block.GetString("Text", string.Empty);
49 var layoutColumns = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Layout", "2"));
50
51 ProductListViewModel selectedProducts = block?.GetValue("Products") as ProductListViewModel;
52 IList<ProductViewModel> products = selectedProducts?.Products;
53 WriteLiteral("\r\n<table");
54 BeginWriteAttribute("id", " id=\"", 4825, "\"", 4838, 1);
55 WriteAttributeValue("", 4830, blockId, 4830, 8, false);
56 EndWriteAttribute();
57 BeginWriteAttribute("class", " class=\"", 4839, "\"", 4857, 1);
58 WriteAttributeValue("", 4847, blockType, 4847, 10, false);
59 EndWriteAttribute();
60 WriteLiteral(" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"");
61 BeginWriteAttribute("style", " style=\"", 4936, "\"", 5045, 4);
62 WriteAttributeValue("", 4944, "mso-table-lspace:0pt;mso-table-rspace:0pt;", 4944, 42, true);
63 WriteAttributeValue("", 4986, GetTableReset(), 4986, 16, false);
64 WriteAttributeValue("", 5002, "color:inherit;width:100%;", 5002, 25, true);
65 WriteAttributeValue("", 5027, backgroundColor, 5027, 18, false);
66 EndWriteAttribute();
67 WriteLiteral(">\r\n\t<tbody>\r\n\t\t<tr");
68 BeginWriteAttribute("style", " style=\"", 5064, "\"", 5088, 1);
69 WriteAttributeValue("", 5072, GetTableReset(), 5072, 16, false);
70 EndWriteAttribute();
71 WriteLiteral(">\r\n\t\t\t<td");
72 BeginWriteAttribute("style", " style=\"", 5098, "\"", 5142, 4);
73 WriteAttributeValue("", 5106, GetTableReset(), 5106, 16, false);
74 WriteAttributeValue("", 5122, "padding:", 5122, 8, true);
75 WriteAttributeValue("", 5130, padding, 5130, 10, false);
76 WriteAttributeValue("", 5140, "px", 5140, 2, true);
77 EndWriteAttribute();
78 WriteLiteral(">\r\n\t\t\t\t<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"");
79 BeginWriteAttribute("style", " style=\"", 5234, "\"", 5325, 3);
80 WriteAttributeValue("", 5242, "mso-table-lspace:0pt;mso-table-rspace:0pt;", 5242, 42, true);
81 WriteAttributeValue("", 5284, GetTableReset(), 5284, 16, false);
82 WriteAttributeValue("", 5300, "color:inherit;width:100%;", 5300, 25, true);
83 EndWriteAttribute();
84 WriteLiteral(">\r\n\t\t\t\t\t<tbody>\r\n");
85 if (products is object && products.Any())
86 {
87 WriteLiteral("\t\t\t\t\t\t\t");
88 WriteLiteral("<tr style=\"");
89 Write(GetTableReset());
90 WriteLiteral("\">\r\n");
91
92 int index = 1;
93 int totalProducts = products.Count();
94 foreach (var product in products)
95 {
96 WriteLiteral("\t\t\t\t\t\t\t\t<td valign=\"top\"");
97 BeginWriteAttribute("style", " style=\"", 5589, "\"", 5628, 2);
98 WriteAttributeValue("", 5597, GetTableReset(), 5597, 16, false);
99 WriteAttributeValue("", 5613, GetFontStack(), 5613, 15, false);
100 EndWriteAttribute();
101 WriteLiteral(">\r\n");
102 Write(RenderProduct(product, blockTheme, align));
103 WriteLiteral("\t\t\t\t\t\t\t\t</td>\r\n");
104
105 if (index % layoutColumns == 0 && !(index == totalProducts))
106 {
107 WriteLiteral("\t\t\t\t\t\t\t\t");
108 WriteLiteral("</tr>\r\n\t\t\t\t\t\t\t\t");
109 WriteLiteral("<tr style=\"");
110 Write(GetTableReset());
111 WriteLiteral("\">\r\n\t\t\t\t\t\t\t\t\t");
112 WriteLiteral("<td style=\"");
113 Write(GetTableReset());
114 WriteLiteral("\" colspan=\"100%\" height=\"");
115 Write(cellSpacing * 4);
116 WriteLiteral("\"> </td>\r\n\t\t\t\t\t\t\t\t");
117 WriteLiteral("</tr>\r\n\t\t\t\t\t\t\t\t");
118 WriteLiteral("<tr style=\"");
119 Write(GetTableReset());
120 WriteLiteral("\">\r\n");
121 }
122 else
123 {
124 if(!(index == totalProducts))
125 {
126 WriteLiteral("\t\t\t\t\t\t\t\t\t\t");
127 WriteLiteral("<td width=\"");
128 Write(cellSpacing);
129 WriteLiteral("\" style=\"");
130 Write(GetTableReset());
131 WriteLiteral("\"> </td>\r\n");
132 }
133 }
134
135 index++;
136 }
137 WriteLiteral("\t\t\t\t\t\t\t");
138 WriteLiteral("</tr>\r\n");
139 }
140 else
141 {
142 if (Pageview.IsVisualEditorMode)
143 {
144 WriteLiteral("\t\t\t\t\t\t\t\t<tr");
145 BeginWriteAttribute("style", " style=\"", 6327, "\"", 6366, 2);
146 WriteAttributeValue("", 6335, GetTableReset(), 6335, 16, false);
147 WriteAttributeValue("", 6351, GetFontStack(), 6351, 15, false);
148 EndWriteAttribute();
149 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t\t<td");
150 BeginWriteAttribute("style", " style=\"", 6382, "\"", 6408, 1);
151 WriteAttributeValue("", 6390, foregroundColor, 6390, 18, false);
152 EndWriteAttribute();
153 WriteLiteral(">");
154 Write(Translate("No products selected"));
155 WriteLiteral("</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n");
156 }
157 }
158 WriteLiteral("\t\t\t\t\t</tbody>\r\n\r\n\t\t\t\t</table>\r\n\t\t\t\t<!--[if mso]><br/><![endif]-->\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t\t\r\n\t</tbody>\r\n</table>\r\n\r\n");
159 Write(helper);
160 WriteLiteral(@" RenderImage(ProductViewModel product, Dynamicweb.Frontend.ItemViewModel theme)
161 {
162 int layout = Dynamicweb.Core.Converter.ToInt32(Model.Item.GetRawValueString(""Layout"", ""2""));
163 int padding = Convert.ToInt32(Model.Item.GetRawValueString(""Padding"", ""0""));
164 var imageRatio = Model.Item.GetRawValueString(""ImageAspectRatio"", ""4-3"").ToLower();
165
166 var parms = new Dictionary<string, object>();
167 parms.Add(""alt"", product.Name);
168 parms.Add(""columns"", layout);
169 parms.Add(""gridColumns"", Model.GridRowColumnCount);
170 parms.Add(""nested"", Model.GridRowColumnCount > 1);
171 parms.Add(""padding"", (padding * 2) + (8 * (layout - 1)));
172 parms.Add(""imageRatio"", imageRatio);
173
174 if(product.DefaultImage is object)
175 {
176 ");
177 Write(RenderPartial("Swift_Email/Components/Image.cshtml", new Dynamicweb.Frontend.FileViewModel() {Name = product.Name, Path = product.DefaultImage.Value }, parms));
178 WriteLiteral(";\r\n }\r\n}\r\n\r\n");
179 Write(helper);
180 WriteLiteral(@" RenderProduct(ProductViewModel product, Dynamicweb.Frontend.ItemViewModel theme, string align)
181 {
182 var backgroundColor = theme?.GetColor(""BackgroundColor"");
183 var foregroundColor = theme?.GetColor(""ForegroundColor"");
184 var borderColor = theme?.GetColor(""BorderColor"");
185
186 string link = product.GetProductLink(GetPageIdByNavigationTag(""Shop""), false);
187
188 var uri = Dynamicweb.Context.Current.Request.Url;
189 var hostname = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
190
191 bool hideProductPrice = Model.Item?.GetBoolean(""HideProductPrice"") ?? false;
192 bool hideProductNumber = Model.Item?.GetBoolean(""HideProductNumber"") ?? false;
193
194 <table");
195 BeginWriteAttribute("style", " style=\"", 8144, "\"", 8212, 2);
196 WriteAttributeValue("", 8152, "border-collapse:collapse;table-layout:fixed;", 8152, 44, true);
197 WriteAttributeValue("", 8196, GetTableReset(), 8196, 16, false);
198 EndWriteAttribute();
199 WriteLiteral(" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" role=\"presentation\">\r\n\t\t<tbody>\r\n\t\t\t<tr");
200 BeginWriteAttribute("style", " style=\"", 8298, "\"", 8322, 1);
201 WriteAttributeValue("", 8306, GetTableReset(), 8306, 16, false);
202 EndWriteAttribute();
203 WriteLiteral(">\r\n\t\t\t\t<td");
204 BeginWriteAttribute("style", " style=\"", 8333, "\"", 8357, 1);
205 WriteAttributeValue("", 8341, GetTableReset(), 8341, 16, false);
206 EndWriteAttribute();
207 WriteLiteral(">\r\n\r\n\t\t\t\t\t<div align=\"center\" style=\"font-size:2px;\">\r\n\t\t\t\t\t\t<a style=\"text-decoration:none;\"");
208 BeginWriteAttribute("href", " href=\"", 8451, "\"", 8463, 1);
209 WriteAttributeValue("", 8458, link, 8458, 5, false);
210 EndWriteAttribute();
211 WriteLiteral(" target=\"_blank\">\r\n");
212 Write(RenderImage(product, theme));
213 WriteLiteral("\t\t\t\t\t\t</a>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t<table");
214 BeginWriteAttribute("style", " style=\"", 8569, "\"", 8637, 2);
215 WriteAttributeValue("", 8577, "border-collapse:collapse;table-layout:fixed;", 8577, 44, true);
216 WriteAttributeValue("", 8621, GetTableReset(), 8621, 16, false);
217 EndWriteAttribute();
218 WriteLiteral(" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" role=\"presentation\">\r\n\t\t\t\t\t\t<tbody>\r\n\t\t\t\t\t\t\t<tr");
219 BeginWriteAttribute("style", " style=\"", 8731, "\"", 8755, 1);
220 WriteAttributeValue("", 8739, GetTableReset(), 8739, 16, false);
221 EndWriteAttribute();
222 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t<td");
223 BeginWriteAttribute("style", " style=\"", 8770, "\"", 8904, 6);
224 WriteAttributeValue("", 8778, GetTableReset(), 8778, 16, false);
225 WriteAttributeValue("", 8794, "padding-top:8px;text-align:", 8794, 27, true);
226 WriteAttributeValue("", 8821, align, 8821, 6, false);
227 WriteAttributeValue("", 8827, ";line-height:18px;font-size:13px;text-decoration:none;color:", 8827, 60, true);
228 WriteAttributeValue("", 8887, foregroundColor, 8887, 16, false);
229 WriteAttributeValue("", 8903, ";", 8903, 1, true);
230 EndWriteAttribute();
231 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t\t<a");
232 BeginWriteAttribute("style", " style=\"", 8919, "\"", 9002, 5);
233 WriteAttributeValue("", 8927, "text-decoration:none;color:", 8927, 27, true);
234 WriteAttributeValue("", 8954, foregroundColor, 8954, 16, false);
235 WriteAttributeValue("", 8970, ";", 8970, 1, true);
236 WriteAttributeValue("", 8971, GetTableReset(), 8971, 16, false);
237 WriteAttributeValue("", 8987, GetFontStack(), 8987, 15, false);
238 EndWriteAttribute();
239 BeginWriteAttribute("href", " href=\"", 9003, "\"", 9015, 1);
240 WriteAttributeValue("", 9010, link, 9010, 5, false);
241 EndWriteAttribute();
242 WriteLiteral(" target=\"_blank\">\r\n\t\t\t\t\t\t\t\t\t\t");
243 Write(product.Name);
244 WriteLiteral("\r\n\t\t\t\t\t\t\t\t\t</a>\r\n\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t</tr>\r\n\r\n");
245 if (!hideProductNumber)
246 {
247 WriteLiteral("\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<td");
248 BeginWriteAttribute("style", " style=\"", 9175, "\"", 9310, 5);
249 WriteAttributeValue("", 9183, GetTableReset(), 9183, 16, false);
250 WriteAttributeValue("", 9199, GetFontStack(), 9199, 15, false);
251 WriteAttributeValue("", 9214, "padding-top:8px;line-height:18px;font-size:11px;color:", 9214, 54, true);
252 WriteAttributeValue("", 9268, GetMutedColor(foregroundColor.Hex, 20), 9268, 41, false);
253 WriteAttributeValue("", 9309, ";", 9309, 1, true);
254 EndWriteAttribute();
255 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t\t\t");
256 Write(product.Number);
257 WriteLiteral("\r\n\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n");
258 }
259 WriteLiteral("\r\n");
260 if (!hideProductPrice)
261 {
262 WriteLiteral("\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<td");
263 BeginWriteAttribute("style", " style=\"", 9452, "\"", 9622, 5);
264 WriteAttributeValue("", 9460, GetTableReset(), 9460, 16, false);
265 WriteAttributeValue("", 9476, GetFontStack(), 9476, 15, false);
266 WriteAttributeValue("", 9491, "padding-top:8px;line-height:13px;font-size:13px;break-inside:avoid;word-break:keep-all;white-space:nowrap;color:", 9491, 112, true);
267 WriteAttributeValue("", 9603, foregroundColor, 9603, 18, false);
268 WriteAttributeValue("", 9621, ";", 9621, 1, true);
269 EndWriteAttribute();
270 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t\t\t");
271 Write(product.Price.PriceFormatted);
272 WriteLiteral("\r\n\r\n");
273 if (product.Discount.Price > 0)
274 {
275 WriteLiteral("\t\t\t\t\t\t\t\t\t\t\t<span");
276 BeginWriteAttribute("style", " style=\"", 9742, "\"", 9917, 3);
277 WriteAttributeValue("", 9750, "line-height:13px;font-size:13px;text-decoration:line-through;break-inside:avoid;word-break:keep-all;white-space:nowrap;color:", 9750, 125, true);
278 WriteAttributeValue("", 9875, GetMutedColor(foregroundColor.Hex, 20), 9875, 41, false);
279 WriteAttributeValue("", 9916, ";", 9916, 1, true);
280 EndWriteAttribute();
281 WriteLiteral(">");
282 Write(product.PriceBeforeDiscount.PriceFormatted);
283 WriteLiteral("</span>\r\n");
284 }
285 WriteLiteral("\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n");
286 }
287 WriteLiteral("\t\t\t\t\t\t\t<tr><td height=\"24\" style=\"padding-top:24px;\"></td></tr>\r\n\t\t\t\t\t\t</tbody>\r\n\t\t\t\t\t</table>\r\n\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t\t\r\n\t\t</tbody>\r\n\t</table>\r\n}\r\n");
288 }
289 #pragma warning restore 1998
290
291 private string GetFontStack()
292 {
293 return "font-family:initial,Arial,Helvetica Neue,Helvetica,sans-serif;";
294 }
295
296 private string GetTableReset()
297 {
298 return "border:0;margin:0;outline:0;padding:0;";
299 }
300
301 public Dynamicweb.Frontend.ColorViewModel GetMutedColor(string hex, int percent, double threshold = 0.5)
302 {
303 /// <summary>
304 /// Return a color in either lighter or darker contrast based on the original color luminance.
305 /// </summary>
306 /// <param name="percent">The percent (1-100) to darken or light the color with - higher percentage will give higher contrast</param>
307 /// <param name="threshold">The luminance threshold (0-1). Default is 0.5. 0 is black, 1 is white. Luminance threshold is used to decide wether the returned contrast color should be darker or lighter than the base color</param>
308 /// <returns>A new color viewmodel with the contrasted color in either darker or lighter luminance compared to base color</returns>
309 ///
310 if (threshold > 1)
311 threshold = 1;
312 if (threshold < 0)
313 threshold = 0;
314
315 var color = Dynamicweb.Imaging.Colors.Color.FromHex(hex);
316 var luminance = (0.2126 * color.BaseColor.R) + (0.7152 * color.BaseColor.G) + (0.0722 * color.BaseColor.B);
317 /// == luminance = 0 is black, luminance = 1 is white == //
318 luminance = color.Brightness / 255;
319 if (luminance < threshold)
320 {
321 return new Dynamicweb.Frontend.ColorViewModel() { Hex = color.Lighten(percent).ToHex() };
322 }
323 else
324 {
325 return new Dynamicweb.Frontend.ColorViewModel() { Hex = color.Darken(percent).ToHex() };
326 }
327 }
328 }
329 }
330 #pragma warning restore 1591
331
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
2 @using Dynamicweb.Ecommerce.ProductCatalog
3
4 @functions {
5 private string GetFontStack()
6 {
7 return "font-family:initial,Arial,Helvetica Neue,Helvetica,sans-serif;";
8 }
9
10 private string GetTableReset()
11 {
12 return "border:0;margin:0;outline:0;padding:0;";
13 }
14
15 public Dynamicweb.Frontend.ColorViewModel GetMutedColor(string hex, int percent, double threshold = 0.5)
16 {
17 /// <summary>
18 /// Return a color in either lighter or darker contrast based on the original color luminance.
19 /// </summary>
20 /// <param name="percent">The percent (1-100) to darken or light the color with - higher percentage will give higher contrast</param>
21 /// <param name="threshold">The luminance threshold (0-1). Default is 0.5. 0 is black, 1 is white. Luminance threshold is used to decide wether the returned contrast color should be darker or lighter than the base color</param>
22 /// <returns>A new color viewmodel with the contrasted color in either darker or lighter luminance compared to base color</returns>
23 ///
24 if (threshold > 1)
25 threshold = 1;
26 if (threshold < 0)
27 threshold = 0;
28
29 var color = Dynamicweb.Imaging.Colors.Color.FromHex(hex);
30 var luminance = (0.2126 * color.BaseColor.R) + (0.7152 * color.BaseColor.G) + (0.0722 * color.BaseColor.B);
31 /// == luminance = 0 is black, luminance = 1 is white == //
32 luminance = color.Brightness / 255;
33 if (luminance < threshold)
34 {
35 return new Dynamicweb.Frontend.ColorViewModel() { Hex = color.Lighten(percent).ToHex() };
36 }
37 else
38 {
39 return new Dynamicweb.Frontend.ColorViewModel() { Hex = color.Darken(percent).ToHex() };
40 }
41 }
42 }
43
44 @{
45 string blockType = "productcatalog_block";
46
47 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageID);
48 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
49 var blockId = Model.ID;
50 var block = Model.Item;
51
52 var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
53 var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
54 var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
55
56 var rowId = Pageview.CurrentParagraph.GridRowId;
57 var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
58 var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
59 var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
60 var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
61 var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
62
63 var blockThemeId = block.GetRawValueString("Theme");
64 var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
65 var blockTheme = blockThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph)?.Item : rowTheme is object ? rowTheme : emailContentTheme;
66
67 string backgroundColor = blockTheme != null ? "background-color: " + blockTheme.GetString("BackgroundColor") + ";" : string.Empty;
68 string foregroundColor = blockTheme != null ? "color:" + blockTheme.GetString("ForegroundColor", "inherit") + ";" : string.Empty;
69
70 string title = block.GetString("Title", string.Empty);
71 int padding = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Padding", "0"));
72 int cellSpacing = 8;
73 string align = block.GetRawValueString("Align", "left");
74 string text = block.GetString("Text", string.Empty);
75 var layoutColumns = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Layout", "2"));
76
77 ProductListViewModel selectedProducts = block?.GetValue("Products") as ProductListViewModel;
78 IList<ProductViewModel> products = selectedProducts?.Products;
79 }
80
81 <table id="@blockId" class="@blockType" align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;@GetTableReset()color:inherit;width:100%;@(backgroundColor)">
82 <tbody>
83 <tr style="@GetTableReset()">
84 <td style="@GetTableReset()padding:@(padding)px">
85 <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;@GetTableReset()color:inherit;width:100%;">
86 <tbody>
87 @if (products is object && products.Any())
88 {
89 @:<tr style="@GetTableReset()">
90
91 int index = 1;
92 int totalProducts = products.Count();
93 foreach (var product in products)
94 {
95 <td valign="top" style="@GetTableReset()@GetFontStack()">
96 @{ @RenderProduct(product, blockTheme, align) }
97 </td>
98
99 if (index % layoutColumns == 0 && !(index == totalProducts))
100 {
101 @:</tr>
102 @:<tr style="@GetTableReset()">
103 @:<td style="@GetTableReset()" colspan="100%" height="@(cellSpacing * 4)"> </td>
104 @:</tr>
105 @:<tr style="@GetTableReset()">
106 }
107 else
108 {
109 if(!(index == totalProducts))
110 {
111 @:<td width="@(cellSpacing)" style="@GetTableReset()"> </td>
112 }
113 }
114
115 index++;
116 }
117 @:</tr>
118 }
119 else
120 {
121 if (Pageview.IsVisualEditorMode)
122 {
123 <tr style="@GetTableReset()@GetFontStack()">
124 <td style="@(foregroundColor)">@Translate("No products selected")</td>
125 </tr>
126 }
127 }
128 </tbody>
129
130 </table>
131 <!--[if mso]><br/><![endif]-->
132 </td>
133 </tr>
134
135 </tbody>
136 </table>
137
138 @helper RenderImage(ProductViewModel product, Dynamicweb.Frontend.ItemViewModel theme)
139 {
140 int layout = Dynamicweb.Core.Converter.ToInt32(Model.Item.GetRawValueString("Layout", "2"));
141 int padding = Convert.ToInt32(Model.Item.GetRawValueString("Padding", "0"));
142 var imageRatio = Model.Item.GetRawValueString("ImageAspectRatio", "4-3").ToLower();
143
144 var parms = new Dictionary<string, object>();
145 parms.Add("alt", product.Name);
146 parms.Add("columns", layout);
147 parms.Add("gridColumns", Model.GridRowColumnCount);
148 parms.Add("nested", Model.GridRowColumnCount > 1);
149 parms.Add("padding", (padding * 2) + (8 * (layout - 1)));
150 parms.Add("imageRatio", imageRatio);
151
152 if(product.DefaultImage is object)
153 {
154 @RenderPartial("Swift_Email/Components/Image.cshtml", new Dynamicweb.Frontend.FileViewModel() {Name = product.Name, Path = product.DefaultImage.Value }, parms);
155 }
156 }
157
158 @helper RenderProduct(ProductViewModel product, Dynamicweb.Frontend.ItemViewModel theme, string align)
159 {
160 var backgroundColor = theme?.GetColor("BackgroundColor");
161 var foregroundColor = theme?.GetColor("ForegroundColor");
162 var borderColor = theme?.GetColor("BorderColor");
163
164 string link = product.GetProductLink(GetPageIdByNavigationTag("Shop"), false);
165
166 var uri = Dynamicweb.Context.Current.Request.Url;
167 var hostname = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
168
169 bool hideProductPrice = Model.Item?.GetBoolean("HideProductPrice") ?? false;
170 bool hideProductNumber = Model.Item?.GetBoolean("HideProductNumber") ?? false;
171
172 <table style="border-collapse:collapse;table-layout:fixed;@GetTableReset()" cellpadding="0" cellspacing="0" width="100%" role="presentation">
173 <tbody>
174 <tr style="@GetTableReset()">
175 <td style="@GetTableReset()">
176
177 <div align="center" style="font-size:2px;">
178 <a style="text-decoration:none;" href="@link" target="_blank">
179 @{ @RenderImage(product, theme) }
180 </a>
181 </div>
182
183 <table style="border-collapse:collapse;table-layout:fixed;@GetTableReset()" cellpadding="0" cellspacing="0" width="100%" role="presentation">
184 <tbody>
185 <tr style="@GetTableReset()">
186 <td style="@GetTableReset()padding-top:8px;text-align:@align;line-height:18px;font-size:13px;text-decoration:none;color:@foregroundColor;">
187 <a style="text-decoration:none;color:@foregroundColor;@GetTableReset()@GetFontStack()" href="@link" target="_blank">
188 @product.Name
189 </a>
190 </td>
191 </tr>
192
193 @if (!hideProductNumber)
194 {
195 <tr>
196 <td style="@GetTableReset()@GetFontStack()padding-top:8px;line-height:18px;font-size:11px;color:@(GetMutedColor(foregroundColor.Hex, 20));">
197 @product.Number
198 </td>
199 </tr>
200 }
201
202 @if (!hideProductPrice)
203 {
204 <tr>
205 <td style="@GetTableReset()@GetFontStack()padding-top:8px;line-height:13px;font-size:13px;break-inside:avoid;word-break:keep-all;white-space:nowrap;color:@(foregroundColor);">
206 @product.Price.PriceFormatted
207
208 @if (product.Discount.Price > 0)
209 {
210 <span style="line-height:13px;font-size:13px;text-decoration:line-through;break-inside:avoid;word-break:keep-all;white-space:nowrap;color:@(GetMutedColor(foregroundColor.Hex, 20));">@product.PriceBeforeDiscount.PriceFormatted</span>
211 }
212 </td>
213 </tr>
214 }
215 <tr><td height="24" style="padding-top:24px;"></td></tr>
216 </tbody>
217 </table>
218
219 </td>
220 </tr>
221
222 </tbody>
223 </table>
224 }
225
|
|
Error executing template "Designs/Swift/eCom/Order/Orderlines.cshtml"
System.ArgumentException: Get page requires a page ID greater than zero, page ID was 0
at Dynamicweb.Core.Ensure.That[TException](Boolean condition, String message)
at Dynamicweb.Content.PageService.GetPage(Int32 pageId)
at CompiledRazorTemplates.Dynamic.RazorEngine_4c77298745d746cdbf22bcea6e93770a.ExecuteAsync()
at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, 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 RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String templateSource, String name, Type modelType, Object model, DynamicViewBag viewBag)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
2 @using Dynamicweb.Frontend
3
4 @functions {
5 private string GetFontStack()
6 {
7 return "font-family:initial,Arial,Helvetica Neue,Helvetica,sans-serif;";
8 }
9
10
11
12 private string GetTableReset()
13 {
14 return "border:0;margin:0;outline:0;padding:0;";
15 }
16 }
17
18 @{
19 ParagraphViewModel currentParagraph = new ParagraphViewModel();
20 if (Dynamicweb.Context.Current.Items.Contains("CurrentParagraph"))
21 {
22 currentParagraph = (ParagraphViewModel)Dynamicweb.Context.Current.Items["CurrentParagraph"];
23 }
24
25 int currentPageId = 0;
26 if (Dynamicweb.Context.Current.Items.Contains("CurrentPageId"))
27 {
28 currentPageId = Convert.ToInt16(Dynamicweb.Context.Current.Items["CurrentPageId"]);
29 }
30
31 int currentGridRowId = 0;
32 if (Dynamicweb.Context.Current.Items.Contains("CurrentGridRowId"))
33 {
34 currentGridRowId = Convert.ToInt16(Dynamicweb.Context.Current.Items["CurrentGridRowId"]);
35 }
36
37 string textPrice = "font-variant-numeric: tabular-nums; white-space: nowrap;";
38
39 var page = Dynamicweb.Content.Services.Pages.GetPage(currentPageId);
40 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
41 var block = currentParagraph.Item;
42
43 var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
44 var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
45 var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
46
47 var rowId = currentGridRowId;
48 var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
49 var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
50 var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
51 var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
52 var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
53
54 var blockThemeId = block.GetRawValueString("Theme");
55 var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
56 var blockTheme = blockThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph)?.Item : rowTheme is object ? rowTheme : emailContentTheme;
57
58 string backgroundColor = blockTheme != null ? "background-color: " + blockTheme.GetString("BackgroundColor") + ";" : string.Empty;
59 string foregroundColor = blockTheme != null ? "color:" + blockTheme.GetString("ForegroundColor", "inherit") + ";" : string.Empty;
60 string borderColor = blockTheme != null ? blockTheme.GetString("BorderColor", "transparent") : string.Empty;
61 string borders = block.GetRawValueString("Borders", "none");
62 string borderThicknes = block.GetRawValueString("BorderThicknes", "0") + "px";
63 string borderClass = string.Empty;
64
65 switch (borders)
66 {
67 case "top":
68 borderClass = $"border-top:{borderThicknes} solid {borderColor};";
69 break;
70 case "bottom":
71 borderClass = $"border-bottom:{borderThicknes} solid {borderColor};";
72 break;
73 case "top-bottom":
74 borderClass = $"border-top:{borderThicknes} solid {borderColor}; border-bottom:{borderThicknes} solid {borderColor}; border-left:0;border-right:0;";
75 break;
76 case "all":
77 borderClass = $"border:{borderThicknes} solid {borderColor};";
78 break;
79 }
80
81 int padding = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Padding", "0"));
82 string align = block.GetRawValueString("Align", "left");
83 string lineHeight = "line-height:" + (16 * Dynamicweb.Core.Converter.ToDouble(block.GetRawValueString("LineHeight", "1.5"))).ToString() + "px;";
84 }
85
86 <tbody>
87 @foreach (LoopItem orderline in GetLoop("OrderLines"))
88 {
89 string name = orderline.GetString("Ecom:Order:OrderLine.ProductName");
90 string image = "Admin/Public/GetImage.ashx?image=" + orderline.GetString("Ecom:Product.PrimaryImage") + "&width=100&height=100";
91 var uri = Dynamicweb.Context.Current.Request.Url;
92 var hostname = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
93 string imagePath = hostname + "/" + image;
94 string priceTotalWithDiscounts = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.TotalPriceWithProductDiscounts.PriceFormatted")) ? orderline.GetString("Ecom:Order:OrderLine.TotalPriceWithProductDiscounts.PriceFormatted") : "";
95 string unitPrice = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.UnitPrice.PriceFormatted")) ? orderline.GetString("Ecom:Order:OrderLine.UnitPrice.PriceFormatted") : "";
96 string discountPrice = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.UnitPriceWithProductDiscount.PriceFormatted")) ? orderline.GetString("Ecom:Order:OrderLine.UnitPriceWithProductDiscount.PriceFormatted") : "";
97 string discountTotal = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.TotalDiscount.PriceFormatted")) ? orderline.GetString("Ecom:Order:OrderLine.TotalDiscount.PriceFormatted") : "";
98 string variantText = orderline.GetString("Ecom:Order:OrderLine.ProductVariantText");
99 var quantity = orderline.GetDouble("Ecom:Order:OrderLine.Quantity");
100
101 bool isProduct = orderline.GetBoolean("Ecom:Order:OrderLine.IsProduct");
102
103 if (isProduct)
104 {
105 <tr style="@GetTableReset()">
106 <td style="word-wrap:anywhere;mso-line-height-rule:exactly;mso-table-lspace:0pt;mso-table-rspace:0pt;@GetTableReset()@GetFontStack()text-align:left;@(backgroundColor)@(foregroundColor)@(lineHeight)word-break:break-word;padding:@(padding)px;@(borderClass)" width="132">
107 @* Image *@
108 <img src="@imagePath" alt="@name">
109 </td>
110 <td style="word-wrap:anywhere;mso-line-height-rule:exactly;mso-table-lspace:0pt;mso-table-rspace:0pt;@GetTableReset()@GetFontStack()text-align:left;@(backgroundColor)@(foregroundColor)@(lineHeight)word-break:break-word;padding:@(padding)px;@(borderClass)">
111 @* Title *@
112 <h3>
113 @name
114 </h3>
115 @* Variants *@
116 <p>@variantText</p>
117 <p>
118 @* Unit price *@
119 @if (discountPrice == unitPrice)
120 {
121 <span style="@(textPrice)">@unitPrice</span>
122 }
123 else
124 {
125 <span style="@(textPrice)">@discountPrice</span>
126 <span style="@(textPrice) text-decoration: line-through;">@unitPrice</span>}
127 </p>
128 @* Quantity *@
129 <p>@Translate("Quantity"): @quantity</p>
130 </td>
131 <td style="word-wrap:anywhere;mso-line-height-rule:exactly;mso-table-lspace:0pt;mso-table-rspace:0pt;@GetTableReset()@GetFontStack()text-align:right;@(backgroundColor)@(foregroundColor)@(lineHeight)word-break:break-word;padding:@(padding)px;@(borderClass)">
132 @* Total *@
133 <span style="@(textPrice)">@priceTotalWithDiscounts</span>
134 @if (orderline.GetDouble("Ecom:Order:OrderLine.TotalDiscount.Price.Value") != 0)
135 {
136 <span style="@(textPrice)">@discountTotal</span>}
137 </td>
138 </tr>
139 }
140 }
141 </tbody>
142
|
|
|
Error compiling template "Designs/Swift/Swift_Email/Paragraph/Copy of Swift_EmailProductCatalog.cshtml"
Line 102: The name 'RenderProduct' does not exist in the current context
Line 159: The name 'helper' does not exist in the current context
Line 177: The name 'product' does not exist in the current context
Line 177: The name 'product' does not exist in the current context
Line 177: The name 'parms' does not exist in the current context
Line 179: The name 'helper' does not exist in the current context
Line 209: The name 'link' does not exist in the current context
Line 212: The name 'RenderImage' does not exist in the current context
Line 212: The name 'product' does not exist in the current context
Line 212: The name 'theme' does not exist in the current context
Line 240: The name 'link' does not exist in the current context
Line 243: The name 'product' does not exist in the current context
Line 245: The name 'hideProductNumber' does not exist in the current context
Line 252: 'string' does not contain a definition for 'Hex' and no accessible extension method 'Hex' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Line 256: The name 'product' does not exist in the current context
Line 260: The name 'hideProductPrice' does not exist in the current context
Line 271: The name 'product' does not exist in the current context
Line 273: The name 'product' does not exist in the current context
Line 278: 'string' does not contain a definition for 'Hex' and no accessible extension method 'Hex' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Line 282: The name 'product' does not exist in the current context
1 // <auto-generated/>
2 #pragma warning disable 1591
3 namespace CompiledRazorTemplates.Dynamic
4 {
5 #line hidden
6 using System.Threading.Tasks;
7 using System;
8 using System.Collections.Generic;
9 using System.Linq;
10 using Dynamicweb.Ecommerce.ProductCatalog;
11 internal class RazorEngine_a74c80d7325748e986448ac52ba61f09 : Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
12 {
13 #pragma warning disable 1998
14 public async override global::System.Threading.Tasks.Task ExecuteAsync()
15 {
16 WriteLiteral("\r\n");
17 WriteLiteral("\r\n");
18
19 string blockType = "productcatalog_block";
20
21 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageID);
22 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
23 var blockId = Model.ID;
24 var block = Model.Item;
25
26 var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
27 var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
28 var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
29
30 var rowId = Pageview.CurrentParagraph.GridRowId;
31 var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
32 var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
33 var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
34 var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
35 var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
36
37 var blockThemeId = block.GetRawValueString("Theme");
38 var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
39 var blockTheme = blockThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph)?.Item : rowTheme is object ? rowTheme : emailContentTheme;
40
41 string backgroundColor = blockTheme != null ? "background-color: " + blockTheme.GetString("BackgroundColor") + ";" : string.Empty;
42 string foregroundColor = blockTheme != null ? "color:" + blockTheme.GetString("ForegroundColor", "inherit") + ";" : string.Empty;
43
44 string title = block.GetString("Title", string.Empty);
45 int padding = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Padding", "0"));
46 int cellSpacing = 8;
47 string align = block.GetRawValueString("Align", "left");
48 string text = block.GetString("Text", string.Empty);
49 var layoutColumns = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Layout", "2"));
50
51 ProductListViewModel selectedProducts = block?.GetValue("Products") as ProductListViewModel;
52 IList<ProductViewModel> products = selectedProducts?.Products;
53 WriteLiteral("\r\n<table");
54 BeginWriteAttribute("id", " id=\"", 4825, "\"", 4838, 1);
55 WriteAttributeValue("", 4830, blockId, 4830, 8, false);
56 EndWriteAttribute();
57 BeginWriteAttribute("class", " class=\"", 4839, "\"", 4857, 1);
58 WriteAttributeValue("", 4847, blockType, 4847, 10, false);
59 EndWriteAttribute();
60 WriteLiteral(" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"");
61 BeginWriteAttribute("style", " style=\"", 4936, "\"", 5045, 4);
62 WriteAttributeValue("", 4944, "mso-table-lspace:0pt;mso-table-rspace:0pt;", 4944, 42, true);
63 WriteAttributeValue("", 4986, GetTableReset(), 4986, 16, false);
64 WriteAttributeValue("", 5002, "color:inherit;width:100%;", 5002, 25, true);
65 WriteAttributeValue("", 5027, backgroundColor, 5027, 18, false);
66 EndWriteAttribute();
67 WriteLiteral(">\r\n\t<tbody>\r\n\t\t<tr");
68 BeginWriteAttribute("style", " style=\"", 5064, "\"", 5088, 1);
69 WriteAttributeValue("", 5072, GetTableReset(), 5072, 16, false);
70 EndWriteAttribute();
71 WriteLiteral(">\r\n\t\t\t<td");
72 BeginWriteAttribute("style", " style=\"", 5098, "\"", 5142, 4);
73 WriteAttributeValue("", 5106, GetTableReset(), 5106, 16, false);
74 WriteAttributeValue("", 5122, "padding:", 5122, 8, true);
75 WriteAttributeValue("", 5130, padding, 5130, 10, false);
76 WriteAttributeValue("", 5140, "px", 5140, 2, true);
77 EndWriteAttribute();
78 WriteLiteral(">\r\n\t\t\t\t<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"");
79 BeginWriteAttribute("style", " style=\"", 5234, "\"", 5325, 3);
80 WriteAttributeValue("", 5242, "mso-table-lspace:0pt;mso-table-rspace:0pt;", 5242, 42, true);
81 WriteAttributeValue("", 5284, GetTableReset(), 5284, 16, false);
82 WriteAttributeValue("", 5300, "color:inherit;width:100%;", 5300, 25, true);
83 EndWriteAttribute();
84 WriteLiteral(">\r\n\t\t\t\t\t<tbody>\r\n");
85 if (products is object && products.Any())
86 {
87 WriteLiteral("\t\t\t\t\t\t\t");
88 WriteLiteral("<tr style=\"");
89 Write(GetTableReset());
90 WriteLiteral("\">\r\n");
91
92 int index = 1;
93 int totalProducts = products.Count();
94 foreach (var product in products)
95 {
96 WriteLiteral("\t\t\t\t\t\t\t\t<td valign=\"top\"");
97 BeginWriteAttribute("style", " style=\"", 5589, "\"", 5628, 2);
98 WriteAttributeValue("", 5597, GetTableReset(), 5597, 16, false);
99 WriteAttributeValue("", 5613, GetFontStack(), 5613, 15, false);
100 EndWriteAttribute();
101 WriteLiteral(">\r\n");
102 Write(RenderProduct(product, blockTheme, align));
103 WriteLiteral("\t\t\t\t\t\t\t\t</td>\r\n");
104
105 if (index % layoutColumns == 0 && !(index == totalProducts))
106 {
107 WriteLiteral("\t\t\t\t\t\t\t\t");
108 WriteLiteral("</tr>\r\n\t\t\t\t\t\t\t\t");
109 WriteLiteral("<tr style=\"");
110 Write(GetTableReset());
111 WriteLiteral("\">\r\n\t\t\t\t\t\t\t\t\t");
112 WriteLiteral("<td style=\"");
113 Write(GetTableReset());
114 WriteLiteral("\" colspan=\"100%\" height=\"");
115 Write(cellSpacing * 4);
116 WriteLiteral("\"> </td>\r\n\t\t\t\t\t\t\t\t");
117 WriteLiteral("</tr>\r\n\t\t\t\t\t\t\t\t");
118 WriteLiteral("<tr style=\"");
119 Write(GetTableReset());
120 WriteLiteral("\">\r\n");
121 }
122 else
123 {
124 if(!(index == totalProducts))
125 {
126 WriteLiteral("\t\t\t\t\t\t\t\t\t\t");
127 WriteLiteral("<td width=\"");
128 Write(cellSpacing);
129 WriteLiteral("\" style=\"");
130 Write(GetTableReset());
131 WriteLiteral("\"> </td>\r\n");
132 }
133 }
134
135 index++;
136 }
137 WriteLiteral("\t\t\t\t\t\t\t");
138 WriteLiteral("</tr>\r\n");
139 }
140 else
141 {
142 if (Pageview.IsVisualEditorMode)
143 {
144 WriteLiteral("\t\t\t\t\t\t\t\t<tr");
145 BeginWriteAttribute("style", " style=\"", 6327, "\"", 6366, 2);
146 WriteAttributeValue("", 6335, GetTableReset(), 6335, 16, false);
147 WriteAttributeValue("", 6351, GetFontStack(), 6351, 15, false);
148 EndWriteAttribute();
149 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t\t<td");
150 BeginWriteAttribute("style", " style=\"", 6382, "\"", 6408, 1);
151 WriteAttributeValue("", 6390, foregroundColor, 6390, 18, false);
152 EndWriteAttribute();
153 WriteLiteral(">");
154 Write(Translate("No products selected"));
155 WriteLiteral("</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n");
156 }
157 }
158 WriteLiteral("\t\t\t\t\t</tbody>\r\n\r\n\t\t\t\t</table>\r\n\t\t\t\t<!--[if mso]><br/><![endif]-->\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t\t\r\n\t</tbody>\r\n</table>\r\n\r\n");
159 Write(helper);
160 WriteLiteral(@" RenderImage(ProductViewModel product, Dynamicweb.Frontend.ItemViewModel theme)
161 {
162 int layout = Dynamicweb.Core.Converter.ToInt32(Model.Item.GetRawValueString(""Layout"", ""2""));
163 int padding = Convert.ToInt32(Model.Item.GetRawValueString(""Padding"", ""0""));
164 var imageRatio = Model.Item.GetRawValueString(""ImageAspectRatio"", ""4-3"").ToLower();
165
166 var parms = new Dictionary<string, object>();
167 parms.Add(""alt"", product.Name);
168 parms.Add(""columns"", layout);
169 parms.Add(""gridColumns"", Model.GridRowColumnCount);
170 parms.Add(""nested"", Model.GridRowColumnCount > 1);
171 parms.Add(""padding"", (padding * 2) + (8 * (layout - 1)));
172 parms.Add(""imageRatio"", imageRatio);
173
174 if(product.DefaultImage is object)
175 {
176 ");
177 Write(RenderPartial("Swift_Email/Components/Image.cshtml", new Dynamicweb.Frontend.FileViewModel() {Name = product.Name, Path = product.DefaultImage.Value }, parms));
178 WriteLiteral(";\r\n }\r\n}\r\n\r\n");
179 Write(helper);
180 WriteLiteral(@" RenderProduct(ProductViewModel product, Dynamicweb.Frontend.ItemViewModel theme, string align)
181 {
182 var backgroundColor = theme?.GetColor(""BackgroundColor"");
183 var foregroundColor = theme?.GetColor(""ForegroundColor"");
184 var borderColor = theme?.GetColor(""BorderColor"");
185
186 string link = product.GetProductLink(GetPageIdByNavigationTag(""Shop""), false);
187
188 var uri = Dynamicweb.Context.Current.Request.Url;
189 var hostname = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
190
191 bool hideProductPrice = Model.Item?.GetBoolean(""HideProductPrice"") ?? false;
192 bool hideProductNumber = Model.Item?.GetBoolean(""HideProductNumber"") ?? false;
193
194 <table");
195 BeginWriteAttribute("style", " style=\"", 8144, "\"", 8212, 2);
196 WriteAttributeValue("", 8152, "border-collapse:collapse;table-layout:fixed;", 8152, 44, true);
197 WriteAttributeValue("", 8196, GetTableReset(), 8196, 16, false);
198 EndWriteAttribute();
199 WriteLiteral(" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" role=\"presentation\">\r\n\t\t<tbody>\r\n\t\t\t<tr");
200 BeginWriteAttribute("style", " style=\"", 8298, "\"", 8322, 1);
201 WriteAttributeValue("", 8306, GetTableReset(), 8306, 16, false);
202 EndWriteAttribute();
203 WriteLiteral(">\r\n\t\t\t\t<td");
204 BeginWriteAttribute("style", " style=\"", 8333, "\"", 8357, 1);
205 WriteAttributeValue("", 8341, GetTableReset(), 8341, 16, false);
206 EndWriteAttribute();
207 WriteLiteral(">\r\n\r\n\t\t\t\t\t<div align=\"center\" style=\"font-size:2px;\">\r\n\t\t\t\t\t\t<a style=\"text-decoration:none;\"");
208 BeginWriteAttribute("href", " href=\"", 8451, "\"", 8463, 1);
209 WriteAttributeValue("", 8458, link, 8458, 5, false);
210 EndWriteAttribute();
211 WriteLiteral(" target=\"_blank\">\r\n");
212 Write(RenderImage(product, theme));
213 WriteLiteral("\t\t\t\t\t\t</a>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t<table");
214 BeginWriteAttribute("style", " style=\"", 8569, "\"", 8637, 2);
215 WriteAttributeValue("", 8577, "border-collapse:collapse;table-layout:fixed;", 8577, 44, true);
216 WriteAttributeValue("", 8621, GetTableReset(), 8621, 16, false);
217 EndWriteAttribute();
218 WriteLiteral(" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" role=\"presentation\">\r\n\t\t\t\t\t\t<tbody>\r\n\t\t\t\t\t\t\t<tr");
219 BeginWriteAttribute("style", " style=\"", 8731, "\"", 8755, 1);
220 WriteAttributeValue("", 8739, GetTableReset(), 8739, 16, false);
221 EndWriteAttribute();
222 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t<td");
223 BeginWriteAttribute("style", " style=\"", 8770, "\"", 8904, 6);
224 WriteAttributeValue("", 8778, GetTableReset(), 8778, 16, false);
225 WriteAttributeValue("", 8794, "padding-top:8px;text-align:", 8794, 27, true);
226 WriteAttributeValue("", 8821, align, 8821, 6, false);
227 WriteAttributeValue("", 8827, ";line-height:18px;font-size:13px;text-decoration:none;color:", 8827, 60, true);
228 WriteAttributeValue("", 8887, foregroundColor, 8887, 16, false);
229 WriteAttributeValue("", 8903, ";", 8903, 1, true);
230 EndWriteAttribute();
231 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t\t<a");
232 BeginWriteAttribute("style", " style=\"", 8919, "\"", 9002, 5);
233 WriteAttributeValue("", 8927, "text-decoration:none;color:", 8927, 27, true);
234 WriteAttributeValue("", 8954, foregroundColor, 8954, 16, false);
235 WriteAttributeValue("", 8970, ";", 8970, 1, true);
236 WriteAttributeValue("", 8971, GetTableReset(), 8971, 16, false);
237 WriteAttributeValue("", 8987, GetFontStack(), 8987, 15, false);
238 EndWriteAttribute();
239 BeginWriteAttribute("href", " href=\"", 9003, "\"", 9015, 1);
240 WriteAttributeValue("", 9010, link, 9010, 5, false);
241 EndWriteAttribute();
242 WriteLiteral(" target=\"_blank\">\r\n\t\t\t\t\t\t\t\t\t\t");
243 Write(product.Name);
244 WriteLiteral("\r\n\t\t\t\t\t\t\t\t\t</a>\r\n\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t</tr>\r\n\r\n");
245 if (!hideProductNumber)
246 {
247 WriteLiteral("\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<td");
248 BeginWriteAttribute("style", " style=\"", 9175, "\"", 9310, 5);
249 WriteAttributeValue("", 9183, GetTableReset(), 9183, 16, false);
250 WriteAttributeValue("", 9199, GetFontStack(), 9199, 15, false);
251 WriteAttributeValue("", 9214, "padding-top:8px;line-height:18px;font-size:11px;color:", 9214, 54, true);
252 WriteAttributeValue("", 9268, GetMutedColor(foregroundColor.Hex, 20), 9268, 41, false);
253 WriteAttributeValue("", 9309, ";", 9309, 1, true);
254 EndWriteAttribute();
255 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t\t\t");
256 Write(product.Number);
257 WriteLiteral("\r\n\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n");
258 }
259 WriteLiteral("\r\n");
260 if (!hideProductPrice)
261 {
262 WriteLiteral("\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<td");
263 BeginWriteAttribute("style", " style=\"", 9452, "\"", 9622, 5);
264 WriteAttributeValue("", 9460, GetTableReset(), 9460, 16, false);
265 WriteAttributeValue("", 9476, GetFontStack(), 9476, 15, false);
266 WriteAttributeValue("", 9491, "padding-top:8px;line-height:13px;font-size:13px;break-inside:avoid;word-break:keep-all;white-space:nowrap;color:", 9491, 112, true);
267 WriteAttributeValue("", 9603, foregroundColor, 9603, 18, false);
268 WriteAttributeValue("", 9621, ";", 9621, 1, true);
269 EndWriteAttribute();
270 WriteLiteral(">\r\n\t\t\t\t\t\t\t\t\t\t");
271 Write(product.Price.PriceFormatted);
272 WriteLiteral("\r\n\r\n");
273 if (product.Discount.Price > 0)
274 {
275 WriteLiteral("\t\t\t\t\t\t\t\t\t\t\t<span");
276 BeginWriteAttribute("style", " style=\"", 9742, "\"", 9917, 3);
277 WriteAttributeValue("", 9750, "line-height:13px;font-size:13px;text-decoration:line-through;break-inside:avoid;word-break:keep-all;white-space:nowrap;color:", 9750, 125, true);
278 WriteAttributeValue("", 9875, GetMutedColor(foregroundColor.Hex, 20), 9875, 41, false);
279 WriteAttributeValue("", 9916, ";", 9916, 1, true);
280 EndWriteAttribute();
281 WriteLiteral(">");
282 Write(product.PriceBeforeDiscount.PriceFormatted);
283 WriteLiteral("</span>\r\n");
284 }
285 WriteLiteral("\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n");
286 }
287 WriteLiteral("\t\t\t\t\t\t\t<tr><td height=\"24\" style=\"padding-top:24px;\"></td></tr>\r\n\t\t\t\t\t\t</tbody>\r\n\t\t\t\t\t</table>\r\n\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t\t\r\n\t\t</tbody>\r\n\t</table>\r\n}\r\n");
288 }
289 #pragma warning restore 1998
290
291 private string GetFontStack()
292 {
293 return "font-family:initial,Arial,Helvetica Neue,Helvetica,sans-serif;";
294 }
295
296 private string GetTableReset()
297 {
298 return "border:0;margin:0;outline:0;padding:0;";
299 }
300
301 public Dynamicweb.Frontend.ColorViewModel GetMutedColor(string hex, int percent, double threshold = 0.5)
302 {
303 /// <summary>
304 /// Return a color in either lighter or darker contrast based on the original color luminance.
305 /// </summary>
306 /// <param name="percent">The percent (1-100) to darken or light the color with - higher percentage will give higher contrast</param>
307 /// <param name="threshold">The luminance threshold (0-1). Default is 0.5. 0 is black, 1 is white. Luminance threshold is used to decide wether the returned contrast color should be darker or lighter than the base color</param>
308 /// <returns>A new color viewmodel with the contrasted color in either darker or lighter luminance compared to base color</returns>
309 ///
310 if (threshold > 1)
311 threshold = 1;
312 if (threshold < 0)
313 threshold = 0;
314
315 var color = Dynamicweb.Imaging.Colors.Color.FromHex(hex);
316 var luminance = (0.2126 * color.BaseColor.R) + (0.7152 * color.BaseColor.G) + (0.0722 * color.BaseColor.B);
317 /// == luminance = 0 is black, luminance = 1 is white == //
318 luminance = color.Brightness / 255;
319 if (luminance < threshold)
320 {
321 return new Dynamicweb.Frontend.ColorViewModel() { Hex = color.Lighten(percent).ToHex() };
322 }
323 else
324 {
325 return new Dynamicweb.Frontend.ColorViewModel() { Hex = color.Darken(percent).ToHex() };
326 }
327 }
328 }
329 }
330 #pragma warning restore 1591
331
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
2 @using Dynamicweb.Ecommerce.ProductCatalog
3
4 @functions {
5 private string GetFontStack()
6 {
7 return "font-family:initial,Arial,Helvetica Neue,Helvetica,sans-serif;";
8 }
9
10 private string GetTableReset()
11 {
12 return "border:0;margin:0;outline:0;padding:0;";
13 }
14
15 public Dynamicweb.Frontend.ColorViewModel GetMutedColor(string hex, int percent, double threshold = 0.5)
16 {
17 /// <summary>
18 /// Return a color in either lighter or darker contrast based on the original color luminance.
19 /// </summary>
20 /// <param name="percent">The percent (1-100) to darken or light the color with - higher percentage will give higher contrast</param>
21 /// <param name="threshold">The luminance threshold (0-1). Default is 0.5. 0 is black, 1 is white. Luminance threshold is used to decide wether the returned contrast color should be darker or lighter than the base color</param>
22 /// <returns>A new color viewmodel with the contrasted color in either darker or lighter luminance compared to base color</returns>
23 ///
24 if (threshold > 1)
25 threshold = 1;
26 if (threshold < 0)
27 threshold = 0;
28
29 var color = Dynamicweb.Imaging.Colors.Color.FromHex(hex);
30 var luminance = (0.2126 * color.BaseColor.R) + (0.7152 * color.BaseColor.G) + (0.0722 * color.BaseColor.B);
31 /// == luminance = 0 is black, luminance = 1 is white == //
32 luminance = color.Brightness / 255;
33 if (luminance < threshold)
34 {
35 return new Dynamicweb.Frontend.ColorViewModel() { Hex = color.Lighten(percent).ToHex() };
36 }
37 else
38 {
39 return new Dynamicweb.Frontend.ColorViewModel() { Hex = color.Darken(percent).ToHex() };
40 }
41 }
42 }
43
44 @{
45 string blockType = "productcatalog_block";
46
47 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageID);
48 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
49 var blockId = Model.ID;
50 var block = Model.Item;
51
52 var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
53 var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
54 var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
55
56 var rowId = Pageview.CurrentParagraph.GridRowId;
57 var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
58 var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
59 var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
60 var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
61 var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
62
63 var blockThemeId = block.GetRawValueString("Theme");
64 var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
65 var blockTheme = blockThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph)?.Item : rowTheme is object ? rowTheme : emailContentTheme;
66
67 string backgroundColor = blockTheme != null ? "background-color: " + blockTheme.GetString("BackgroundColor") + ";" : string.Empty;
68 string foregroundColor = blockTheme != null ? "color:" + blockTheme.GetString("ForegroundColor", "inherit") + ";" : string.Empty;
69
70 string title = block.GetString("Title", string.Empty);
71 int padding = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Padding", "0"));
72 int cellSpacing = 8;
73 string align = block.GetRawValueString("Align", "left");
74 string text = block.GetString("Text", string.Empty);
75 var layoutColumns = Dynamicweb.Core.Converter.ToInt32(block.GetRawValueString("Layout", "2"));
76
77 ProductListViewModel selectedProducts = block?.GetValue("Products") as ProductListViewModel;
78 IList<ProductViewModel> products = selectedProducts?.Products;
79 }
80
81 <table id="@blockId" class="@blockType" align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;@GetTableReset()color:inherit;width:100%;@(backgroundColor)">
82 <tbody>
83 <tr style="@GetTableReset()">
84 <td style="@GetTableReset()padding:@(padding)px">
85 <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;@GetTableReset()color:inherit;width:100%;">
86 <tbody>
87 @if (products is object && products.Any())
88 {
89 @:<tr style="@GetTableReset()">
90
91 int index = 1;
92 int totalProducts = products.Count();
93 foreach (var product in products)
94 {
95 <td valign="top" style="@GetTableReset()@GetFontStack()">
96 @{ @RenderProduct(product, blockTheme, align) }
97 </td>
98
99 if (index % layoutColumns == 0 && !(index == totalProducts))
100 {
101 @:</tr>
102 @:<tr style="@GetTableReset()">
103 @:<td style="@GetTableReset()" colspan="100%" height="@(cellSpacing * 4)"> </td>
104 @:</tr>
105 @:<tr style="@GetTableReset()">
106 }
107 else
108 {
109 if(!(index == totalProducts))
110 {
111 @:<td width="@(cellSpacing)" style="@GetTableReset()"> </td>
112 }
113 }
114
115 index++;
116 }
117 @:</tr>
118 }
119 else
120 {
121 if (Pageview.IsVisualEditorMode)
122 {
123 <tr style="@GetTableReset()@GetFontStack()">
124 <td style="@(foregroundColor)">@Translate("No products selected")</td>
125 </tr>
126 }
127 }
128 </tbody>
129
130 </table>
131 <!--[if mso]><br/><![endif]-->
132 </td>
133 </tr>
134
135 </tbody>
136 </table>
137
138 @helper RenderImage(ProductViewModel product, Dynamicweb.Frontend.ItemViewModel theme)
139 {
140 int layout = Dynamicweb.Core.Converter.ToInt32(Model.Item.GetRawValueString("Layout", "2"));
141 int padding = Convert.ToInt32(Model.Item.GetRawValueString("Padding", "0"));
142 var imageRatio = Model.Item.GetRawValueString("ImageAspectRatio", "4-3").ToLower();
143
144 var parms = new Dictionary<string, object>();
145 parms.Add("alt", product.Name);
146 parms.Add("columns", layout);
147 parms.Add("gridColumns", Model.GridRowColumnCount);
148 parms.Add("nested", Model.GridRowColumnCount > 1);
149 parms.Add("padding", (padding * 2) + (8 * (layout - 1)));
150 parms.Add("imageRatio", imageRatio);
151
152 if(product.DefaultImage is object)
153 {
154 @RenderPartial("Swift_Email/Components/Image.cshtml", new Dynamicweb.Frontend.FileViewModel() {Name = product.Name, Path = product.DefaultImage.Value }, parms);
155 }
156 }
157
158 @helper RenderProduct(ProductViewModel product, Dynamicweb.Frontend.ItemViewModel theme, string align)
159 {
160 var backgroundColor = theme?.GetColor("BackgroundColor");
161 var foregroundColor = theme?.GetColor("ForegroundColor");
162 var borderColor = theme?.GetColor("BorderColor");
163
164 string link = product.GetProductLink(GetPageIdByNavigationTag("Shop"), false);
165
166 var uri = Dynamicweb.Context.Current.Request.Url;
167 var hostname = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
168
169 bool hideProductPrice = Model.Item?.GetBoolean("HideProductPrice") ?? false;
170 bool hideProductNumber = Model.Item?.GetBoolean("HideProductNumber") ?? false;
171
172 <table style="border-collapse:collapse;table-layout:fixed;@GetTableReset()" cellpadding="0" cellspacing="0" width="100%" role="presentation">
173 <tbody>
174 <tr style="@GetTableReset()">
175 <td style="@GetTableReset()">
176
177 <div align="center" style="font-size:2px;">
178 <a style="text-decoration:none;" href="@link" target="_blank">
179 @{ @RenderImage(product, theme) }
180 </a>
181 </div>
182
183 <table style="border-collapse:collapse;table-layout:fixed;@GetTableReset()" cellpadding="0" cellspacing="0" width="100%" role="presentation">
184 <tbody>
185 <tr style="@GetTableReset()">
186 <td style="@GetTableReset()padding-top:8px;text-align:@align;line-height:18px;font-size:13px;text-decoration:none;color:@foregroundColor;">
187 <a style="text-decoration:none;color:@foregroundColor;@GetTableReset()@GetFontStack()" href="@link" target="_blank">
188 @product.Name
189 </a>
190 </td>
191 </tr>
192
193 @if (!hideProductNumber)
194 {
195 <tr>
196 <td style="@GetTableReset()@GetFontStack()padding-top:8px;line-height:18px;font-size:11px;color:@(GetMutedColor(foregroundColor.Hex, 20));">
197 @product.Number
198 </td>
199 </tr>
200 }
201
202 @if (!hideProductPrice)
203 {
204 <tr>
205 <td style="@GetTableReset()@GetFontStack()padding-top:8px;line-height:13px;font-size:13px;break-inside:avoid;word-break:keep-all;white-space:nowrap;color:@(foregroundColor);">
206 @product.Price.PriceFormatted
207
208 @if (product.Discount.Price > 0)
209 {
210 <span style="line-height:13px;font-size:13px;text-decoration:line-through;break-inside:avoid;word-break:keep-all;white-space:nowrap;color:@(GetMutedColor(foregroundColor.Hex, 20));">@product.PriceBeforeDiscount.PriceFormatted</span>
211 }
212 </td>
213 </tr>
214 }
215 <tr><td height="24" style="padding-top:24px;"></td></tr>
216 </tbody>
217 </table>
218
219 </td>
220 </tr>
221
222 </tbody>
223 </table>
224 }
225
|
|
|