/// <summary> /// Prepare the customer order list model /// </summary> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the customer order list model /// </returns> public virtual async Task <CustomerOrderListModel> PrepareCustomerOrderListModelAsync() { var model = new CustomerOrderListModel(); var customer = await _workContext.GetCurrentCustomerAsync(); var store = await _storeContext.GetCurrentStoreAsync(); var orders = await _orderService.SearchOrdersAsync(storeId : store.Id, customerId : customer.Id); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = await _localizationService.GetLocalizedEnumAsync(order.OrderStatus), PaymentStatus = await _localizationService.GetLocalizedEnumAsync(order.PaymentStatus), ShippingStatus = await _localizationService.GetLocalizedEnumAsync(order.ShippingStatus), IsReturnRequestAllowed = await _orderProcessingService.IsReturnRequestAllowedAsync(order), CustomOrderNumber = order.CustomOrderNumber }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = await _priceFormatter.FormatPriceAsync(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, (await _workContext.GetWorkingLanguageAsync()).Id); model.Orders.Add(orderModel); } var recurringPayments = await _orderService.SearchRecurringPaymentsAsync(store.Id, customer.Id); foreach (var recurringPayment in recurringPayments) { var order = await _orderService.GetOrderByIdAsync(recurringPayment.InitialOrderId); var recurringPaymentModel = new CustomerOrderListModel.RecurringOrderModel { Id = recurringPayment.Id, StartDate = (await _dateTimeHelper.ConvertToUserTimeAsync(recurringPayment.StartDateUtc, DateTimeKind.Utc)).ToString(), CycleInfo = $"{recurringPayment.CycleLength} {await _localizationService.GetLocalizedEnumAsync(recurringPayment.CyclePeriod)}", NextPayment = await _orderProcessingService.GetNextPaymentDateAsync(recurringPayment) is DateTime nextPaymentDate ? (await _dateTimeHelper.ConvertToUserTimeAsync(nextPaymentDate, DateTimeKind.Utc)).ToString() : "", TotalCycles = recurringPayment.TotalCycles, CyclesRemaining = await _orderProcessingService.GetCyclesRemainingAsync(recurringPayment), InitialOrderId = order.Id, InitialOrderNumber = order.CustomOrderNumber, CanCancel = await _orderProcessingService.CanCancelRecurringPaymentAsync(customer, recurringPayment), CanRetryLastPayment = await _orderProcessingService.CanRetryLastRecurringPaymentAsync(customer, recurringPayment) }; model.RecurringOrders.Add(recurringPaymentModel); } return(model); }