diff --git a/Directory.Build.props b/Directory.Build.props index b2cc603..6c05eba 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ - 3.817.0 + 3.818.0 $(VersionSuffix)-$(BuildNumber) diff --git a/src/VirtoCommerce.XCart.Core/VirtoCommerce.XCart.Core.csproj b/src/VirtoCommerce.XCart.Core/VirtoCommerce.XCart.Core.csproj index 05e4278..620e88c 100644 --- a/src/VirtoCommerce.XCart.Core/VirtoCommerce.XCart.Core.csproj +++ b/src/VirtoCommerce.XCart.Core/VirtoCommerce.XCart.Core.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/VirtoCommerce.XCart.Data/Commands/AddCartItemCommandHandler.cs b/src/VirtoCommerce.XCart.Data/Commands/AddCartItemCommandHandler.cs index 6674c08..21bd7ad 100644 --- a/src/VirtoCommerce.XCart.Data/Commands/AddCartItemCommandHandler.cs +++ b/src/VirtoCommerce.XCart.Data/Commands/AddCartItemCommandHandler.cs @@ -2,6 +2,9 @@ using System.Threading; using System.Threading.Tasks; using MediatR; +using VirtoCommerce.CatalogModule.Core.Model.Search; +using VirtoCommerce.CatalogModule.Core.Search; +using VirtoCommerce.Platform.Core.Common; using VirtoCommerce.XCart.Core; using VirtoCommerce.XCart.Core.Commands; using VirtoCommerce.XCart.Core.Commands.BaseCommands; @@ -14,15 +17,19 @@ public class AddCartItemCommandHandler : CartCommandHandler { private readonly ICartProductService _cartProductService; private readonly IMediator _mediator; + private readonly IProductConfigurationSearchService _productConfigurationSearchService; public AddCartItemCommandHandler( ICartAggregateRepository cartAggregateRepository, ICartProductService cartProductService, - IMediator mediator) + IMediator mediator, + IProductConfigurationSearchService productConfigurationSearchService + ) : base(cartAggregateRepository) { _cartProductService = cartProductService; _mediator = mediator; + _productConfigurationSearchService = productConfigurationSearchService; } public override async Task Handle(AddCartItemCommand request, CancellationToken cancellationToken) @@ -38,7 +45,13 @@ public override async Task Handle(AddCartItemCommand request, Can CartProduct = product, }; - if (product?.Product?.IsConfigurable == true) + var configurations = await _productConfigurationSearchService.SearchNoCloneAsync(new ProductConfigurationSearchCriteria + { + ProductId = request.ProductId + }); + var configuration = configurations.Results.FirstOrDefault(); + + if (configuration?.IsActive == true) { var createConfigurableProductCommand = new CreateConfiguredLineItemCommand { diff --git a/src/VirtoCommerce.XCart.Data/Queries/GetProductConfigurationQueryHandler.cs b/src/VirtoCommerce.XCart.Data/Queries/GetProductConfigurationQueryHandler.cs index 903ab17..0eb0370 100644 --- a/src/VirtoCommerce.XCart.Data/Queries/GetProductConfigurationQueryHandler.cs +++ b/src/VirtoCommerce.XCart.Data/Queries/GetProductConfigurationQueryHandler.cs @@ -1,7 +1,10 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using VirtoCommerce.CatalogModule.Core.Services; +using VirtoCommerce.CatalogModule.Core.Model.Configuration; +using VirtoCommerce.CatalogModule.Core.Model.Search; +using VirtoCommerce.CatalogModule.Core.Search; +using VirtoCommerce.Platform.Core.Common; using VirtoCommerce.Xapi.Core.Infrastructure; using VirtoCommerce.XCart.Core; using VirtoCommerce.XCart.Core.Models; @@ -12,23 +15,30 @@ namespace VirtoCommerce.XCatalog.Data.Queries; public class GetProductConfigurationQueryHandler : IQueryHandler { - private readonly IConfigurableProductService _configurableProductService; + private readonly IProductConfigurationSearchService _productConfigurationSearchService; private readonly IConfiguredLineItemContainerService _configuredLineItemContainerService; private readonly ICartProductsLoaderService _cartProductService; public GetProductConfigurationQueryHandler( - IConfigurableProductService configurableProductService, + IProductConfigurationSearchService productConfigurationSearchService, IConfiguredLineItemContainerService configuredLineItemContainerService, ICartProductsLoaderService cartProductService) { - _configurableProductService = configurableProductService; + _productConfigurationSearchService = productConfigurationSearchService; _configuredLineItemContainerService = configuredLineItemContainerService; _cartProductService = cartProductService; } public async Task Handle(GetProductConfigurationQuery request, CancellationToken cancellationToken) { - var configuration = await _configurableProductService.GetProductConfigurationAsync(request.ConfigurableProductId); + var result = new ProductConfigurationQueryResponse(); + + var configuration = await GetConfiguration(request); + + if (configuration == null) + { + return result; + } var container = await _configuredLineItemContainerService.CreateContainerAsync(request); @@ -40,7 +50,6 @@ public async Task Handle(GetProductConfigurat var productByIds = cartProducts.ToDictionary(x => x.Product.Id, x => x); - var result = new ProductConfigurationQueryResponse(); foreach (var section in configuration.Sections) { var configurationSection = new ExpProductConfigurationSection @@ -49,7 +58,6 @@ public async Task Handle(GetProductConfigurat Name = section.Name, IsRequired = section.IsRequired, Description = section.Description, - Type = section.Type, }; result.ConfigurationSections.Add(configurationSection); @@ -76,4 +84,13 @@ public async Task Handle(GetProductConfigurat return result; } + + private async Task GetConfiguration(GetProductConfigurationQuery request) + { + var criteria = AbstractTypeFactory.TryCreateInstance(); + criteria.ProductId = request.ConfigurableProductId; + + var configurationsResult = await _productConfigurationSearchService.SearchNoCloneAsync(criteria); + return configurationsResult.Results.FirstOrDefault(); + } } diff --git a/src/VirtoCommerce.XCart.Web/module.manifest b/src/VirtoCommerce.XCart.Web/module.manifest index 7bf11f5..0f91239 100644 --- a/src/VirtoCommerce.XCart.Web/module.manifest +++ b/src/VirtoCommerce.XCart.Web/module.manifest @@ -1,7 +1,7 @@ VirtoCommerce.XCart - 3.817.0 + 3.818.0 3.867.0 @@ -13,7 +13,7 @@ - + Cart Experience API