/// <summary> /// Prepare the customer order list model /// </summary> /// <returns>Customer order list model</returns> public override CustomerOrderListModel PrepareCustomerOrderListModel() { //_logger.Information("Entered PrepareCustomerOrderListModel"); CustomerOrderListModel model = new CustomerOrderListModel(); // string colmJSON = JsonConvert.SerializeObject(model, Formatting.Indented); List <CustomerOrderListModel.OrderDetailsModel> legacyOrders = null; try { model = base.PrepareCustomerOrderListModel(); var miscPlugins = _pluginFinder.GetPlugins <MyOrderServicePlugin>(storeId: EngineContext.Current.Resolve <IStoreContext>().CurrentStore.Id).ToList(); if (miscPlugins.Count > 0 && _gbsOrderSettings.LegacyOrdersInOrderHistory) { legacyOrders = new Orders.OrderExtensions().getLegacyOrders(); //_logger.Information("Trace - legacyOrders.count = " + (legacyOrders != null ? Convert.ToString(legacyOrders.Count()) : "NULL")); if (legacyOrders != null && legacyOrders.Count() > 0) { ((List <CustomerOrderListModel.OrderDetailsModel>)model.Orders).AddRange(legacyOrders); //_logger.Information("added range to orders"); } ((List <CustomerOrderListModel.OrderDetailsModel>)model.Orders).Sort((x, y) => y.CreatedOn.CompareTo(x.CreatedOn)); //_logger.Information("sorted orders"); } } catch (Exception ex) { var customer = _workContext.CurrentCustomer; _logger.Error("Error in PrepareCustomerOrderListModel() - legacyOrders.count = " + (legacyOrders != null ? Convert.ToString(legacyOrders.Count()) : "NULL"), ex, customer); } return(model); }
protected CustomerOrderListModel PrepareCustomerOrderListModel(CustomerOrderPagingFilteringModel command) { int?orderId = null; if (!string.IsNullOrEmpty(command.q)) { int temp = 0; if (int.TryParse(command.q, out temp)) { orderId = temp; } } var profileId = _workContext.CurrentProfile.Id; var model = new CustomerOrderListModel(); var result = _orderService.GetPagedOrderOverviewModel( pageIndex: command.PageNumber - 1, pageSize: command.PageSize, profileIds: new int[] { profileId }, orderIds: orderId.HasValue ? new int[] { orderId.Value } : null, statusCodes: ValidOrderStatus.VALID_CUSTOMER_STATUSES, orderBy: OrderSortingType.OrderPlacedDesc); for (int i = 0; i < result.Items.Count; i++) { var order = result.Items[i]; var orderModel = new OrderSummaryModel { Id = order.Id, CreatedOn = order.OrderPlaced.Value, OrderStatusCode = order.StatusCode, OrderStatus = order.OrderStatus }; // To avoid customer frustration, ON HOLD will be changed to ORDER PLACED if (orderModel.OrderStatusCode == OrderStatusCode.ON_HOLD) { orderModel.OrderStatusCode = OrderStatusCode.ORDER_PLACED; orderModel.OrderStatus = _orderService.GetOrderStatusByCode(OrderStatusCode.ORDER_PLACED); } orderModel.OrderTotal = _priceFormatter.FormatValue(order.GrandTotal, order.CurrencyCode); model.Orders.Add(orderModel); } model.PagingFilteringContext.LoadPagedList(result); model.PagingFilteringContext.q = command.q; if (model.Orders.Count > 0) { model.Orders[0].Chosen = true; } return(model); }
/// <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); }
/// <summary> /// Prepare the customer order list model /// </summary> /// <returns>Customer order list model</returns> public virtual CustomerOrderListModel PrepareCustomerOrderListModel() { var model = new CustomerOrderListModel(); var orders = _orderService.SearchOrders(storeId: _storeContext.CurrentStore.Id, customerId: _workContext.CurrentCustomer.Id); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext), PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext), ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext), IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order), CustomOrderNumber = order.CustomOrderNumber, // ++ CanCancelOrderForCustomer CanCancelOrder = _orderProcessingService.CanCancelOrderForCustomer(order), }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); model.Orders.Add(orderModel); } var recurringPayments = _orderService.SearchRecurringPayments(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id); foreach (var recurringPayment in recurringPayments) { var recurringPaymentModel = new CustomerOrderListModel.RecurringOrderModel { Id = recurringPayment.Id, StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(), CycleInfo = $"{recurringPayment.CycleLength} {recurringPayment.CyclePeriod.GetLocalizedEnum(_localizationService, _workContext)}", NextPayment = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : "", TotalCycles = recurringPayment.TotalCycles, CyclesRemaining = recurringPayment.CyclesRemaining, InitialOrderId = recurringPayment.InitialOrder.Id, InitialOrderNumber = recurringPayment.InitialOrder.CustomOrderNumber, CanCancel = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment), CanRetryLastPayment = _orderProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment) }; model.RecurringOrders.Add(recurringPaymentModel); } return(model); }
/// <summary> /// Prepare the customer order list model /// </summary> /// <returns>Customer order list model</returns> public virtual CustomerOrderListModel PrepareCustomerOrderListModel() { var model = new CustomerOrderListModel(); var orders = _orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext), PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext), CustomOrderNumber = order.CustomOrderNumber }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage); model.Orders.Add(orderModel); } return(model); }
/// <summary> /// Prepare the customer order list model /// </summary> /// <returns>Customer order list model</returns> public virtual CustomerOrderListModel PrepareCustomerOrderListModel(int?page) { var model = new CustomerOrderListModel(); var pageSize = 5; var orders = _orderService.SearchOrders(storeId: _storeContext.CurrentStore.Id, customerId: _workContext.CurrentCustomer.Id, pageIndex: --page ?? 0, pageSize: pageSize); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = _localizationService.GetLocalizedEnum(order.OrderStatus), PaymentStatus = _localizationService.GetLocalizedEnum(order.PaymentStatus), ShippingStatus = _localizationService.GetLocalizedEnum(order.ShippingStatus), IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order), CustomOrderNumber = order.CustomOrderNumber }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); model.Orders.Add(orderModel); } model.PagerModel = new PagerModel { PageSize = orders.PageSize, TotalRecords = orders.TotalCount, PageIndex = orders.PageIndex, ShowTotalSummary = false, RouteActionName = "CustomerOrdersListPaged", UseRouteLinks = true, RouteValues = new OrdersListRouteValues { pageNumber = page ?? 0 } }; var recurringPayments = _orderService.SearchRecurringPayments(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id); foreach (var recurringPayment in recurringPayments) { var recurringPaymentModel = new CustomerOrderListModel.RecurringOrderModel { Id = recurringPayment.Id, StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(), CycleInfo = $"{recurringPayment.CycleLength} {_localizationService.GetLocalizedEnum(recurringPayment.CyclePeriod)}", NextPayment = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : "", TotalCycles = recurringPayment.TotalCycles, CyclesRemaining = recurringPayment.CyclesRemaining, InitialOrderId = recurringPayment.InitialOrder.Id, InitialOrderNumber = recurringPayment.InitialOrder.CustomOrderNumber, CanCancel = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment), CanRetryLastPayment = _orderProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment) }; model.RecurringOrders.Add(recurringPaymentModel); } return(model); }
/// <summary> /// Prepare the customer order list model /// </summary> /// <returns>Customer order list model</returns> public virtual CustomerOrderListModel PrepareCustomerOrderListModel(string status, int?page, int?pageSize) { if (page == 0) { page = null; } List <int> statusList = new List <int>(); if (!string.IsNullOrEmpty(status)) { if (status == ((int)OrderStatus.Cancelled).ToString()) { statusList.Add((int)OrderStatus.Cancelled); } if (status == ((int)OrderStatus.Pending).ToString()) { statusList.Add((int)OrderStatus.Pending); statusList.Add((int)OrderStatus.Processing); } } var model = new CustomerOrderListModel(); var orders = _orderService.SearchOrders(storeId: _storeContext.CurrentStore.Id, customerId: _workContext.CurrentCustomer.Id, osIds: statusList); //pageIndex: --page ?? 0, pageSize: 5, List <CustomerOrderListModel.OrderDetailsModel> allOrders = new List <CustomerOrderListModel.OrderDetailsModel>(); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext), PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext), ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext), IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order), CustomOrderNumber = order.CustomOrderNumber }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); allOrders.Add(orderModel); } List <CustomerOrderListModel.OrderDetailsModel> legacyOrders = null; var miscPlugins = _pluginFinder.GetPlugins <MyOrderServicePlugin>(storeId: EngineContext.Current.Resolve <IStoreContext>().CurrentStore.Id).ToList(); if (miscPlugins.Count > 0 && _gbsOrderSettings.LegacyOrdersInOrderHistory) { legacyOrders = new Orders.OrderExtensions().getLegacyOrders(); if (!string.IsNullOrEmpty(status)) { legacyOrders = legacyOrders.Where(x => statusList.Contains((int)x.OrderStatusEnum)).ToList(); } if (legacyOrders != null && legacyOrders.Count() > 0) { allOrders.AddRange(legacyOrders); } allOrders.Sort((x, y) => y.CreatedOn.CompareTo(x.CreatedOn)); } var ordersPaging = new PagedList <CustomerOrderListModel.OrderDetailsModel>(allOrders, pageIndex: --page ?? 0, pageSize: pageSize ?? 5); model.Orders = ordersPaging.ToList(); // do paging on orders var recurringPayments = _orderService.SearchRecurringPayments(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id); foreach (var recurringPayment in recurringPayments) { var recurringPaymentModel = new CustomerOrderListModel.RecurringOrderModel { Id = recurringPayment.Id, StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(), CycleInfo = string.Format("{0} {1}", recurringPayment.CycleLength, recurringPayment.CyclePeriod.GetLocalizedEnum(_localizationService, _workContext)), NextPayment = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : "", TotalCycles = recurringPayment.TotalCycles, CyclesRemaining = recurringPayment.CyclesRemaining, InitialOrderId = recurringPayment.InitialOrder.Id, InitialOrderNumber = recurringPayment.InitialOrder.CustomOrderNumber, CanCancel = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment), CanRetryLastPayment = _orderProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment) }; model.RecurringOrders.Add(recurringPaymentModel); } model.CustomProperties["PagerModel"] = new PagerModel { PageSize = ordersPaging.PageSize, TotalRecords = ordersPaging.TotalCount, PageIndex = ordersPaging.PageIndex, ShowTotalSummary = true, RouteActionName = "CustomerOrders", UseRouteLinks = true, RouteValues = new OrderRouteValues { page = page ?? 0, status = status, pageSize = pageSize } }; if (model.Orders.Any()) { model.Orders.FirstOrDefault().CustomProperties["PagerModel"] = new PagerModel { PageSize = ordersPaging.PageSize, TotalRecords = ordersPaging.TotalCount, PageIndex = ordersPaging.PageIndex, ShowTotalSummary = true, RouteActionName = "CustomerOrders", UseRouteLinks = true, RouteValues = new OrderRouteValues { page = page ?? 0, status = status, pageSize = pageSize } }; } return(model); }
public async Task <IActionResult> GetUpcomingOrders() { var customer = await _workContext.GetCurrentCustomerAsync(); var orders = await _orderService.SearchOrdersAsync(customerId : customer.Id); var perviousOrders = orders.Where(x => x.ScheduleDate.Date > DateTime.Now.Date); if (perviousOrders.Any()) { var languageId = _workContext.GetWorkingLanguageAsync().Id; var model = new CustomerOrderListModel(); foreach (var order in perviousOrders) { 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, ScheduleDate = await _dateTimeHelper.ConvertToUserTimeAsync(order.ScheduleDate, DateTimeKind.Utc), Rating = order.Rating, RatingText = order.RatingText }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = await _priceFormatter.FormatPriceAsync(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.GetWorkingLanguageAsync().Id); var orderItems = await _orderService.GetOrderItemsAsync(order.Id); foreach (var orderItem in orderItems) { var product = await _productService.GetProductByIdAsync(orderItem.ProductId); var productPicture = await _pictureService.GetPicturesByProductIdAsync(orderItem.ProductId); var vendor = await _vendorService.GetVendorByProductIdAsync(product.Id); var orderItemModel = new OrderDetailsModel.OrderItemModel { Id = orderItem.Id, OrderItemGuid = orderItem.OrderItemGuid, Sku = await _productService.FormatSkuAsync(product, orderItem.AttributesXml), VendorName = vendor != null ? vendor.Name : string.Empty, ProductId = product.Id, ProductName = await _localizationService.GetLocalizedAsync(product, x => x.Name), ProductPictureUrl = productPicture.Any() ? await _pictureService.GetPictureUrlAsync(productPicture.FirstOrDefault().Id) : await _pictureService.GetDefaultPictureUrlAsync(), ProductSeName = await _urlRecordService.GetSeNameAsync(product), Quantity = orderItem.Quantity, AttributeInfo = orderItem.AttributeDescription, VendorLogoPictureUrl = await _pictureService.GetPictureUrlAsync(vendor != null?vendor.PictureId : 0, showDefaultPicture : true) }; //rental info if (product.IsRental) { var rentalStartDate = orderItem.RentalStartDateUtc.HasValue ? _productService.FormatRentalDate(product, orderItem.RentalStartDateUtc.Value) : ""; var rentalEndDate = orderItem.RentalEndDateUtc.HasValue ? _productService.FormatRentalDate(product, orderItem.RentalEndDateUtc.Value) : ""; orderItemModel.RentalInfo = string.Format(await _localizationService.GetResourceAsync("Order.Rental.FormattedDate"), rentalStartDate, rentalEndDate); } orderModel.Items.Add(orderItemModel); //unit price, subtotal if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate); orderItemModel.UnitPrice = await _priceFormatter.FormatPriceAsync(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, languageId, true); var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceInclTax, order.CurrencyRate); orderItemModel.SubTotal = await _priceFormatter.FormatPriceAsync(priceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, languageId, true); } else { //excluding tax var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate); orderItemModel.UnitPrice = await _priceFormatter.FormatPriceAsync(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, languageId, false); var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceExclTax, order.CurrencyRate); orderItemModel.SubTotal = await _priceFormatter.FormatPriceAsync(priceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, languageId, false); } //downloadable products if (await _orderService.IsDownloadAllowedAsync(orderItem)) { orderItemModel.DownloadId = product.DownloadId; } if (await _orderService.IsLicenseDownloadAllowedAsync(orderItem)) { orderItemModel.LicenseId = orderItem.LicenseDownloadId ?? 0; } } model.Orders.Add(orderModel); } return(Ok(new { success = true, model })); } return(Ok(new { success = false, message = "No upcoming order found" })); }