Skip to content

Commit

Permalink
Allow to use recommended products per store
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Jul 20, 2021
1 parent 982be63 commit f9e2750
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Grand.Business.Catalog.Interfaces.Products;
using Grand.Business.Catalog.Queries.Models;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Data;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
using MediatR;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class GetRecommendedProductsQueryHandler : IRequestHandler<GetRecommended

public async Task<IList<Product>> Handle(GetRecommendedProductsQuery request, CancellationToken cancellationToken)
{
return await _cacheBase.GetAsync(string.Format(CacheKey.PRODUCTS_CUSTOMER_GROUP, string.Join(",", request.CustomerGroupIds)), async () =>
return await _cacheBase.GetAsync(string.Format(CacheKey.PRODUCTS_CUSTOMER_GROUP, string.Join(",", request.CustomerGroupIds), request.StoreId), async () =>
{
var query = from cr in _customerGroupProductRepository.Table
where request.CustomerGroupIds.Contains(cr.CustomerGroupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace Grand.Business.Catalog.Queries.Models
public class GetRecommendedProductsQuery : IRequest<IList<Product>>
{
public string[] CustomerGroupIds { get; set; }
public string StoreId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public static partial class CacheKey
/// </summary>
/// <remarks>
/// {0} : customer group IDs
/// {1} : store ident
/// </remarks>
public static string PRODUCTS_CUSTOMER_GROUP => "Grand.product.cr-{0}";
public static string PRODUCTS_CUSTOMER_GROUP => "Grand.product.cr-{0}-{1}";

/// <summary>
/// Key for caching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<IViewComponentResult> InvokeAsync(int? productThumbPictureSize
if (!_catalogSettings.RecommendedProductsEnabled)
return Content("");

var products = await _mediator.Send(new GetRecommendedProductsQuery() { CustomerGroupIds = _workContext.CurrentCustomer.GetCustomerGroupIds() });
var products = await _mediator.Send(new GetRecommendedProductsQuery() { CustomerGroupIds = _workContext.CurrentCustomer.GetCustomerGroupIds(), StoreId =_workContext.CurrentStore.Id });

if (!products.Any())
return Content("");
Expand Down

0 comments on commit f9e2750

Please sign in to comment.