Skip to content

Commit a7084d6

Browse files
committed
#1969 Settings for display news and blog comments per stores
1 parent 1e74b7e commit a7084d6

File tree

29 files changed

+306
-52
lines changed

29 files changed

+306
-52
lines changed

src/Libraries/Nop.Core/Domain/Blogs/BlogComment.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Nop.Core.Domain.Customers;
3+
using Nop.Core.Domain.Stores;
34

45
namespace Nop.Core.Domain.Blogs
56
{
@@ -23,6 +24,11 @@ public partial class BlogComment : BaseEntity
2324
/// </summary>
2425
public bool IsApproved { get; set; }
2526

27+
/// <summary>
28+
/// Gets or sets the store identifier
29+
/// </summary>
30+
public int StoreId { get; set; }
31+
2632
/// <summary>
2733
/// Gets or sets the blog post identifier
2834
/// </summary>
@@ -42,5 +48,10 @@ public partial class BlogComment : BaseEntity
4248
/// Gets or sets the blog post
4349
/// </summary>
4450
public virtual BlogPost BlogPost { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets the store
54+
/// </summary>
55+
public virtual Store Store { get; set; }
4556
}
4657
}

src/Libraries/Nop.Core/Domain/Blogs/BlogSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ public class BlogSettings : ISettings
3939
/// Gets or sets a value indicating whether blog comments must be approved
4040
/// </summary>
4141
public bool BlogCommentsMustBeApproved { get; set; }
42+
43+
/// <summary>
44+
/// Gets or sets a value indicating whether blog comments will be filtered per store
45+
/// </summary>
46+
public bool ShowBlogCommentsPerStore { get; set; }
4247
}
4348
}

src/Libraries/Nop.Core/Domain/News/NewsComment.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Nop.Core.Domain.Customers;
3+
using Nop.Core.Domain.Stores;
34

45
namespace Nop.Core.Domain.News
56
{
@@ -33,6 +34,11 @@ public partial class NewsComment : BaseEntity
3334
/// </summary>
3435
public bool IsApproved { get; set; }
3536

37+
/// <summary>
38+
/// Gets or sets the store identifier
39+
/// </summary>
40+
public int StoreId { get; set; }
41+
3642
/// <summary>
3743
/// Gets or sets the date and time of instance creation
3844
/// </summary>
@@ -47,5 +53,10 @@ public partial class NewsComment : BaseEntity
4753
/// Gets or sets the news item
4854
/// </summary>
4955
public virtual NewsItem NewsItem { get; set; }
56+
57+
/// <summary>
58+
/// Gets or sets the store
59+
/// </summary>
60+
public virtual Store Store { get; set; }
5061
}
5162
}

src/Libraries/Nop.Core/Domain/News/NewsSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ public class NewsSettings : ISettings
4444
/// Gets or sets a value indicating whether news comments must be approved
4545
/// </summary>
4646
public bool NewsCommentsMustBeApproved { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets a value indicating whether news comments will be filtered per store
50+
/// </summary>
51+
public bool ShowNewsCommentsPerStore { get; set; }
4752
}
4853
}

src/Libraries/Nop.Data/Mapping/Blogs/BlogCommentMap.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ public partial class BlogCommentMap : NopEntityTypeConfiguration<BlogComment>
77
public BlogCommentMap()
88
{
99
this.ToTable("BlogComment");
10-
this.HasKey(pr => pr.Id);
10+
this.HasKey(comment => comment.Id);
1111

12-
this.HasRequired(bc => bc.BlogPost)
13-
.WithMany(bp => bp.BlogComments)
14-
.HasForeignKey(bc => bc.BlogPostId);
12+
this.HasRequired(comment => comment.BlogPost)
13+
.WithMany(blog => blog.BlogComments)
14+
.HasForeignKey(comment => comment.BlogPostId);
1515

16-
this.HasRequired(cc => cc.Customer)
16+
this.HasRequired(comment => comment.Customer)
1717
.WithMany()
18-
.HasForeignKey(cc => cc.CustomerId);
18+
.HasForeignKey(comment => comment.CustomerId);
19+
20+
this.HasRequired(comment => comment.Store)
21+
.WithMany()
22+
.HasForeignKey(comment => comment.StoreId);
1923
}
2024
}
2125
}

src/Libraries/Nop.Data/Mapping/News/NewsCommentMap.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ public partial class NewsCommentMap : NopEntityTypeConfiguration<NewsComment>
77
public NewsCommentMap()
88
{
99
this.ToTable("NewsComment");
10-
this.HasKey(pr => pr.Id);
10+
this.HasKey(comment => comment.Id);
1111

12-
this.HasRequired(nc => nc.NewsItem)
13-
.WithMany(n => n.NewsComments)
14-
.HasForeignKey(nc => nc.NewsItemId);
12+
this.HasRequired(comment => comment.NewsItem)
13+
.WithMany(news => news.NewsComments)
14+
.HasForeignKey(comment => comment.NewsItemId);
1515

16-
this.HasRequired(cc => cc.Customer)
16+
this.HasRequired(comment => comment.Customer)
1717
.WithMany()
18-
.HasForeignKey(cc => cc.CustomerId);
18+
.HasForeignKey(comment => comment.CustomerId);
19+
20+
this.HasRequired(comment => comment.Store)
21+
.WithMany()
22+
.HasForeignKey(comment => comment.StoreId);
1923
}
2024
}
2125
}

src/Libraries/Nop.Services/Blogs/BlogService.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,21 @@ public virtual void UpdateBlogPost(BlogPost blogPost)
242242
/// Gets all comments
243243
/// </summary>
244244
/// <param name="customerId">Customer identifier; 0 to load all records</param>
245+
/// <param name="storeId">Store identifier; pass 0 to load all records</param>
245246
/// <returns>Comments</returns>
246-
public virtual IList<BlogComment> GetAllComments(int customerId)
247+
public virtual IList<BlogComment> GetAllComments(int customerId = 0, int storeId = 0)
247248
{
248249
var query = _blogCommentRepository.Table;
250+
249251
if (customerId > 0)
250-
query = query.Where(bc => bc.CustomerId == customerId);
252+
query = query.Where(comment => comment.CustomerId == customerId);
253+
254+
if (storeId > 0)
255+
query = query.Where(comment => comment.StoreId == storeId);
256+
251257
query = query.OrderBy(bc => bc.CreatedOnUtc);
252-
var comments = query.ToList();
253-
return comments;
258+
259+
return query.ToList();
254260
}
255261

256262
/// <summary>
@@ -295,12 +301,16 @@ where commentIds.Contains(bc.Id)
295301
/// Get the count of blog comments
296302
/// </summary>
297303
/// <param name="blogPost">Blog post</param>
304+
/// <param name="storeId">Store identifier; pass 0 to load all records</param>
298305
/// <param name="isApproved">A value indicating whether to count only approved or not approved comments; pass null to get number of all comments</param>
299306
/// <returns>Number of blog comments</returns>
300-
public virtual int GetBlogCommentsCount(BlogPost blogPost, bool? isApproved = null)
307+
public virtual int GetBlogCommentsCount(BlogPost blogPost, int storeId = 0, bool? isApproved = null)
301308
{
302309
var query = _blogCommentRepository.Table.Where(comment => comment.BlogPostId == blogPost.Id);
303310

311+
if (storeId > 0)
312+
query = query.Where(comment => comment.StoreId == storeId);
313+
304314
if (isApproved.HasValue)
305315
query = query.Where(comment => comment.IsApproved == isApproved.Value);
306316

src/Libraries/Nop.Services/Blogs/IBlogService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ IPagedList<BlogPost> GetAllBlogPostsByTag(int storeId = 0,
9090
/// Gets all comments
9191
/// </summary>
9292
/// <param name="customerId">Customer identifier; 0 to load all records</param>
93+
/// <param name="storeId">Store identifier; pass 0 to load all records</param>
9394
/// <returns>Comments</returns>
94-
IList<BlogComment> GetAllComments(int customerId);
95+
IList<BlogComment> GetAllComments(int customerId = 0, int storeId = 0);
9596

9697
/// <summary>
9798
/// Gets a blog comment
@@ -111,9 +112,10 @@ IPagedList<BlogPost> GetAllBlogPostsByTag(int storeId = 0,
111112
/// Get the count of blog comments
112113
/// </summary>
113114
/// <param name="blogPost">Blog post</param>
115+
/// <param name="storeId">Store identifier; pass 0 to load all records</param>
114116
/// <param name="isApproved">A value indicating whether to count only approved or not approved comments; pass null to get number of all comments</param>
115117
/// <returns>Number of blog comments</returns>
116-
int GetBlogCommentsCount(BlogPost blogPost, bool? isApproved = null);
118+
int GetBlogCommentsCount(BlogPost blogPost, int storeId = 0, bool? isApproved = null);
117119

118120
/// <summary>
119121
/// Deletes a blog comment

src/Libraries/Nop.Services/Installation/CodeFirstInstallationService.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6207,7 +6207,8 @@ protected virtual void InstallSettings()
62076207
NotifyAboutNewBlogComments = false,
62086208
NumberOfTags = 15,
62096209
ShowHeaderRssUrl = false,
6210-
BlogCommentsMustBeApproved = false
6210+
BlogCommentsMustBeApproved = false,
6211+
ShowBlogCommentsPerStore = false
62116212
});
62126213
settingService.SaveSetting(new NewsSettings
62136214
{
@@ -6218,7 +6219,8 @@ protected virtual void InstallSettings()
62186219
MainPageNewsCount = 3,
62196220
NewsArchivePageSize = 10,
62206221
ShowHeaderRssUrl = false,
6221-
NewsCommentsMustBeApproved = false
6222+
NewsCommentsMustBeApproved = false,
6223+
ShowNewsCommentsPerStore = false
62226224
});
62236225

62246226
settingService.SaveSetting(new ForumSettings
@@ -10762,6 +10764,7 @@ protected virtual void InstallDiscounts()
1076210764
protected virtual void InstallBlogPosts(string defaultUserEmail)
1076310765
{
1076410766
var defaultLanguage = _languageRepository.Table.FirstOrDefault();
10767+
1076510768
var blogPosts = new List<BlogPost>
1076610769
{
1076710770
new BlogPost
@@ -10804,6 +10807,12 @@ protected virtual void InstallBlogPosts(string defaultUserEmail)
1080410807
var defaultCustomer = _customerRepository.Table.FirstOrDefault(x => x.Email == defaultUserEmail);
1080510808
if (defaultCustomer == null)
1080610809
throw new Exception("Cannot load default customer");
10810+
10811+
//default store
10812+
var defaultStore = _storeRepository.Table.FirstOrDefault();
10813+
if (defaultStore == null)
10814+
throw new Exception("No default store could be loaded");
10815+
1080710816
foreach (var blogPost in blogPosts)
1080810817
{
1080910818
blogPost.BlogComments.Add(new BlogComment
@@ -10812,6 +10821,7 @@ protected virtual void InstallBlogPosts(string defaultUserEmail)
1081210821
CustomerId = defaultCustomer.Id,
1081310822
CommentText = "This is a sample comment for this blog post",
1081410823
IsApproved = true,
10824+
StoreId = defaultStore.Id,
1081510825
CreatedOnUtc = DateTime.UtcNow
1081610826
});
1081710827
}
@@ -10821,6 +10831,7 @@ protected virtual void InstallBlogPosts(string defaultUserEmail)
1082110831
protected virtual void InstallNews(string defaultUserEmail)
1082210832
{
1082310833
var defaultLanguage = _languageRepository.Table.FirstOrDefault();
10834+
1082410835
var news = new List<NewsItem>
1082510836
{
1082610837
new NewsItem
@@ -10874,6 +10885,12 @@ protected virtual void InstallNews(string defaultUserEmail)
1087410885
var defaultCustomer = _customerRepository.Table.FirstOrDefault(x => x.Email == defaultUserEmail);
1087510886
if (defaultCustomer == null)
1087610887
throw new Exception("Cannot load default customer");
10888+
10889+
//default store
10890+
var defaultStore = _storeRepository.Table.FirstOrDefault();
10891+
if (defaultStore == null)
10892+
throw new Exception("No default store could be loaded");
10893+
1087710894
foreach (var newsItem in news)
1087810895
{
1087910896
newsItem.NewsComments.Add(new NewsComment
@@ -10883,6 +10900,7 @@ protected virtual void InstallNews(string defaultUserEmail)
1088310900
CommentTitle = "Sample comment title",
1088410901
CommentText = "This is a sample comment...",
1088510902
IsApproved = true,
10903+
StoreId = defaultStore.Id,
1088610904
CreatedOnUtc = DateTime.UtcNow
1088710905
});
1088810906
}

src/Libraries/Nop.Services/News/INewsService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ IPagedList<NewsItem> GetAllNews(int languageId = 0, int storeId = 0,
6363
/// Gets all comments
6464
/// </summary>
6565
/// <param name="customerId">Customer identifier; 0 to load all records</param>
66+
/// <param name="storeId">Store identifier; pass 0 to load all records</param>
6667
/// <returns>Comments</returns>
67-
IList<NewsComment> GetAllComments(int customerId);
68+
IList<NewsComment> GetAllComments(int customerId = 0, int storeId = 0);
6869

6970
/// <summary>
7071
/// Gets a news comment
@@ -84,9 +85,10 @@ IPagedList<NewsItem> GetAllNews(int languageId = 0, int storeId = 0,
8485
/// Get the count of news comments
8586
/// </summary>
8687
/// <param name="newsItem">News item</param>
88+
/// <param name="storeId">Store identifier; pass 0 to load all records</param>
8789
/// <param name="isApproved">A value indicating whether to count only approved or not approved comments; pass null to get number of all comments</param>
8890
/// <returns>Number of news comments</returns>
89-
int GetNewsCommentsCount(NewsItem newsItem, bool? isApproved = null);
91+
int GetNewsCommentsCount(NewsItem newsItem, int storeId = 0, bool? isApproved = null);
9092

9193
/// <summary>
9294
/// Deletes a news comment

0 commit comments

Comments
 (0)