-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat/VCST-2241
- Loading branch information
Showing
19 changed files
with
397 additions
and
61 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
src/VirtoCommerce.XCart.Core/Commands/ChangeCartConfiguredLineItemCommand.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,14 @@ | ||
using System.Collections.Generic; | ||
using VirtoCommerce.XCart.Core.Commands.BaseCommands; | ||
using VirtoCommerce.XCart.Core.Models; | ||
|
||
namespace VirtoCommerce.XCart.Core.Commands; | ||
|
||
public class ChangeCartConfiguredLineItemCommand : CartCommand | ||
{ | ||
public string LineItemId { get; set; } | ||
|
||
public int? Quantity { get; set; } | ||
|
||
public IList<ProductConfigurationSection> ConfigurationSections { get; set; } = new List<ProductConfigurationSection>(); | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/VirtoCommerce.XCart.Core/Models/ConfigurationItemsResponse.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,11 @@ | ||
using System.Collections.Generic; | ||
using VirtoCommerce.CartModule.Core.Model; | ||
|
||
namespace VirtoCommerce.XCart.Core.Models; | ||
|
||
public class ConfigurationItemsResponse | ||
{ | ||
public CartAggregate CartAggregate { get; set; } | ||
|
||
public IList<ConfigurationItem> ConfigurationItems { get; set; } = []; | ||
} |
51 changes: 51 additions & 0 deletions
51
src/VirtoCommerce.XCart.Core/Queries/GetConfigurationItemsQuery.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,51 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using GraphQL; | ||
using GraphQL.Types; | ||
using VirtoCommerce.Xapi.Core.BaseQueries; | ||
using VirtoCommerce.Xapi.Core.Extensions; | ||
using VirtoCommerce.XCart.Core.Models; | ||
|
||
namespace VirtoCommerce.XCart.Core.Queries; | ||
|
||
public class GetConfigurationItemsQuery : Query<ConfigurationItemsResponse>, ICartQuery | ||
{ | ||
public IList<string> IncludeFields { get; set; } = new List<string>(); | ||
public string StoreId { get; set; } | ||
public string CartType { get; set; } | ||
public string CartName { get; set; } | ||
public string UserId { get; set; } | ||
public string OrganizationId { get; set; } | ||
public string CurrencyCode { get; set; } | ||
public string CultureName { get; set; } | ||
|
||
public string CartId { get; set; } | ||
public string LineItemId { get; set; } | ||
|
||
public override IEnumerable<QueryArgument> GetArguments() | ||
{ | ||
yield return Argument<StringGraphType>(nameof(CartId)); | ||
yield return Argument<NonNullGraphType<StringGraphType>>(nameof(LineItemId)); | ||
yield return Argument<NonNullGraphType<StringGraphType>>(nameof(StoreId), description: "Store Id"); | ||
yield return Argument<NonNullGraphType<StringGraphType>>(nameof(CurrencyCode), description: "Currency code (\"USD\")"); | ||
yield return Argument<StringGraphType>(nameof(CartType), description: "Cart type"); | ||
yield return Argument<StringGraphType>(nameof(CartName), description: "Cart name"); | ||
yield return Argument<StringGraphType>(nameof(UserId), description: "User Id"); | ||
yield return Argument<StringGraphType>(nameof(CultureName), description: "Culture name (\"en-Us\")"); | ||
} | ||
|
||
public override void Map(IResolveFieldContext context) | ||
{ | ||
CartId = context.GetArgument<string>(nameof(CartId)); | ||
LineItemId = context.GetArgument<string>(nameof(LineItemId)); | ||
StoreId = context.GetArgument<string>(nameof(StoreId)); | ||
CartType = context.GetArgument<string>(nameof(CartType)); | ||
CartName = context.GetArgument<string>(nameof(CartName)); | ||
UserId = context.GetArgument<string>(nameof(UserId)); | ||
OrganizationId = context.GetCurrentOrganizationId(); | ||
CurrencyCode = context.GetArgument<string>(nameof(CurrencyCode)); | ||
CultureName = context.GetArgument<string>(nameof(CultureName)); | ||
|
||
IncludeFields = context.SubFields.Values.GetAllNodesPaths(context).ToArray(); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/VirtoCommerce.XCart.Core/Schemas/ConfigurationItemsResponseType.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,16 @@ | ||
using GraphQL.Types; | ||
using VirtoCommerce.Xapi.Core.Schemas; | ||
using VirtoCommerce.XCart.Core.Models; | ||
|
||
namespace VirtoCommerce.XCart.Core.Schemas; | ||
|
||
public class ConfigurationItemsResponseType : ExtendableGraphType<ConfigurationItemsResponse> | ||
{ | ||
public ConfigurationItemsResponseType() | ||
{ | ||
ExtendableField<ListGraphType<CartConfigurationItemType>>( | ||
"configurationItems", | ||
"Configuration items for configurable product", | ||
resolve: context => context.Source.ConfigurationItems ?? []); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/VirtoCommerce.XCart.Core/Schemas/InputChangeCartConfiguredItemType.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,14 @@ | ||
using GraphQL.Types; | ||
|
||
namespace VirtoCommerce.XCart.Core.Schemas | ||
{ | ||
public class InputChangeCartConfiguredItemType : InputCartBaseType | ||
{ | ||
public InputChangeCartConfiguredItemType() | ||
{ | ||
Field<NonNullGraphType<StringGraphType>>("lineItemId", "Line item Id"); | ||
Field<IntGraphType>("quantity", "Quantity"); | ||
Field<ListGraphType<ConfigurationSectionInput>>("configurationSections", "Configuration sections"); | ||
} | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
src/VirtoCommerce.XCart.Data/Commands/ChangeCartConfiguredLineItemCommandHandler.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,55 @@ | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using VirtoCommerce.CartModule.Core.Model; | ||
using VirtoCommerce.XCart.Core; | ||
using VirtoCommerce.XCart.Core.Commands; | ||
using VirtoCommerce.XCart.Core.Commands.BaseCommands; | ||
using VirtoCommerce.XCart.Core.Services; | ||
|
||
namespace VirtoCommerce.XCart.Data.Commands; | ||
|
||
public class ChangeCartConfiguredLineItemCommandHandler : CartCommandHandler<ChangeCartConfiguredLineItemCommand> | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public ChangeCartConfiguredLineItemCommandHandler(ICartAggregateRepository cartAggregateRepository, IMediator mediator) | ||
: base(cartAggregateRepository) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
public override async Task<CartAggregate> Handle(ChangeCartConfiguredLineItemCommand request, CancellationToken cancellationToken) | ||
{ | ||
var cartAggregate = await GetOrCreateCartFromCommandAsync(request); | ||
|
||
var lineItem = GetConfiguredLineItem(request, cartAggregate); | ||
if (lineItem != null) | ||
{ | ||
var command = new CreateConfiguredLineItemCommand | ||
{ | ||
StoreId = request.StoreId, | ||
UserId = request.UserId, | ||
OrganizationId = request.OrganizationId, | ||
CultureName = request.CultureName, | ||
CurrencyCode = request.CurrencyCode, | ||
ConfigurableProductId = lineItem.ProductId, | ||
ConfigurationSections = request.ConfigurationSections, | ||
Quantity = request.Quantity ?? lineItem.Quantity, | ||
}; | ||
|
||
var mediatorResult = await _mediator.Send(command, cancellationToken); | ||
await cartAggregate.UpdateConfiguredLineItemAsync(lineItem.Id, mediatorResult.Item); | ||
|
||
return await SaveCartAsync(cartAggregate); | ||
} | ||
|
||
return cartAggregate; | ||
} | ||
|
||
private static LineItem GetConfiguredLineItem(ChangeCartConfiguredLineItemCommand request, CartAggregate cartAggregate) | ||
{ | ||
return cartAggregate.Cart.Items.FirstOrDefault(x => x.Id == request.LineItemId && x.IsConfigured); | ||
} | ||
} |
Oops, something went wrong.