Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/VirtoCommerce.Xapi.Core/Queries/SlugInfoQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SlugInfoQuery : Query<SlugInfoResponse>
#pragma warning restore VC0008
public string StoreId { get; set; }
public string UserId { get; set; }
public string OrganizationId { get; set; }
public string CultureName { get; set; }

public override IEnumerable<QueryArgument> GetArguments()
Expand Down
10 changes: 10 additions & 0 deletions src/VirtoCommerce.Xapi.Data/Queries/SlugInfoQueryBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Threading.Tasks;
using GraphQL;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using VirtoCommerce.Xapi.Core.BaseQueries;
using VirtoCommerce.Xapi.Core.Extensions;
using VirtoCommerce.Xapi.Core.Models;
using VirtoCommerce.Xapi.Core.Queries;
using VirtoCommerce.Xapi.Core.Schemas;
Expand All @@ -15,5 +18,12 @@ public SlugInfoQueryBuilder(IMediator mediator, IAuthorizationService authorizat
}

protected override string Name => "slugInfo";

protected override Task BeforeMediatorSend(IResolveFieldContext<object> context, SlugInfoQuery request)
{
request.OrganizationId = context.GetCurrentOrganizationId();

return base.BeforeMediatorSend(context, request);
}
}
}
9 changes: 5 additions & 4 deletions src/VirtoCommerce.Xapi.Data/Queries/SlugInfoQueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SlugInfoQueryHandler(
: IQueryHandler<SlugInfoQuery, SlugInfoResponse>
{

public async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationToken cancellationToken)
public virtual async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationToken cancellationToken)
{
var result = new SlugInfoResponse();

Expand Down Expand Up @@ -56,7 +56,7 @@ public async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationTo
criteria.Slug = lastSegment;
criteria.UserId = request.UserId;

result.EntityInfo = await GetBestMatchingSeoInfo(criteria, store);
result.EntityInfo = await GetBestMatchingSeoInfo(request, criteria, store);

if (result.EntityInfo == null)
{
Expand All @@ -72,7 +72,7 @@ public async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationTo
if (brokenLinkResult.Results.Count > 0)
{
var resultItem = brokenLinkResult.Results.FirstOrDefault(x =>
(x.Language == request.CultureName) ||
x.Language == request.CultureName ||
(!request.CultureName.IsNullOrEmpty() && x.Language.IsNullOrEmpty()))
?? brokenLinkResult.Results.FirstOrDefault();

Expand All @@ -83,9 +83,10 @@ public async Task<SlugInfoResponse> Handle(SlugInfoQuery request, CancellationTo
return result;
}

protected virtual async Task<SeoInfo> GetBestMatchingSeoInfo(SeoSearchCriteria criteria, Store store)
protected virtual async Task<SeoInfo> GetBestMatchingSeoInfo(SlugInfoQuery request, SeoSearchCriteria criteria, Store store)
{
var itemsToMatch = await seoResolver.FindSeoAsync(criteria);

return itemsToMatch.GetBestMatchingSeoInfo(store, criteria.LanguageCode);
}
}
Loading