Repository navigation
Expand file tree
/
Copy pathCommonController.cs
More file actions
1119 lines (958 loc) · 41.6 KB
/
Copy pathCommonController.cs
File metadata and controls
1119 lines (958 loc) · 41.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using SmartStore.Core.Data;
using SmartStore.Core.Domain;
using SmartStore.Core.Domain.Blogs;
using SmartStore.Core.Domain.Catalog;
using SmartStore.Core.Domain.Common;
using SmartStore.Core.Domain.Customers;
using SmartStore.Core.Domain.Discounts;
using SmartStore.Core.Domain.Forums;
using SmartStore.Core.Domain.Localization;
using SmartStore.Core.Domain.Media;
using SmartStore.Core.Domain.Messages;
using SmartStore.Core.Domain.News;
using SmartStore.Core.Domain.Orders;
using SmartStore.Core.Domain.Security;
using SmartStore.Core.Domain.Seo;
using SmartStore.Core.Domain.Tax;
using SmartStore.Core.Domain.Themes;
using SmartStore.Core.Infrastructure;
using SmartStore.Core.Localization;
using SmartStore.Core.Themes;
using SmartStore.Services;
using SmartStore.Services.Catalog;
using SmartStore.Services.Common;
using SmartStore.Services.Customers;
using SmartStore.Services.Directory;
using SmartStore.Services.Forums;
using SmartStore.Services.Localization;
using SmartStore.Services.Media;
using SmartStore.Services.Orders;
using SmartStore.Services.Security;
using SmartStore.Services.Topics;
using SmartStore.Web.Framework;
using SmartStore.Web.Framework.Controllers;
using SmartStore.Web.Framework.Localization;
using SmartStore.Web.Framework.Pdf;
using SmartStore.Web.Framework.Theming;
using SmartStore.Web.Framework.UI;
using SmartStore.Web.Infrastructure.Cache;
using SmartStore.Web.Models.Common;
using SmartStore.Services.Seo;
using SmartStore.Core.Search;
namespace SmartStore.Web.Controllers
{
public partial class CommonController : PublicControllerBase
{
private readonly static string[] s_hints = new string[] { "Shopsystem", "Onlineshop Software", "Shopsoftware", "E-Commerce Solution" };
private readonly ICommonServices _services;
private readonly ITopicService _topicService;
private readonly Lazy<ILanguageService> _languageService;
private readonly Lazy<ICurrencyService> _currencyService;
private readonly IThemeContext _themeContext;
private readonly Lazy<IThemeRegistry> _themeRegistry;
private readonly Lazy<IForumService> _forumservice;
private readonly Lazy<IGenericAttributeService> _genericAttributeService;
private readonly Lazy<ICompareProductsService> _compareProductsService;
private readonly Lazy<IUrlRecordService> _urlRecordService;
private readonly StoreInformationSettings _storeInfoSettings;
private readonly CustomerSettings _customerSettings;
private readonly TaxSettings _taxSettings;
private readonly CatalogSettings _catalogSettings;
private readonly ShoppingCartSettings _shoppingCartSettings;
private readonly ThemeSettings _themeSettings;
private readonly CommonSettings _commonSettings;
private readonly NewsSettings _newsSettings;
private readonly BlogSettings _blogSettings;
private readonly ForumSettings _forumSettings;
private readonly LocalizationSettings _localizationSettings;
private readonly Lazy<SecuritySettings> _securitySettings;
private readonly Lazy<SocialSettings> _socialSettings;
private readonly Lazy<MediaSettings> _mediaSettings;
private readonly Lazy<SearchSettings> _searchSettings;
private readonly IOrderTotalCalculationService _orderTotalCalculationService;
private readonly IPriceFormatter _priceFormatter;
private readonly IPageAssetsBuilder _pageAssetsBuilder;
private readonly Lazy<IPictureService> _pictureService;
private readonly Lazy<IManufacturerService> _manufacturerService;
private readonly Lazy<ICategoryService> _categoryService;
private readonly Lazy<IProductService> _productService;
private readonly Lazy<IShoppingCartService> _shoppingCartService;
public CommonController(
ICommonServices services,
ITopicService topicService,
Lazy<ILanguageService> languageService,
Lazy<ICurrencyService> currencyService,
IThemeContext themeContext,
Lazy<IThemeRegistry> themeRegistry,
Lazy<IForumService> forumService,
Lazy<IGenericAttributeService> genericAttributeService,
Lazy<IMobileDeviceHelper> mobileDeviceHelper,
Lazy<ICompareProductsService> compareProductsService,
Lazy<IUrlRecordService> urlRecordService,
StoreInformationSettings storeInfoSettings,
CustomerSettings customerSettings,
TaxSettings taxSettings,
CatalogSettings catalogSettings,
ShoppingCartSettings shoppingCartSettings,
EmailAccountSettings emailAccountSettings,
CommonSettings commonSettings,
NewsSettings newsSettings,
BlogSettings blogSettings,
ForumSettings forumSettings,
LocalizationSettings localizationSettings,
Lazy<SecuritySettings> securitySettings,
Lazy<SocialSettings> socialSettings,
Lazy<MediaSettings> mediaSettings,
Lazy<SearchSettings> searchSettings,
IOrderTotalCalculationService orderTotalCalculationService,
IPriceFormatter priceFormatter,
ThemeSettings themeSettings,
IPageAssetsBuilder pageAssetsBuilder,
Lazy<IPictureService> pictureService,
Lazy<IManufacturerService> manufacturerService,
Lazy<ICategoryService> categoryService,
Lazy<IProductService> productService,
Lazy<IShoppingCartService> shoppingCartService)
{
this._services = services;
this._topicService = topicService;
this._languageService = languageService;
this._currencyService = currencyService;
this._themeContext = themeContext;
this._themeRegistry = themeRegistry;
this._forumservice = forumService;
this._genericAttributeService = genericAttributeService;
this._compareProductsService = compareProductsService;
this._urlRecordService = urlRecordService;
this._storeInfoSettings = storeInfoSettings;
this._customerSettings = customerSettings;
this._taxSettings = taxSettings;
this._catalogSettings = catalogSettings;
this._shoppingCartSettings = shoppingCartSettings;
this._commonSettings = commonSettings;
this._newsSettings = newsSettings;
this._blogSettings = blogSettings;
this._forumSettings = forumSettings;
this._localizationSettings = localizationSettings;
this._securitySettings = securitySettings;
this._socialSettings = socialSettings;
this._mediaSettings = mediaSettings;
this._searchSettings = searchSettings;
this._orderTotalCalculationService = orderTotalCalculationService;
this._priceFormatter = priceFormatter;
this._themeSettings = themeSettings;
this._pageAssetsBuilder = pageAssetsBuilder;
this._pictureService = pictureService;
this._manufacturerService = manufacturerService;
this._categoryService = categoryService;
this._productService = productService;
this._shoppingCartService = shoppingCartService;
}
#region Utilities
[NonAction]
protected LanguageSelectorModel PrepareLanguageSelectorModel()
{
var availableLanguages = _services.Cache.Get(string.Format(ModelCacheEventConsumer.AVAILABLE_LANGUAGES_MODEL_KEY, _services.StoreContext.CurrentStore.Id), () =>
{
var result = _languageService.Value
.GetAllLanguages(storeId: _services.StoreContext.CurrentStore.Id)
.Select(x => new LanguageModel
{
Id = x.Id,
Name = x.Name,
NativeName = LocalizationHelper.GetLanguageNativeName(x.LanguageCulture) ?? x.Name,
ISOCode = x.LanguageCulture,
SeoCode = x.UniqueSeoCode,
FlagImageFileName = x.FlagImageFileName
})
.ToList();
return result;
});
var workingLanguage = _services.WorkContext.WorkingLanguage;
var model = new LanguageSelectorModel
{
CurrentLanguageId = workingLanguage.Id,
AvailableLanguages = availableLanguages,
UseImages = _localizationSettings.UseImagesForLanguageSelection
};
string defaultSeoCode = _languageService.Value.GetDefaultLanguageSeoCode();
foreach (var lang in model.AvailableLanguages)
{
//var helper = new LocalizedUrlHelper(HttpContext.Request, true);
var helper = CreateUrlHelperForLanguageSelector(lang, workingLanguage.Id);
if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
{
if (lang.SeoCode == defaultSeoCode && (int)(_localizationSettings.DefaultLanguageRedirectBehaviour) > 0)
{
helper.StripSeoCode();
}
else
{
helper.PrependSeoCode(lang.SeoCode, true);
}
}
model.ReturnUrls[lang.SeoCode] = helper.GetAbsolutePath();
}
return model;
}
private LocalizedUrlHelper CreateUrlHelperForLanguageSelector(LanguageModel model, int currentLanguageId)
{
if (currentLanguageId != model.Id)
{
var routeValues = this.Request.RequestContext.RouteData.Values;
var controller = routeValues["controller"].ToString();
object val;
if (!routeValues.TryGetValue(controller + "id", out val))
{
controller = routeValues["action"].ToString();
routeValues.TryGetValue(controller + "id", out val);
}
int entityId = 0;
if (val != null)
{
entityId = val.Convert<int>();
}
if (entityId > 0)
{
var activeSlug = _urlRecordService.Value.GetActiveSlug(entityId, controller, model.Id);
if (activeSlug.HasValue())
{
var helper = new LocalizedUrlHelper(Request.ApplicationPath, activeSlug, false);
return helper;
}
}
}
return new LocalizedUrlHelper(HttpContext.Request, true);
}
[NonAction]
protected CurrencySelectorModel PrepareCurrencySelectorModel()
{
var availableCurrencies = _services.Cache.Get(string.Format(ModelCacheEventConsumer.AVAILABLE_CURRENCIES_MODEL_KEY, _services.WorkContext.WorkingLanguage.Id, _services.StoreContext.CurrentStore.Id), () =>
{
var result = _currencyService.Value
.GetAllCurrencies(storeId: _services.StoreContext.CurrentStore.Id)
.Select(x => new CurrencyModel()
{
Id = x.Id,
Name = x.GetLocalized(y => y.Name),
ISOCode = x.CurrencyCode,
Symbol = LocalizationHelper.GetCurrencySymbol(x.DisplayLocale) ?? x.CurrencyCode
})
.ToList();
return result;
});
var model = new CurrencySelectorModel()
{
CurrentCurrencyId = _services.WorkContext.WorkingCurrency.Id,
AvailableCurrencies = availableCurrencies
};
return model;
}
[NonAction]
protected TaxTypeSelectorModel PrepareTaxTypeSelectorModel()
{
var model = new TaxTypeSelectorModel()
{
Enabled = _taxSettings.AllowCustomersToSelectTaxDisplayType,
CurrentTaxType = _services.WorkContext.TaxDisplayType
};
return model;
}
[NonAction]
protected int GetUnreadPrivateMessages()
{
var result = 0;
var customer = _services.WorkContext.CurrentCustomer;
if (_forumSettings.AllowPrivateMessages && !customer.IsGuest())
{
var privateMessages = _forumservice.Value.GetAllPrivateMessages(_services.StoreContext.CurrentStore.Id, 0, customer.Id, false, null, false, string.Empty, 0, 1);
if (privateMessages.TotalCount > 0)
{
result = privateMessages.TotalCount;
}
}
return result;
}
#endregion
#region Methods
[ChildActionOnly]
public ActionResult LanguageSelector()
{
var model = PrepareLanguageSelectorModel();
if (model.AvailableLanguages.Count < 2)
return Content("");
// register all available languages as <link hreflang="..." ... />
if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
{
var host = _services.WebHelper.GetStoreLocation();
foreach (var lang in model.AvailableLanguages)
{
_pageAssetsBuilder.AddLinkPart("alternate", host + model.ReturnUrls[lang.SeoCode].TrimStart('/'), hreflang: lang.SeoCode);
}
}
return PartialView(model);
}
[ChildActionOnly]
public ActionResult Logo()
{
var model = _services.Cache.Get(ModelCacheEventConsumer.SHOPHEADER_MODEL_KEY.FormatWith(_services.StoreContext.CurrentStore.Id), () =>
{
var pictureService = _pictureService.Value;
int logoPictureId = _services.StoreContext.CurrentStore.LogoPictureId;
Picture picture = null;
if (logoPictureId > 0)
{
picture = pictureService.GetPictureById(logoPictureId);
}
string logoUrl = null;
var logoSize = new Size();
if (picture != null)
{
logoUrl = pictureService.GetPictureUrl(picture);
logoSize = pictureService.GetPictureSize(picture);
}
return new ShopHeaderModel()
{
LogoUploaded = picture != null && logoUrl.HasValue(),
LogoUrl = logoUrl,
LogoWidth = logoSize.Width,
LogoHeight = logoSize.Height,
LogoTitle = _services.StoreContext.CurrentStore.Name
};
});
return PartialView(model);
}
public ActionResult SetLanguage(int langid, string returnUrl = "")
{
var language = _languageService.Value.GetLanguageById(langid);
if (language != null && language.Published)
{
_services.WorkContext.WorkingLanguage = language;
}
if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
{
var helper = new LocalizedUrlHelper(HttpContext.Request.ApplicationPath, returnUrl, true);
helper.PrependSeoCode(_services.WorkContext.WorkingLanguage.UniqueSeoCode, true);
returnUrl = helper.GetAbsolutePath();
}
return RedirectToReferrer(returnUrl);
}
[ChildActionOnly]
public ActionResult CurrencySelector()
{
var model = PrepareCurrencySelectorModel();
if (model.AvailableCurrencies.Count < 2)
return Content("");
return PartialView(model);
}
public ActionResult CurrencySelected(int customerCurrency, string returnUrl = "")
{
var currency = _currencyService.Value.GetCurrencyById(customerCurrency);
if (currency != null)
{
_services.WorkContext.WorkingCurrency = currency;
}
return RedirectToReferrer(returnUrl);
}
[ChildActionOnly]
public ActionResult TaxTypeSelector()
{
var model = PrepareTaxTypeSelectorModel();
return PartialView(model);
}
public ActionResult TaxTypeSelected(int customerTaxType, string returnUrl = "")
{
var taxDisplayType = (TaxDisplayType)Enum.ToObject(typeof(TaxDisplayType), customerTaxType);
_services.WorkContext.TaxDisplayType = taxDisplayType;
return RedirectToReferrer(returnUrl);
}
public ActionResult Settings()
{
return View();
}
// footer
[ChildActionOnly]
public ActionResult JavaScriptDisabledWarning()
{
if (!_commonSettings.DisplayJavaScriptDisabledWarning)
return Content("");
return PartialView();
}
// header links
[ChildActionOnly]
public ActionResult HeaderLinks()
{
var customer = _services.WorkContext.CurrentCustomer;
var unreadMessageCount = GetUnreadPrivateMessages();
var unreadMessage = string.Empty;
var alertMessage = string.Empty;
if (unreadMessageCount > 0)
{
unreadMessage = T("PrivateMessages.TotalUnread", unreadMessageCount);
//notifications here
var notifiedAboutNewPrivateMessagesAttributeKey = string.Format(SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, _services.StoreContext.CurrentStore.Id);
if (_forumSettings.ShowAlertForPM &&
!customer.GetAttribute<bool>(SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, _services.StoreContext.CurrentStore.Id))
{
_genericAttributeService.Value.SaveAttribute(customer, SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, true, _services.StoreContext.CurrentStore.Id);
alertMessage = T("PrivateMessages.YouHaveUnreadPM", unreadMessageCount);
}
}
var model = new HeaderLinksModel
{
IsAuthenticated = customer.IsRegistered(),
CustomerEmailUsername = customer.IsRegistered() ? (_customerSettings.UsernamesEnabled ? customer.Username : customer.Email) : "",
IsCustomerImpersonated = _services.WorkContext.OriginalCustomerIfImpersonated != null,
DisplayAdminLink = _services.Permissions.Authorize(StandardPermissionProvider.AccessAdminPanel),
ShoppingCartEnabled = _services.Permissions.Authorize(StandardPermissionProvider.EnableShoppingCart),
ShoppingCartItems = customer.CountProductsInCart(ShoppingCartType.ShoppingCart, _services.StoreContext.CurrentStore.Id),
WishlistEnabled = _services.Permissions.Authorize(StandardPermissionProvider.EnableWishlist),
WishlistItems = customer.CountProductsInCart(ShoppingCartType.Wishlist, _services.StoreContext.CurrentStore.Id),
AllowPrivateMessages = _forumSettings.AllowPrivateMessages,
UnreadPrivateMessages = unreadMessage,
AlertMessage = alertMessage,
};
return PartialView(model);
}
[ChildActionOnly]
public ActionResult ShopBar()
{
var customer = _services.WorkContext.CurrentCustomer;
var isAdmin = customer.IsAdmin();
var isRegistered = isAdmin || customer.IsRegistered();
if (_storeInfoSettings.StoreClosed)
{
if (!isAdmin || !_storeInfoSettings.StoreClosedAllowForAdmins)
{
return Content("");
}
}
var unreadMessageCount = GetUnreadPrivateMessages();
var unreadMessage = string.Empty;
var alertMessage = string.Empty;
if (unreadMessageCount > 0)
{
unreadMessage = T("PrivateMessages.TotalUnread");
//notifications here
if (_forumSettings.ShowAlertForPM &&
!customer.GetAttribute<bool>(SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, _services.StoreContext.CurrentStore.Id))
{
_genericAttributeService.Value.SaveAttribute(customer, SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, true, _services.StoreContext.CurrentStore.Id);
alertMessage = T("PrivateMessages.YouHaveUnreadPM", unreadMessageCount);
}
}
var cart = _services.WorkContext.CurrentCustomer.GetCartItems(ShoppingCartType.ShoppingCart, _services.StoreContext.CurrentStore.Id);
decimal subtotal = _shoppingCartService.Value.GetCurrentCartSubTotal(cart);
var model = new ShopBarModel
{
IsAuthenticated = isRegistered,
CustomerEmailUsername = isRegistered ? (_customerSettings.UsernamesEnabled ? customer.Username : customer.Email) : "",
IsCustomerImpersonated = _services.WorkContext.OriginalCustomerIfImpersonated != null,
DisplayAdminLink = _services.Permissions.Authorize(StandardPermissionProvider.AccessAdminPanel),
ShoppingCartEnabled = _services.Permissions.Authorize(StandardPermissionProvider.EnableShoppingCart) && _shoppingCartSettings.MiniShoppingCartEnabled,
ShoppingCartAmount = _priceFormatter.FormatPrice(subtotal, true, false),
WishlistEnabled = _services.Permissions.Authorize(StandardPermissionProvider.EnableWishlist),
AllowPrivateMessages = _forumSettings.AllowPrivateMessages,
UnreadPrivateMessages = unreadMessage,
AlertMessage = alertMessage,
CompareProductsEnabled = _catalogSettings.CompareProductsEnabled
};
if (model.ShoppingCartEnabled || model.WishlistEnabled)
{
if (model.ShoppingCartEnabled)
model.ShoppingCartItems = cart.GetTotalProducts();
if (model.WishlistEnabled)
model.WishlistItems = customer.CountProductsInCart(ShoppingCartType.Wishlist, _services.StoreContext.CurrentStore.Id);
}
if (_catalogSettings.CompareProductsEnabled)
{
model.CompareItems = _compareProductsService.Value.GetComparedProductsCount();
}
return PartialView(model);
}
[ChildActionOnly]
public ActionResult Footer()
{
var store = _services.StoreContext.CurrentStore;
var allTopics = _topicService.GetAllTopics(store.Id);
var taxDisplayType = _services.WorkContext.GetTaxDisplayTypeFor(_services.WorkContext.CurrentCustomer, store.Id);
var taxInfo = T(taxDisplayType == TaxDisplayType.IncludingTax ? "Tax.InclVAT" : "Tax.ExclVAT");
var availableStoreThemes = !_themeSettings.AllowCustomerToSelectTheme ? new List<StoreThemeModel>() : _themeRegistry.Value.GetThemeManifests()
.Select(x =>
{
return new StoreThemeModel
{
Name = x.ThemeName,
Title = x.ThemeTitle
};
})
.ToList();
var model = new FooterModel
{
StoreName = store.Name,
ShowLegalInfo = _taxSettings.ShowLegalHintsInFooter,
ShowThemeSelector = availableStoreThemes.Count > 1,
BlogEnabled = _blogSettings.Enabled,
ForumEnabled = _forumSettings.ForumsEnabled,
HideNewsletterBlock = _customerSettings.HideNewsletterBlock,
};
model.TopicPageUrls = allTopics
.Where(x => !x.RenderAsWidget)
.GroupBy(x => x.SystemName)
.ToDictionary(x => x.Key.EmptyNull().ToLower(), x =>
{
if (x.Key.IsCaseInsensitiveEqual("contactus"))
return Url.RouteUrl("ContactUs");
return Url.RouteUrl("Topic", new { SystemName = x.Key });
});
if (model.TopicPageUrls.ContainsKey("shippinginfo"))
{
model.LegalInfo = T("Tax.LegalInfoFooter", taxInfo, model.TopicPageUrls["shippinginfo"]);
}
else
{
model.LegalInfo = T("Tax.LegalInfoFooter2", taxInfo);
}
var hint = _services.Settings.GetSettingByKey<string>("Rnd_SmCopyrightHint", string.Empty, store.Id);
if (hint.IsEmpty())
{
hint = s_hints[new Random().Next(s_hints.Length)];
_services.Settings.SetSetting<string>("Rnd_SmCopyrightHint", hint, store.Id);
}
model.ShowSocialLinks = _socialSettings.Value.ShowSocialLinksInFooter;
model.FacebookLink = _socialSettings.Value.FacebookLink;
model.GooglePlusLink = _socialSettings.Value.GooglePlusLink;
model.TwitterLink = _socialSettings.Value.TwitterLink;
model.PinterestLink = _socialSettings.Value.PinterestLink;
model.YoutubeLink = _socialSettings.Value.YoutubeLink;
model.SmartStoreHint = "<a href='http://www.smartstore.com/net' class='sm-hint' target='_blank'><strong>{0}</strong></a> by SmartStore AG © {1}"
.FormatCurrent(hint, DateTime.Now.Year);
return PartialView(model);
}
[ChildActionOnly]
public ActionResult Menu()
{
var store = _services.StoreContext.CurrentStore;
var customer = _services.WorkContext.CurrentCustomer;
var model = new MenuModel
{
RecentlyAddedProductsEnabled = _catalogSettings.RecentlyAddedProductsEnabled,
NewsEnabled = _newsSettings.Enabled,
BlogEnabled = _blogSettings.Enabled,
ForumEnabled = _forumSettings.ForumsEnabled,
AllowPrivateMessages = _forumSettings.AllowPrivateMessages && customer.IsRegistered(),
UnreadPrivateMessages = GetUnreadPrivateMessages(),
CustomerEmailUsername = customer.IsRegistered() ? (_customerSettings.UsernamesEnabled ? customer.Username : customer.Email) : "",
IsCustomerImpersonated = _services.WorkContext.OriginalCustomerIfImpersonated != null,
IsAuthenticated = customer.IsRegistered(),
DisplayAdminLink = _services.Permissions.Authorize(StandardPermissionProvider.AccessAdminPanel),
HasContactUsPage = (_topicService.GetTopicBySystemName("ContactUs", store.Id) != null)
};
model.DisplayLoginLink = _storeInfoSettings.StoreClosed && !model.DisplayAdminLink;
return PartialView(model);
}
[ChildActionOnly]
public ActionResult ServiceMenu()
{
var store = _services.StoreContext.CurrentStore;
var allTopics = _topicService.GetAllTopics(store.Id);
var model = new InfoBlockModel
{
RecentlyAddedProductsEnabled = _catalogSettings.RecentlyAddedProductsEnabled,
RecentlyViewedProductsEnabled = _catalogSettings.RecentlyViewedProductsEnabled,
CompareProductsEnabled = _catalogSettings.CompareProductsEnabled,
BlogEnabled = _blogSettings.Enabled,
SitemapEnabled = _commonSettings.SitemapEnabled,
ForumEnabled = _forumSettings.ForumsEnabled,
AllowPrivateMessages = _forumSettings.AllowPrivateMessages,
};
model.TopicPageUrls = allTopics
.Where(x => !x.RenderAsWidget)
.GroupBy(x => x.SystemName)
.ToDictionary(x => x.Key.EmptyNull().ToLower(), x =>
{
if (x.Key.IsCaseInsensitiveEqual("contactus"))
return Url.RouteUrl("ContactUs");
return Url.RouteUrl("Topic", new { SystemName = x.Key });
});
return PartialView(model);
}
[ChildActionOnly]
public ActionResult StoreThemeSelector()
{
if (!_themeSettings.AllowCustomerToSelectTheme)
return Content("");
var model = new StoreThemeSelectorModel();
var currentTheme = _themeRegistry.Value.GetThemeManifest(_themeContext.WorkingThemeName);
model.CurrentStoreTheme = new StoreThemeModel()
{
Name = currentTheme.ThemeName,
Title = currentTheme.ThemeTitle
};
model.AvailableStoreThemes = _themeRegistry.Value
.GetThemeManifests()
.Select(x =>
{
return new StoreThemeModel
{
Name = x.ThemeName,
Title = x.ThemeTitle
};
})
.ToList();
return PartialView(model);
}
public ActionResult ChangeTheme(string themeName, string returnUrl = null)
{
if (!_themeSettings.AllowCustomerToSelectTheme || (themeName.HasValue() && !_themeRegistry.Value.ThemeManifestExists(themeName)))
{
return HttpNotFound();
}
_themeContext.WorkingThemeName = themeName;
if (HttpContext.Request.IsAjaxRequest())
{
return Json(new { Success = true });
}
return RedirectToReferrer(returnUrl);
}
[ChildActionOnly]
[OutputCache(Duration=3600, VaryByCustom="Theme_Store")]
public ActionResult Favicon()
{
var icons = new string[]
{
"favicon-{0}.ico".FormatInvariant(_services.StoreContext.CurrentStore.Id),
"favicon.ico"
};
string virtualPath = null;
foreach (var icon in icons)
{
virtualPath = Url.ThemeAwareContent(icon);
if (virtualPath.HasValue())
{
break;
}
}
if (virtualPath.IsEmpty())
{
return Content("");
}
var model = new FaviconModel()
{
Uploaded = true,
FaviconUrl = virtualPath
};
return PartialView(model);
}
public ActionResult RobotsTextFile()
{
var disallowPaths = new List<string>()
{
"/bin/",
"/Content/files/",
"/Content/files/ExportImport/",
"/Exchange/",
"/Country/GetStatesByCountryId",
"/Install",
"/Product/SetReviewHelpfulness",
};
var localizableDisallowPaths = new List<string>()
{
"/Boards/ForumWatch",
"/Boards/PostEdit",
"/Boards/PostDelete",
"/Boards/PostCreate",
"/Boards/TopicEdit",
"/Boards/TopicDelete",
"/Boards/TopicCreate",
"/Boards/TopicMove",
"/Boards/TopicWatch",
"/Cart",
"/Checkout",
"/Product/ClearCompareList",
"/CompareProducts",
"/Customer/Avatar",
"/Customer/Activation",
"/Customer/Addresses",
"/Customer/BackInStockSubscriptions",
"/Customer/ChangePassword",
"/Customer/CheckUsernameAvailability",
"/Customer/DownloadableProducts",
"/Customer/ForumSubscriptions",
"/Customer/DeleteForumSubscriptions",
"/Customer/Info",
"/Customer/Orders",
"/Customer/ReturnRequests",
"/Customer/RewardPoints",
"/PrivateMessages",
"/Newsletter/SubscriptionActivation",
"/Order",
"/PasswordRecovery",
"/Poll/Vote",
"/ReturnRequest",
"/Newsletter/Subscribe",
"/Topic/Authenticate",
"/Wishlist",
"/Product/AskQuestion",
"/Product/EmailAFriend",
"/Search",
"/Config",
"/Settings",
"/Login",
"/Register"
};
const string newLine = "\r\n"; //Environment.NewLine
var sb = new StringBuilder();
sb.Append("User-agent: *");
sb.Append(newLine);
sb.AppendFormat("Sitemap: {0}", Url.RouteUrl("SitemapSEO", (object)null, _securitySettings.Value.ForceSslForAllPages ? "https" : "http"));
sb.AppendLine();
var disallows = disallowPaths.Concat(localizableDisallowPaths);
if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
{
// URLs are localizable. Append SEO code
foreach (var language in _languageService.Value.GetAllLanguages(storeId: _services.StoreContext.CurrentStore.Id))
{
disallows = disallows.Concat(localizableDisallowPaths.Select(x => "/{0}{1}".FormatInvariant(language.UniqueSeoCode, x)));
}
}
var seoSettings = EngineContext.Current.Resolve<SeoSettings>();
// append extra disallows
disallows = disallows.Concat(seoSettings.ExtraRobotsDisallows.Select(x => x.Trim()));
// Append all lowercase variants (at least Google is case sensitive)
disallows = disallows.Concat(GetLowerCaseVariants(disallows));
foreach (var disallow in disallows)
{
sb.AppendFormat("Disallow: {0}", disallow);
sb.Append(newLine);
}
Response.ContentType = "text/plain";
Response.Write(sb.ToString());
return null;
}
private IEnumerable<string> GetLowerCaseVariants(IEnumerable<string> disallows)
{
var other = new List<string>();
foreach (var item in disallows)
{
var lower = item.ToLower();
if (lower != item)
{
other.Add(lower);
}
}
return other;
}
public ActionResult GenericUrl()
{
// seems that no entity was found
return HttpNotFound();
}
[ChildActionOnly]
public ActionResult AccountDropdown()
{
var customer = _services.WorkContext.CurrentCustomer;
var unreadMessageCount = GetUnreadPrivateMessages();
var unreadMessage = string.Empty;
var alertMessage = string.Empty;
if (unreadMessageCount > 0)
{
unreadMessage = unreadMessageCount.ToString();
//notifications here
if (_forumSettings.ShowAlertForPM &&
!customer.GetAttribute<bool>(SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, _services.StoreContext.CurrentStore.Id))
{
_genericAttributeService.Value.SaveAttribute(customer, SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, true, _services.StoreContext.CurrentStore.Id);
alertMessage = T("PrivateMessages.YouHaveUnreadPM", unreadMessageCount);
}
}
var model = new AccountDropdownModel
{
IsAuthenticated = customer.IsRegistered(),
DisplayAdminLink = _services.Permissions.Authorize(StandardPermissionProvider.AccessAdminPanel),
ShoppingCartEnabled = _services.Permissions.Authorize(StandardPermissionProvider.EnableShoppingCart),
ShoppingCartItems = customer.CountProductsInCart(ShoppingCartType.ShoppingCart, _services.StoreContext.CurrentStore.Id),
WishlistEnabled = _services.Permissions.Authorize(StandardPermissionProvider.EnableWishlist),
WishlistItems = customer.CountProductsInCart(ShoppingCartType.Wishlist, _services.StoreContext.CurrentStore.Id),
AllowPrivateMessages = _forumSettings.AllowPrivateMessages,
UnreadPrivateMessages = unreadMessage,
AlertMessage = alertMessage
};
return PartialView(model);
}
[OverrideActionFilters, OverrideAuthorization]
public ActionResult PdfReceiptHeader(PdfHeaderFooterVariables vars, int storeId = 0, bool isPartial = false)
{
var model = PreparePdfReceiptHeaderFooterModel(storeId);
model.Variables = vars;
ViewBag.IsPartial = isPartial;
if (isPartial)
return PartialView(model);
return View(model);
}
[OverrideActionFilters, OverrideAuthorization]
public ActionResult PdfReceiptFooter(PdfHeaderFooterVariables vars, int storeId = 0, bool isPartial = false)
{
var model = PreparePdfReceiptHeaderFooterModel(storeId);
model.Variables = vars;
ViewBag.IsPartial = isPartial;
if (isPartial)
return PartialView(model);
return View(model);
}
protected PdfReceiptHeaderFooterModel PreparePdfReceiptHeaderFooterModel(int storeId)
{
return _services.Cache.Get("PdfReceiptHeaderFooterModel-{0}".FormatInvariant(storeId), () =>
{
var model = new PdfReceiptHeaderFooterModel { StoreId = storeId };
var store = _services.StoreService.GetStoreById(model.StoreId) ?? _services.StoreContext.CurrentStore;
var companyInfoSettings = _services.Settings.LoadSetting<CompanyInformationSettings>(store.Id);
var bankSettings = _services.Settings.LoadSetting<BankConnectionSettings>(store.Id);
var contactSettings = _services.Settings.LoadSetting<ContactDataSettings>(store.Id);
var pdfSettings = _services.Settings.LoadSetting<PdfSettings>(store.Id);
model.StoreName = store.Name;
model.StoreUrl = store.Url;
var logoPicture = _pictureService.Value.GetPictureById(pdfSettings.LogoPictureId);
if (logoPicture == null)
{
logoPicture = _pictureService.Value.GetPictureById(store.LogoPictureId);
}
if (logoPicture != null)
{
model.LogoUrl = _pictureService.Value.GetPictureUrl(logoPicture, showDefaultPicture: false);
}
model.MerchantCompanyInfo = companyInfoSettings;
model.MerchantBankAccount = bankSettings;
model.MerchantContactData = contactSettings;
return model;
}, TimeSpan.FromMinutes(1) /* 1 min. (just for the duration of pdf processing) */);
}
#endregion
#region Entity Picker
public ActionResult EntityPicker(EntityPickerModel model)
{
model.PageSize = 48; // _commonSettings.EntityPickerPageSize;
model.AllString = T("Admin.Common.All");
if (model.Entity.IsCaseInsensitiveEqual("product"))
{
var allCategories = _categoryService.Value.GetAllCategories(showHidden: true);
var mappedCategories = allCategories.ToDictionary(x => x.Id);
model.AvailableCategories = allCategories
.Select(x => new SelectListItem { Text = x.GetCategoryNameWithPrefix(_categoryService.Value, mappedCategories), Value = x.Id.ToString() })
.ToList();
model.AvailableManufacturers = _manufacturerService.Value.GetAllManufacturers(true)
.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() })
.ToList();
model.AvailableStores = _services.StoreService.GetAllStores()
.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() })
.ToList();
model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList();
}
return PartialView(model);
}