Ejemplo n.º 1
0
        /// <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);
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task<IActionResult> ReturnRequest(int orderId)
        {
            var order = await _orderService.GetOrderByIdAsync(orderId);
            if (order == null || order.Deleted || (await _workContext.GetCurrentCustomerAsync()).Id != order.CustomerId)
                return Challenge();

            if (!await _orderProcessingService.IsReturnRequestAllowedAsync(order))
                return RedirectToRoute("Homepage");

            var model = new SubmitReturnRequestModel();
            model = await _returnRequestModelFactory.PrepareSubmitReturnRequestModelAsync(model, order);
            return View(model);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetTodaysOrders()
        {
            var customer = await _workContext.GetCurrentCustomerAsync();

            var orders = await _orderService.SearchOrdersAsync(customerId : customer.Id);

            var perviousOrders = orders.Where(x => x.ScheduleDate.Date == DateTime.Now.Date).ToList();

            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,
                        ScheduleDate           = await _dateTimeHelper.ConvertToUserTimeAsync(order.ScheduleDate, DateTimeKind.Utc),
                        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,
                        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,
                            ProductPictureUrl    = productPicture.Any() ? await _pictureService.GetPictureUrlAsync(productPicture.FirstOrDefault().Id) : await _pictureService.GetDefaultPictureUrlAsync(),
                            ProductName          = await _localizationService.GetLocalizedAsync(product, x => x.Name),
                            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 previous order found" }));
        }