Hey Virto Community !
Currently I was trying to create a custom graphql query that updates the dynamic properties of a line item as well as the price. I am returning this in the handler:
await cartAggregate.ChangeItemPriceAsync(priceAdjustment);
return await SaveCartAsync(cartAggregate);
The returned cart has missing fields like extendedPrice etc.
Here are some points related to the implementation:
- The endpoint is query and not mutation.
- We have already overriding InnerGetCartAggregateFromCartAsync in CartAggregateRepository.
- My code for handler for the query:
public async Task<CartAggregate> Handle(CartItemChangeQuery request, CancellationToken cancellationToken)
{
var dynamicPropertyHandlerRequest = new UpdateCartItemCommand
{
UserId = request.UserId,
StoreId = request.StoreId,
LineItemId = request.LineItemId,
DynamicProperties = request.DynamicProperties,
};
var cartAggregate = await GetOrCreateCartFromCommandAsync(dynamicPropertyHandlerRequest);
await cartAggregate.UpdateCartItemDynamicProperties(request.LineItemId, request.DynamicProperties);
var lineItem = cartAggregate.Cart.Items.FirstOrDefault(x => x.Id.Equals(request.LineItemId));
var priceAdjustment = new PriceAdjustment
{
LineItem = lineItem,
LineItemId = request.LineItemId,
NewPrice = request.Price
};
await cartAggregate.ChangeItemPriceAsync(priceAdjustment);
return await SaveCartAsync(cartAggregate);
}
Thanks in advance !