-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VCST-2223: update to Configurable Products (#23)
* feat: update to Configurable Products (#23) --------- Co-authored-by: Евгений Колосов <[email protected]>
- Loading branch information
1 parent
ba3118c
commit 5d4f971
Showing
5 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/VirtoCommerce.XCatalog.Core/Queries/GetProductConfigurationsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Collections.Generic; | ||
using VirtoCommerce.Xapi.Core.Infrastructure; | ||
|
||
namespace VirtoCommerce.XCatalog.Core.Queries; | ||
public class GetProductConfigurationsQuery : IQuery<Dictionary<string, bool>> | ||
{ | ||
public string[] ProductIds { get; set; } = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/VirtoCommerce.XCatalog.Data/Queries/GetProductConfigurationsQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using VirtoCommerce.CatalogModule.Core.Model.Search; | ||
using VirtoCommerce.CatalogModule.Core.Search; | ||
using VirtoCommerce.Platform.Core.Common; | ||
using VirtoCommerce.Xapi.Core.Infrastructure; | ||
using VirtoCommerce.XCatalog.Core.Queries; | ||
|
||
namespace VirtoCommerce.XCatalog.Data.Queries; | ||
public class GetProductConfigurationsQueryHandler : IQueryHandler<GetProductConfigurationsQuery, Dictionary<string, bool>> | ||
{ | ||
private readonly IProductConfigurationSearchService _productConfigurationSearchService; | ||
|
||
public GetProductConfigurationsQueryHandler(IProductConfigurationSearchService productConfigurationSearchService) | ||
{ | ||
_productConfigurationSearchService = productConfigurationSearchService; | ||
} | ||
|
||
public async Task<Dictionary<string, bool>> Handle(GetProductConfigurationsQuery request, CancellationToken cancellationToken) | ||
{ | ||
var criteria = AbstractTypeFactory<ProductConfigurationSearchCriteria>.TryCreateInstance(); | ||
criteria.ProductIds = request.ProductIds; | ||
|
||
var configurations = await _productConfigurationSearchService.SearchNoCloneAsync(criteria); | ||
|
||
var result = configurations.Results.ToDictionary(x => x.ProductId, x => x.IsActive); | ||
|
||
var existingConfigurations = result.Select(result => result.Key).ToArray(); | ||
foreach (var nonExistingConfiguration in request.ProductIds.Except(existingConfigurations)) | ||
{ | ||
result.TryAdd(nonExistingConfiguration, false); | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters