Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

CompareProductService - move actions to the product controller

KrzysztofPajak1cec820cf37b
diff --git a/src/Business/Grand.Business.Catalog/Interfaces/Products/ICompareProductsService.cs b/src/Business/Grand.Business.Catalog/Interfaces/Products/ICompareProductsService.cs
deleted file mode 100644
index de46cd3e7..000000000
--- a/src/Business/Grand.Business.Catalog/Interfaces/Products/ICompareProductsService.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using Grand.Domain.Catalog;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-
-namespace Grand.Business.Catalog.Interfaces.Products
-{
- /// <summary>
- /// Compare products service interface
- /// </summary>
- public partial interface ICompareProductsService
- {
-
- /// <summary>
- /// Gets a "compare products" list
- /// </summary>
- /// <returns>"Compare products" list</returns>
- Task<IList<Product>> GetComparedProducts();
-
- /// <summary>
- /// Removes a product from a "compare products" list
- /// </summary>
- /// <param name="productId">Product identifier</param>
- void RemoveProductFromCompareList(string productId);
-
- /// <summary>
- /// Adds a product to a "compare products" list
- /// </summary>
- /// <param name="productId">Product identifier</param>
- void AddProductToCompareList(string productId);
-
- /// <summary>
- /// Clears a "compare products" list
- /// </summary>
- void ClearCompareProducts();
-
- }
-}
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/CompareProductsService.cs b/src/Business/Grand.Business.Catalog/Services/Products/CompareProductsService.cs
deleted file mode 100644
index b5c29ff69..000000000
--- a/src/Business/Grand.Business.Catalog/Services/Products/CompareProductsService.cs
+++ /dev/null
@@ -1,172 +0,0 @@
-using Grand.Business.Catalog.Interfaces.Products;
-using Grand.Infrastructure.Caching.Constants;
-using Grand.Domain.Catalog;
-using Grand.SharedKernel.Extensions;
-using Microsoft.AspNetCore.Http;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Grand.Business.Catalog.Services.Products
-{
- /// <summary>
- /// Compare products service
- /// </summary>
- public partial class CompareProductsService : ICompareProductsService
- {
- #region Fields
-
- private readonly IHttpContextAccessor _httpContextAccessor;
- private readonly IProductService _productService;
- private readonly CatalogSettings _catalogSettings;
-
- #endregion
-
- #region Ctor
-
-
- #region Utilities
-
- protected virtual void AddCompareProductsCookie(IEnumerable<string> comparedProductIds)
- {
- //delete current cookie if exists
- _httpContextAccessor.HttpContext.Response.Cookies.Delete(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME);
-
- //create cookie value
- var comparedProductIdsCookie = string.Join(",", comparedProductIds);
-
- //create cookie options
- var cookieOptions = new CookieOptions
- {
- Expires = DateTime.UtcNow.AddHours(CommonHelper.CookieAuthExpires),
- HttpOnly = true
- };
-
- //add cookie
- _httpContextAccessor.HttpContext.Response.Cookies.Append(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, comparedProductIdsCookie, cookieOptions);
- }
-
- #endregion
-
- /// <summary>
- /// Ctor
- /// </summary>
- /// <param name="httpContext">HTTP context</param>
- /// <param name="productService">Product service</param>
- /// <param name="catalogSettings">Catalog settings</param>
- public CompareProductsService(IHttpContextAccessor httpContextAccessor, IProductService productService,
- CatalogSettings catalogSettings)
- {
- _httpContextAccessor = httpContextAccessor;
- _productService = productService;
- _catalogSettings = catalogSettings;
- }
-
- #endregion
-
- #region Utilities
-
- /// <summary>
- /// Gets a "compare products" identifier list
- /// </summary>
- /// <returns>"compare products" identifier list</returns>
- protected virtual List<string> GetComparedProductIds()
- {
- var httpContext = _httpContextAccessor.HttpContext;
- if (httpContext == null || httpContext.Request == null)
- return new List<string>();
-
- //try to get cookie
- if (!httpContext.Request.Cookies.TryGetValue(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, out string productIdsCookie) || string.IsNullOrEmpty(productIdsCookie))
- return new List<string>();
-
- //get array of string product identifiers from cookie
- var productIds = productIdsCookie.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
-
- //return list of int product identifiers
- return productIds.Select(productId => productId).Distinct().ToList();
- }
-
- #endregion
-
- #region Methods
-
- /// <summary>
- /// Gets a "compare products" list
- /// </summary>
- /// <returns>"Compare products" list</returns>
- public virtual async Task<IList<Product>> GetComparedProducts()
- {
- var products = new List<Product>();
- var productIds = GetComparedProductIds();
- foreach (string productId in productIds)
- {
- var product = await _productService.GetProductById(productId);
- if (product != null && product.Published)
- products.Add(product);
- }
- return products;
- }
-
- /// <summary>
- /// Removes a product from a "compare products" list
- /// </summary>
- /// <param name="productId">Product identifier</param>
- public virtual void RemoveProductFromCompareList(string productId)
- {
- if (_httpContextAccessor.HttpContext == null || _httpContextAccessor.HttpContext.Response == null)
- return;
-
- //get list of compared product identifiers
- var comparedProductIds = GetComparedProductIds();
-
- //whether product identifier to remove exists
- if (!comparedProductIds.Contains(productId))
- return;
-
- //it exists, so remove it from list
- comparedProductIds.Remove(productId);
-
- //set cookie
- AddCompareProductsCookie(comparedProductIds);
- }
-
- /// <summary>
- /// Adds a product to a "compare products" list
- /// </summary>
- /// <param name="productId">Product identifier</param>
- public virtual void AddProductToCompareList(string productId)
- {
-
- if (_httpContextAccessor.HttpContext == null || _httpContextAccessor.HttpContext.Response == null)
- return;
-
- //get list of compared product identifiers
- var comparedProductIds = GetComparedProductIds();
-
- //whether product identifier to add already exist
- if (!comparedProductIds.Contains(productId))
- comparedProductIds.Insert(0, productId);
-
- //limit list based on the allowed number of products to be compared
- comparedProductIds = comparedProductIds.Take(_catalogSettings.CompareProductsNumber).ToList();
-
- //set cookie
- AddCompareProductsCookie(comparedProductIds);
- }
- /// <summary>
- /// Clears a "compare products" list
- /// </summary>
- public virtual void ClearCompareProducts()
- {
- if (_httpContextAccessor.HttpContext == null || _httpContextAccessor.HttpContext.Response == null)
- return;
-
- //sets an expired cookie
- _httpContextAccessor.HttpContext.Response.Cookies.Delete(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME);
- }
-
- #endregion
- }
-}
diff --git a/src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs b/src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs
index aed2d24d6..6e546cffd 100644
--- a/src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs
+++ b/src/Business/Grand.Business.Catalog/Startup/StartupApplication.cs
@@ -42,7 +42,6 @@ namespace Grand.Business.Catalog.Startup
serviceCollection.AddScoped<IOutOfStockSubscriptionService, OutOfStockSubscriptionService>();
serviceCollection.AddScoped<ICategoryService, CategoryService>();
serviceCollection.AddScoped<IBrandService, BrandService>();
- serviceCollection.AddScoped<ICompareProductsService, CompareProductsService>();
serviceCollection.AddScoped<IRecentlyViewedProductsService, RecentlyViewedProductsService>();
serviceCollection.AddScoped<ICollectionService, CollectionService>();
serviceCollection.AddScoped<IPriceFormatter, PriceFormatter>();
diff --git a/src/Business/Grand.Business.Storage/Extensions/Extensions.cs b/src/Business/Grand.Business.Storage/Extensions/Extensions.cs
index a8b47132c..dc4e4d883 100644
--- a/src/Business/Grand.Business.Storage/Extensions/Extensions.cs
+++ b/src/Business/Grand.Business.Storage/Extensions/Extensions.cs
@@ -1,9 +1,5 @@
using Microsoft.AspNetCore.Http;
-using System;
-using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Threading.Tasks;
namespace Grand.Business.Storage.Extensions
{
@@ -38,6 +34,6 @@ namespace Grand.Business.Storage.Extensions
return GetDownloadBits(file);
}
-
+
}
}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Products/CompareProductsServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Service/Products/CompareProductsServiceTests.cs
deleted file mode 100644
index 3cc223912..000000000
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Products/CompareProductsServiceTests.cs
+++ /dev/null
@@ -1,157 +0,0 @@
-using Grand.Business.Catalog.Interfaces.Products;
-using Grand.Business.Catalog.Services.Products;
-using Grand.Domain.Catalog;
-using Microsoft.AspNetCore.Http;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Grand.Business.Catalog.Tests.Service.Products
-{
- [TestClass()]
- public class CompareProductsServiceTests
- {
- private Mock<IProductService> _productServiceMock;
- private Mock<IHttpContextAccessor> _httpContextAccessor;
- private CatalogSettings _settings;
- private CompareProductsService _compareProductsService;
- private List<Product> _mockProducts;
-
- [TestInitialize()]
- public void Init()
- {
- _productServiceMock = new Mock<IProductService>();
- _httpContextAccessor = new Mock<IHttpContextAccessor>();
- _settings = new CatalogSettings();
- _compareProductsService = new CompareProductsService(_httpContextAccessor.Object, _productServiceMock.Object, _settings);
- _mockProducts = new List<Product>
- {
- new Product(){Id="1",Published=true},
- new Product(){Id="2",Published=true},
- new Product(){Id="3",Published=true},
- new Product(){Id="4",Published=true},
- new Product(){Id="5",Published=true}
- };
- }
-
- [TestMethod()]
- public async Task GetComparedProducts_NullHttpContext_ReturnEmptyList()
- {
- var result = await _compareProductsService.GetComparedProducts();
- Assert.IsTrue(result.Count == 0);
- }
-
- [TestMethod()]
- public async Task GetComparedProducts_NotConstainsCookie_ReturnEmptyList()
- {
- var value = "";
- var request = new Mock<HttpRequest>();
- var cookie = new Mock<IRequestCookieCollection>();
- cookie.Setup(c => c.TryGetValue(It.IsAny<string>(), out value)).Returns(false);
- request.Setup(r => r.Cookies).Returns(cookie.Object);
- var httpContext = new Mock<HttpContext>();
- httpContext.Setup(c => c.Request).Returns(request.Object);
- _httpContextAccessor.Setup(c => c.HttpContext).Returns(httpContext.Object);
-
- var result = await _compareProductsService.GetComparedProducts();
- Assert.IsTrue(result.Count == 0);
- }
-
- [TestMethod()]
- public async Task GetComparedProducts_ConstainsCookie_ReturnProductList()
- {
- var ids = "1,2,3,4,5";
- var request = new Mock<HttpRequest>();
- var cookie = new Mock<IRequestCookieCollection>();
- cookie.Setup(c => c.TryGetValue(It.IsAny<string>(), out ids)).Returns(true);
- request.Setup(r => r.Cookies).Returns(cookie.Object);
- var httpContext = new Mock<HttpContext>();
- httpContext.Setup(c => c.Request).Returns(request.Object);
- _httpContextAccessor.Setup(c => c.HttpContext).Returns(httpContext.Object);
- _productServiceMock.Setup(c => c.GetProductById(It.IsAny<string>(), default(bool)))
- .Returns((string w, bool f) => Task.FromResult(_mockProducts.FirstOrDefault(i => i.Id.Equals(w))));
-
- var result = await _compareProductsService.GetComparedProducts();
- Assert.IsTrue(result.Count == 5);
- }
-
- [TestMethod()]
- public void RemoveProductFromCompareList_SetNewCompareProductCookie()
- {
- var ids = "1,2,3,4,5";
- var request = new Mock<HttpRequest>();
- var cookie = new Mock<IRequestCookieCollection>();
- cookie.Setup(c => c.TryGetValue(It.IsAny<string>(), out ids)).Returns(true);
- request.Setup(r => r.Cookies).Returns(cookie.Object);
- var httpContext = new Mock<HttpContext>();
- httpContext.Setup(c => c.Request).Returns(request.Object);
- _httpContextAccessor.Setup(c => c.HttpContext).Returns(httpContext.Object);
- _productServiceMock.Setup(c => c.GetProductById(It.IsAny<string>(), default(bool)))
- .Returns((string w, bool f) => Task.FromResult(_mockProducts.FirstOrDefault(i => i.Id.Equals(w))));
- var responseCookie = new Mock<IResponseCookies>();
- var response = new Mock<HttpResponse>();
- response.Setup(r => r.Cookies).Returns(responseCookie.Object);
- httpContext.Setup(c => c.Response).Returns(response.Object);
- _compareProductsService.RemoveProductFromCompareList("5");
-
- //delete current cookie if exists
- responseCookie.Verify(rc => rc.Delete(It.IsAny<string>()), Times.Once);
- //add cookie
- responseCookie.Verify(rc => rc.Append(It.IsAny<string>(), "1,2,3,4", It.IsAny<CookieOptions>()), Times.Once);
-
- }
-
- [TestMethod()]
- public void ClearCompareProducts_NullHttpContext_NotInvokeDeleteCookie()
- {
- var responseCookie = new Mock<IResponseCookies>();
- _compareProductsService.ClearCompareProducts();
- responseCookie.Verify(rc => rc.Delete(It.IsAny<string>()), Times.Never);
- }
-
-
- [TestMethod()]
- public void ClearCompareProducts_InvokeDeleteCookie()
- {
- var httpContext = new Mock<HttpContext>();
- _httpContextAccessor.Setup(c => c.HttpContext).Returns(httpContext.Object);
- var responseCookie = new Mock<IResponseCookies>();
- var response = new Mock<HttpResponse>();
- response.Setup(r => r.Cookies).Returns(responseCookie.Object);
- httpContext.Setup(c => c.Response).Returns(response.Object);
-
- _compareProductsService.ClearCompareProducts();
- responseCookie.Verify(rc => rc.Delete(It.IsAny<string>()), Times.Once);
- }
-
- [TestMethod()]
- public void AddProductToCompareList_SetNewCompareProductCookie()
- {
- var ids = "1,2,3,4,5";
- var exprectedNewCookie = "6,1,2,3,4,5";
- var request = new Mock<HttpRequest>();
- var cookie = new Mock<IRequestCookieCollection>();
- cookie.Setup(c => c.TryGetValue(It.IsAny<string>(), out ids)).Returns(true);
- request.Setup(r => r.Cookies).Returns(cookie.Object);
- var httpContext = new Mock<HttpContext>();
- httpContext.Setup(c => c.Request).Returns(request.Object);
- _httpContextAccessor.Setup(c => c.HttpContext).Returns(httpContext.Object);
- _productServiceMock.Setup(c => c.GetProductById(It.IsAny<string>(), default(bool)))
- .Returns((string w, bool f) => Task.FromResult(_mockProducts.FirstOrDefault(i => i.Id.Equals(w))));
- var responseCookie = new Mock<IResponseCookies>();
- var response = new Mock<HttpResponse>();
- response.Setup(r => r.Cookies).Returns(responseCookie.Object);
- httpContext.Setup(c => c.Response).Returns(response.Object);
- _settings.CompareProductsNumber = 10;
- _compareProductsService.AddProductToCompareList("6");
-
- //delete current cookie if exists
- responseCookie.Verify(rc => rc.Delete(It.IsAny<string>()), Times.Once);
- //add cookie
- responseCookie.Verify(rc => rc.Append(It.IsAny<string>(), exprectedNewCookie, It.IsAny<CookieOptions>()), Times.Once);
-
- }
- }
-}
diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.cs
index 99a82cd17..135bd375b 100644
--- a/src/Web/Grand.Web/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web/Controllers/ProductController.cs
@@ -15,6 +15,8 @@ using Grand.Domain.Catalog;
using Grand.Domain.Media;
using Grand.Domain.Orders;
using Grand.Infrastructure;
+using Grand.Infrastructure.Caching.Constants;
+using Grand.SharedKernel.Extensions;
using Grand.Web.Commands.Models.Products;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Security.Captcha;
@@ -26,6 +28,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
using System;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -41,7 +44,6 @@ namespace Grand.Web.Controllers
private readonly ITranslationService _translationService;
private readonly IRecentlyViewedProductsService _recentlyViewedProductsService;
private readonly IShoppingCartService _shoppingCartService;
- private readonly ICompareProductsService _compareProductsService;
private readonly IAclService _aclService;
private readonly IPermissionService _permissionService;
private readonly ICustomerActivityService _customerActivityService;
@@ -61,7 +63,6 @@ namespace Grand.Web.Controllers
ITranslationService translationService,
IRecentlyViewedProductsService recentlyViewedProductsService,
IShoppingCartService shoppingCartService,
- ICompareProductsService compareProductsService,
IAclService aclService,
IPermissionService permissionService,
ICustomerActivityService customerActivityService,
@@ -77,7 +78,6 @@ namespace Grand.Web.Controllers
_translationService = translationService;
_recentlyViewedProductsService = recentlyViewedProductsService;
_shoppingCartService = shoppingCartService;
- _compareProductsService = compareProductsService;
_aclService = aclService;
_permissionService = permissionService;
_customerActivityService = customerActivityService;
@@ -867,6 +867,40 @@ namespace Grand.Web.Controllers
#region Comparing products
+ /// <summary>
+ /// Gets a "compare products" identifier list
+ /// </summary>
+ /// <returns>"compare products" identifier list</returns>
+ protected virtual List<string> GetComparedProductIds()
+ {
+ //try to get cookie
+ if (!HttpContext.Request.Cookies.TryGetValue(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, out string productIdsCookie) || string.IsNullOrEmpty(productIdsCookie))
+ return new List<string>();
+
+ //get array of string product identifiers from cookie
+ var productIds = productIdsCookie.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+
+ //return list of int product identifiers
+ return productIds.Select(productId => productId).Distinct().ToList();
+ }
+
+ protected virtual void AddCompareProductsCookie(IEnumerable<string> comparedProductIds)
+ {
+ //delete current cookie if exists
+ HttpContext.Response.Cookies.Delete(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME);
+
+ //create cookie value
+ var comparedProductIdsCookie = string.Join(",", comparedProductIds);
+
+ //create cookie options
+ var cookieOptions = new CookieOptions {
+ Expires = DateTime.UtcNow.AddHours(CommonHelper.CookieAuthExpires),
+ HttpOnly = true
+ };
+ //add cookie
+ HttpContext.Response.Cookies.Append(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, comparedProductIdsCookie, cookieOptions);
+ }
+
[HttpPost]
public virtual async Task<IActionResult> AddProductToCompareList(string productId)
{
@@ -892,7 +926,18 @@ namespace Grand.Web.Controllers
comparemessage = "Product comparison is disabled"
});
- _compareProductsService.AddProductToCompareList(productId);
+ //get list of compared product identifiers
+ var comparedProductIds = GetComparedProductIds();
+
+ //whether product identifier to add already exist
+ if (!comparedProductIds.Contains(productId))
+ comparedProductIds.Insert(0, productId);
+
+ //limit list based on the allowed number of products to be compared
+ comparedProductIds = comparedProductIds.Take(_catalogSettings.CompareProductsNumber).ToList();
+
+ //set cookie
+ AddCompareProductsCookie(comparedProductIds);
//activity log
await _customerActivityService.InsertActivity("PublicStore.AddToCompareList", productId,
@@ -903,8 +948,6 @@ namespace Grand.Web.Controllers
{
success = true,
comparemessage = string.Format(_translationService.GetResource("Products.ProductHasBeenAddedToCompareList.Link"), Url.RouteUrl("CompareProducts"))
- //use the code below (commented) if you want a customer to be automatically redirected to the compare products page
- //redirect = Url.RouteUrl("CompareProducts"),
});
}
@@ -917,7 +960,18 @@ namespace Grand.Web.Controllers
if (!_catalogSettings.CompareProductsEnabled)
return RedirectToRoute("HomePage");
- _compareProductsService.RemoveProductFromCompareList(productId);
+ //get list of compared product identifiers
+ var comparedProductIds = GetComparedProductIds();
+
+ //whether product identifier to remove exists
+ if (!comparedProductIds.Contains(productId))
+ return RedirectToRoute("CompareProducts");
+
+ //it exists, so remove it from list
+ comparedProductIds.Remove(productId);
+
+ //set cookie
+ AddCompareProductsCookie(comparedProductIds); ;
return RedirectToRoute("CompareProducts");
}
@@ -932,7 +986,14 @@ namespace Grand.Web.Controllers
IncludeFullDescriptionInCompareProducts = _catalogSettings.IncludeFullDescriptionInCompareProducts,
};
- var products = await _compareProductsService.GetComparedProducts();
+ var products = new List<Product>();
+ var productIds = GetComparedProductIds();
+ foreach (var id in productIds)
+ {
+ var product = await _productService.GetProductById(id);
+ if (product != null && product.Published)
+ products.Add(product);
+ }
//ACL and store acl
products = products.Where(p => _aclService.Authorize(p, _workContext.CurrentCustomer) && _aclService.Authorize(p, _workContext.CurrentStore.Id)).ToList();
@@ -953,10 +1014,13 @@ namespace Grand.Web.Controllers
if (!_catalogSettings.CompareProductsEnabled)
return RedirectToRoute("HomePage");
- _compareProductsService.ClearCompareProducts();
+ HttpContext.Response.Cookies.Delete(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME);
return RedirectToRoute("CompareProducts");
}
+ #endregion
+
+ #region Calendar
public virtual async Task<IActionResult> GetDatesForMonth(string productId, int month, string parameter, int year, [FromServices] IProductReservationService productReservationService)
{
@@ -983,6 +1047,8 @@ namespace Grand.Web.Controllers
return Json(toReturn);
}
+
#endregion
+
}
}
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchHandler.cs
index 4cc9da209..7fd8f555a 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchHandler.cs
@@ -12,9 +12,9 @@ using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Vendors;
using Grand.Infrastructure.Caching;
+using Grand.Web.Events.Cache;
using Grand.Web.Features.Models.Catalog;
using Grand.Web.Features.Models.Products;
-using Grand.Web.Events.Cache;
using Grand.Web.Models.Catalog;
using MediatR;
using Microsoft.AspNetCore.Http;
@@ -87,8 +87,7 @@ namespace Grand.Web.Features.Handlers.Catalog
request.Model.adv = true;
//view/sorting/page size
- var options = await _mediator.Send(new GetViewSortSizeOptions()
- {
+ var options = await _mediator.Send(new GetViewSortSizeOptions() {
Command = request.Command,
PagingFilteringModel = request.Model.PagingFilteringContext,
Language = request.Language,
@@ -120,8 +119,7 @@ namespace Grand.Web.Features.Handlers.Catalog
if (i != breadcrumb.Count - 1)
categoryBreadcrumb += " >> ";
}
- categoriesModel.Add(new SearchModel.CategoryModel
- {
+ categoriesModel.Add(new SearchModel.CategoryModel {
Id = c.Id,
Breadcrumb = categoryBreadcrumb
});
@@ -131,16 +129,14 @@ namespace Grand.Web.Features.Handlers.Catalog
if (categories.Any())
{
//first empty entry
- request.Model.AvailableCategories.Add(new SelectListItem
- {
+ request.Model.AvailableCategories.Add(new SelectListItem {
Value = "",
Text = _translationService.GetResource("Common.All")
});
//all other categories
foreach (var c in categories)
{
- request.Model.AvailableCategories.Add(new SelectListItem
- {
+ request.Model.AvailableCategories.Add(new SelectListItem {
Value = c.Id.ToString(),
Text = c.Breadcrumb,
Selected = request.Model.cid == c.Id
@@ -151,14 +147,12 @@ namespace Grand.Web.Features.Handlers.Catalog
var collections = await _collectionService.GetAllCollections();
if (collections.Any())
{
- request.Model.AvailableCollections.Add(new SelectListItem
- {
+ request.Model.AvailableCollections.Add(new SelectListItem {
Value = "",
Text = _translationService.GetResource("Common.All")
});
foreach (var m in collections)
- request.Model.AvailableCollections.Add(new SelectListItem
- {
+ request.Model.AvailableCollections.Add(new SelectListItem {
Value = m.Id.ToString(),
Text = m.GetTranslation(x => x.Name, request.Language.Id),
Selected = request.Model.mid == m.Id
@@ -171,14 +165,12 @@ namespace Grand.Web.Features.Handlers.Catalog
var vendors = await _vendorService.GetAllVendors();
if (vendors.Any())
{
- request.Model.AvailableVendors.Add(new SelectListItem
- {
+ request.Model.AvailableVendors.Add(new SelectListItem {
Value = "",
Text = _translationService.GetResource("Common.All")
});
foreach (var vendor in vendors)
- request.Model.AvailableVendors.Add(new SelectListItem
- {
+ request.Model.AvailableVendors.Add(new SelectListItem {
Value = vendor.Id.ToString(),
Text = vendor.GetTranslation(x => x.Name, request.Language.Id),
Selected = request.Model.vid == vendor.Id
@@ -240,8 +232,7 @@ namespace Grand.Web.Features.Handlers.Catalog
(_httpContextAccessor, _specificationAttributeService);
//products
- var searchproducts = (await _mediator.Send(new GetSearchProductsQuery()
- {
+ var searchproducts = (await _mediator.Send(new GetSearchProductsQuery() {
LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption,
CategoryIds = categoryIds,
CollectionId = collectionId,
@@ -262,8 +253,7 @@ namespace Grand.Web.Features.Handlers.Catalog
VendorId = vendorId
}));
- request.Model.Products = (await _mediator.Send(new GetProductOverview()
- {
+ request.Model.Products = (await _mediator.Send(new GetProductOverview() {
Products = searchproducts.products,
PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages
})).ToList();
@@ -288,8 +278,7 @@ namespace Grand.Web.Features.Handlers.Catalog
}
else
{
- searchTerm = new SearchTerm
- {
+ searchTerm = new SearchTerm {
Keyword = searchTerms,
StoreId = request.Store.Id,
Count = 1
diff --git a/src/Web/Grand.Web/Features/Models/Catalog/GetComparedProducts.cs b/src/Web/Grand.Web/Features/Models/Catalog/GetComparedProducts.cs
new file mode 100644
index 000000000..71c5d4c21
--- /dev/null
+++ b/src/Web/Grand.Web/Features/Models/Catalog/GetComparedProducts.cs
@@ -0,0 +1,11 @@
+using Grand.Domain.Catalog;
+using MediatR;
+using System.Collections.Generic;
+
+namespace Grand.Web.Features.Models.Catalog
+{
+ public class GetComparedProducts : IRequest<IList<Product>>
+ {
+
+ }
+}