public async Task Run(TaxEvaluationContext parameter, Func <TaxEvaluationContext, Task> next) { if (!string.IsNullOrEmpty(parameter.CustomerId)) { var member = await _memberIdResolver.ResolveMemberByIdAsync(parameter.CustomerId); if (member != null && member is Contact contact) { parameter.Customer = _mapper.Map <Customer>(contact); } } await next(parameter); }
public virtual async Task TryToSendOrderNotificationsAsync(OrderNotificationJobArgument[] jobArguments) { var ordersByIdDict = (await _customerOrderService.GetAsync(jobArguments.Select(x => x.CustomerOrderId).Distinct().ToList())) .ToDictionary(x => x.Id) .WithDefaultValue(null); foreach (var jobArgument in jobArguments) { var notification = await _notificationSearchService.GetNotificationAsync(jobArgument.NotificationTypeName, new TenantIdentity(jobArgument.StoreId, nameof(Store))); if (notification != null) { var order = ordersByIdDict[jobArgument.CustomerOrderId]; if (order != null && notification is CustomerReviewEmailNotification orderNotification) { var customer = await _memberResolver.ResolveMemberByIdAsync(jobArgument.CustomerId); orderNotification.Item = order.Items.FirstOrDefault(i => i.ProductId == jobArgument.ProductId); orderNotification.Customer = customer; orderNotification.RequestId = jobArgument.RequestId; orderNotification.LanguageCode = order.LanguageCode; await SetNotificationParametersAsync(notification, order, customer); await _notificationSender.ScheduleSendNotificationAsync(notification); } } } }
protected virtual async Task <CartAggregate> InnerGetCartAggregateFromCartAsync(ShoppingCart cart, string language, CartAggregateResponseGroup responseGroup = CartAggregateResponseGroup.Full) { if (cart == null) { throw new ArgumentNullException(nameof(cart)); } var storeLoadTask = _storeService.GetByIdAsync(cart.StoreId); var allCurrenciesLoadTask = _currencyService.GetAllCurrenciesAsync(); await Task.WhenAll(storeLoadTask, allCurrenciesLoadTask); var store = storeLoadTask.Result; var allCurrencies = allCurrenciesLoadTask.Result; if (store == null) { throw new OperationCanceledException($"store with id {cart.StoreId} not found"); } if (string.IsNullOrEmpty(cart.Currency)) { cart.Currency = store.DefaultCurrency; } var currency = allCurrencies.GetCurrencyForLanguage(cart.Currency, language ?? store.DefaultLanguage); var member = await _memberResolver.ResolveMemberByIdAsync(cart.CustomerId); var aggregate = _cartAggregateFactory(); aggregate.GrabCart(cart, store, member, currency); //Load cart products explicitly if no validation is requested var cartProducts = await _cartProductsService.GetCartProductsByIdsAsync(aggregate, aggregate.Cart.Items.Select(x => x.ProductId).ToArray()); //Populate aggregate.CartProducts with the products data for all cart line items foreach (var cartProduct in cartProducts) { aggregate.CartProducts[cartProduct.Id] = cartProduct; } foreach (var lineItem in aggregate.LineItems) { var cartProduct = aggregate.CartProducts[lineItem.ProductId]; await aggregate.SetItemFulfillmentCenterAsync(lineItem, cartProduct); } await aggregate.RecalculateAsync(); return(aggregate); }
protected virtual async Task <CartAggregate> InnerGetCartAggregateFromCartAsync(ShoppingCart cart, string language) { if (cart == null) { throw new ArgumentNullException(nameof(cart)); } var storeLoadTask = _storeService.GetByIdAsync(cart.StoreId); var allCurrenciesLoadTask = _currencyService.GetAllCurrenciesAsync(); await Task.WhenAll(storeLoadTask, allCurrenciesLoadTask); var store = storeLoadTask.Result; var allCurrencies = allCurrenciesLoadTask.Result; if (store == null) { throw new OperationCanceledException($"store with id {cart.StoreId} not found"); } if (string.IsNullOrEmpty(cart.Currency)) { cart.Currency = store.DefaultCurrency; } var currency = allCurrencies.GetCurrencyForLanguage(cart.Currency, language ?? store.DefaultLanguage); var member = await _memberResolver.ResolveMemberByIdAsync(cart.CustomerId); var aggregate = _cartAggregateFactory(); aggregate.GrabCart(cart, store, member, currency); var validationContext = await _cartValidationContextFactory.CreateValidationContextAsync(aggregate); //Populate aggregate.CartProducts with the products data for all cart line items foreach (var cartProduct in validationContext.AllCartProducts) { aggregate.CartProducts[cartProduct.Id] = cartProduct; } await aggregate.RecalculateAsync(); //Run validation await aggregate.ValidateAsync(validationContext); return(aggregate); }