public ActionResult ReturnRequest(int orderId) { var order = _orderService.GetOrderById(orderId); if (order == null || order.Deleted || _workContext.CurrentCustomer.Id != order.CustomerId) { return(new HttpUnauthorizedResult()); } if (!_orderProcessingService.IsReturnRequestAllowed(order)) { return(RedirectToRoute("HomePage")); } var model = new SubmitReturnRequestModel(); model = PrepareReturnRequestModel(model, order); return(View(model)); }
public virtual IActionResult ReturnRequest(string orderId, string errors = "") { var order = _orderService.GetOrderById(orderId); if (order == null || order.Deleted || _workContext.CurrentCustomer.Id != order.CustomerId) { return(Challenge()); } if (!_orderProcessingService.IsReturnRequestAllowed(order)) { return(RedirectToRoute("HomePage")); } var model = new SubmitReturnRequestModel(); model = _returnRequestViewModelService.PrepareReturnRequest(model, order); model.Error = errors; return(View(model)); }
public async Task <IActionResult> ReturnRequest(int id /* orderId */) { var order = await _db.Orders .Include(x => x.OrderItems) .ThenInclude(x => x.Product) .FindByIdAsync(id); if (order == null || Services.WorkContext.CurrentCustomer.Id != order.CustomerId) { return(new UnauthorizedResult()); } if (!_orderProcessingService.IsReturnRequestAllowed(order)) { return(RedirectToRoute("Homepage")); } var model = new SubmitReturnRequestModel(); model = await PrepareReturnRequestModelAsync(model, order); return(View(model)); }
private async Task PrepareOrder(CustomerOrderListModel model, GetCustomerOrderList request) { var orders = await _orderService.SearchOrders(storeId : request.Store.Id, customerId : request.Customer.Id); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, OrderNumber = order.OrderNumber, CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, request.Language.Id), PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, request.Language.Id), ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, request.Language.Id), IsReturnRequestAllowed = await _orderProcessingService.IsReturnRequestAllowed(order) }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = await _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, request.Language); model.Orders.Add(orderModel); } }
protected OrderDetailsModel PrepareOrderDetailsModel(Order order) { if (order == null) { throw new ArgumentNullException("order"); } var model = new OrderDetailsModel(); model.Id = order.Id; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc); model.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext); model.IsReOrderAllowed = _orderSettings.IsReOrderAllowed; model.IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order); model.DisplayPdfInvoice = _pdfSettings.Enabled; //shipping info model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext); if (order.ShippingStatus != ShippingStatus.ShippingNotRequired) { model.IsShippable = true; model.ShippingAddress = order.ShippingAddress.ToModel(); model.ShippingMethod = order.ShippingMethod; model.OrderWeight = order.OrderWeight; var baseWeight = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId); if (baseWeight != null) { model.BaseWeightIn = baseWeight.Name; } //shipments var shipments = order.Shipments.OrderBy(x => x.ShippedDateUtc).ToList(); foreach (var shipment in shipments) { var shipmentModel = new OrderDetailsModel.ShipmentBriefModel() { Id = shipment.Id, TrackingNumber = shipment.TrackingNumber, ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc, DateTimeKind.Utc), }; if (shipment.DeliveryDateUtc.HasValue) { shipmentModel.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); } model.Shipments.Add(shipmentModel); } } //billing info model.BillingAddress = order.BillingAddress.ToModel(); //VAT number model.VatNumber = order.VatNumber; //payment method var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); model.PaymentMethod = paymentMethod != null?paymentMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id) : order.PaymentMethodSystemName; model.CanRePostProcessPayment = _paymentService.CanRePostProcessPayment(order); //totals) switch (order.CustomerTaxDisplayType) { case TaxDisplayType.ExcludingTax: { //order subtotal var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); //discount (applied to order subtotal) var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate); if (orderSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } //order shipping var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); //payment method additional fee var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeExclTaxInCustomerCurrency > decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } } break; case TaxDisplayType.IncludingTax: { //order subtotal var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); //discount (applied to order subtotal) var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate); if (orderSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } //order shipping var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); //payment method additional fee var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeInclTaxInCustomerCurrency > decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } } break; } //tax bool displayTax = true; bool displayTaxRates = true; if (_taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { displayTax = false; displayTaxRates = false; } else { if (order.OrderTax == 0 && _taxSettings.HideZeroTax) { displayTax = false; displayTaxRates = false; } else { displayTaxRates = _taxSettings.DisplayTaxRates && order.TaxRatesDictionary.Count > 0; displayTax = !displayTaxRates; var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate); //TODO pass languageId to _priceFormatter.FormatPrice model.Tax = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); foreach (var tr in order.TaxRatesDictionary) { model.TaxRates.Add(new OrderDetailsModel.TaxRate() { Rate = _priceFormatter.FormatTaxRate(tr.Key), //TODO pass languageId to _priceFormatter.FormatPrice Value = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(tr.Value, order.CurrencyRate), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage), }); } } } model.DisplayTaxRates = displayTaxRates; model.DisplayTax = displayTax; //discount (applied to order total) var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate); if (orderDiscountInCustomerCurrency > decimal.Zero) { model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); } //gift cards foreach (var gcuh in order.GiftCardUsageHistory) { model.GiftCards.Add(new OrderDetailsModel.GiftCard() { CouponCode = gcuh.GiftCard.GiftCardCouponCode, Amount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage), }); } //reward points if (order.RedeemedRewardPointsEntry != null) { model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points; model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); } //total var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); model.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); //checkout attributes model.CheckoutAttributeInfo = order.CheckoutAttributeDescription; //order notes foreach (var orderNote in order.OrderNotes .Where(on => on.DisplayToCustomer) .OrderByDescending(on => on.CreatedOnUtc) .ToList()) { model.OrderNotes.Add(new OrderDetailsModel.OrderNote() { Note = orderNote.FormatOrderNoteText(), CreatedOn = _dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc) }); } //purchased products model.ShowSku = _catalogSettings.ShowProductSku; var orderProductVariants = _orderService.GetAllOrderProductVariants(order.Id, null, null, null, null, null, null); foreach (var opv in orderProductVariants) { var opvModel = new OrderDetailsModel.OrderProductVariantModel() { Id = opv.Id, Sku = opv.ProductVariant.Sku, ProductId = opv.ProductVariant.ProductId, ProductSeName = opv.ProductVariant.Product.GetSeName(), Quantity = opv.Quantity, AttributeInfo = opv.AttributeDescription, }; //product name if (!String.IsNullOrEmpty(opv.ProductVariant.GetLocalized(x => x.Name))) { opvModel.ProductName = string.Format("{0} ({1})", opv.ProductVariant.Product.GetLocalized(x => x.Name), opv.ProductVariant.GetLocalized(x => x.Name)); } else { opvModel.ProductName = opv.ProductVariant.Product.GetLocalized(x => x.Name); } model.Items.Add(opvModel); //unit price, subtotal switch (order.CustomerTaxDisplayType) { case TaxDisplayType.ExcludingTax: { var opvUnitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(opv.UnitPriceExclTax, order.CurrencyRate); opvModel.UnitPrice = _priceFormatter.FormatPrice(opvUnitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); var opvPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(opv.PriceExclTax, order.CurrencyRate); opvModel.SubTotal = _priceFormatter.FormatPrice(opvPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } break; case TaxDisplayType.IncludingTax: { var opvUnitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(opv.UnitPriceInclTax, order.CurrencyRate); opvModel.UnitPrice = _priceFormatter.FormatPrice(opvUnitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); var opvPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(opv.PriceInclTax, order.CurrencyRate); opvModel.SubTotal = _priceFormatter.FormatPrice(opvPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } break; } } 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); }
protected virtual OrderDetailsModel PrepareOrderDetailsModel(Order order) { if (order == null) { throw new ArgumentNullException("order"); } var model = new OrderDetailsModel(); model.Id = order.Id; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc); model.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext); model.IsReOrderAllowed = _orderSettings.IsReOrderAllowed; model.IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order); //shipping info model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext); if (order.ShippingStatus != ShippingStatus.ShippingNotRequired) { model.IsShippable = true; model.PickUpInStore = order.PickUpInStore; if (!order.PickUpInStore) { model.ShippingAddress.PrepareModel(order.ShippingAddress, false, _addressSettings); } model.ShippingMethod = order.ShippingMethod; //shipments (only already shipped) var shipments = order.Shipments.Where(x => x.ShippedDateUtc.HasValue).OrderBy(x => x.CreatedOnUtc).ToList(); foreach (var shipment in shipments) { var shipmentModel = new OrderDetailsModel.ShipmentBriefModel() { Id = shipment.Id, TrackingNumber = shipment.TrackingNumber, }; if (shipment.ShippedDateUtc.HasValue) { shipmentModel.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc); } if (shipment.DeliveryDateUtc.HasValue) { shipmentModel.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); } model.Shipments.Add(shipmentModel); } } //billing info model.BillingAddress.PrepareModel(order.BillingAddress, false, _addressSettings); //VAT number model.VatNumber = order.VatNumber; //payment method var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); model.PaymentMethod = paymentMethod != null?paymentMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id) : order.PaymentMethodSystemName; model.CanRePostProcessPayment = _paymentService.CanRePostProcessPayment(order); //purchase order number (we have to find a better to inject this information because it's related to a certain plugin) if (paymentMethod != null && paymentMethod.PluginDescriptor.SystemName.Equals("Payments.PurchaseOrder", StringComparison.InvariantCultureIgnoreCase)) { model.DisplayPurchaseOrderNumber = true; model.PurchaseOrderNumber = order.PurchaseOrderNumber; } //order subtotal if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal) { //including tax //order subtotal var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); //discount (applied to order subtotal) var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate); if (orderSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } } else { //excluding tax //order subtotal var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); //discount (applied to order subtotal) var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate); if (orderSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } } if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax //order shipping var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); //payment method additional fee var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeInclTaxInCustomerCurrency > decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } } else { //excluding tax //order shipping var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); //payment method additional fee var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeExclTaxInCustomerCurrency > decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } } //tax bool displayTax = true; bool displayTaxRates = true; if (_taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { displayTax = false; displayTaxRates = false; } else { if (order.OrderTax == 0 && _taxSettings.HideZeroTax) { displayTax = false; displayTaxRates = false; } else { displayTaxRates = _taxSettings.DisplayTaxRates && order.TaxRatesDictionary.Count > 0; displayTax = !displayTaxRates; var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate); //TODO pass languageId to _priceFormatter.FormatPrice model.Tax = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); foreach (var tr in order.TaxRatesDictionary) { model.TaxRates.Add(new OrderDetailsModel.TaxRate() { Rate = _priceFormatter.FormatTaxRate(tr.Key), //TODO pass languageId to _priceFormatter.FormatPrice Value = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(tr.Value, order.CurrencyRate), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage), }); } } } model.DisplayTaxRates = displayTaxRates; model.DisplayTax = displayTax; //discount (applied to order total) var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate); if (orderDiscountInCustomerCurrency > decimal.Zero) { model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); } //gift cards foreach (var gcuh in order.GiftCardUsageHistory) { model.GiftCards.Add(new OrderDetailsModel.GiftCard() { CouponCode = gcuh.GiftCard.GiftCardCouponCode, Amount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage), }); } //reward points if (order.RedeemedRewardPointsEntry != null) { model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points; model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); } //total var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); model.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); //checkout attributes model.CheckoutAttributeInfo = order.CheckoutAttributeDescription; //order notes foreach (var orderNote in order.OrderNotes .Where(on => on.DisplayToCustomer) .OrderByDescending(on => on.CreatedOnUtc) .ToList()) { model.OrderNotes.Add(new OrderDetailsModel.OrderNote() { Id = orderNote.Id, HasDownload = orderNote.DownloadId > 0, Note = orderNote.FormatOrderNoteText(), CreatedOn = _dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc) }); } //purchased products model.ShowSku = _catalogSettings.ShowProductSku; var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null); foreach (var orderItem in orderItems) { var orderItemModel = new OrderDetailsModel.OrderItemModel() { Id = orderItem.Id, Sku = orderItem.Product.FormatSku(orderItem.AttributesXml, _productAttributeParser), ProductId = orderItem.Product.Id, ProductName = orderItem.Product.GetLocalized(x => x.Name), ProductSeName = orderItem.Product.GetSeName(), Quantity = orderItem.Quantity, AttributeInfo = orderItem.AttributeDescription, }; model.Items.Add(orderItemModel); //unit price, subtotal if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate); orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceInclTax, order.CurrencyRate); orderItemModel.SubTotal = _priceFormatter.FormatPrice(priceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } else { //excluding tax var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate); orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceExclTax, order.CurrencyRate); orderItemModel.SubTotal = _priceFormatter.FormatPrice(priceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } } return(model); }
public OrderDetailsModel PrepareOrderDetailsModel(Order order) { Guard.NotNull(order, nameof(order)); var store = _services.StoreService.GetStoreById(order.StoreId) ?? _services.StoreContext.CurrentStore; var language = _services.WorkContext.WorkingLanguage; var orderSettings = _services.Settings.LoadSetting <OrderSettings>(store.Id); var catalogSettings = _services.Settings.LoadSetting <CatalogSettings>(store.Id); var taxSettings = _services.Settings.LoadSetting <TaxSettings>(store.Id); var pdfSettings = _services.Settings.LoadSetting <PdfSettings>(store.Id); var addressSettings = _services.Settings.LoadSetting <AddressSettings>(store.Id); var companyInfoSettings = _services.Settings.LoadSetting <CompanyInformationSettings>(store.Id); var shoppingCartSettings = _services.Settings.LoadSetting <ShoppingCartSettings>(store.Id); var mediaSettings = _services.Settings.LoadSetting <MediaSettings>(store.Id); var model = new OrderDetailsModel(); model.MerchantCompanyInfo = companyInfoSettings; model.Id = order.Id; model.StoreId = order.StoreId; model.CustomerLanguageId = order.CustomerLanguageId; model.CustomerComment = order.CustomerOrderComment; model.OrderNumber = order.GetOrderNumber(); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc); model.OrderStatus = order.OrderStatus.GetLocalizedEnum(_services.Localization, _services.WorkContext); model.IsReOrderAllowed = orderSettings.IsReOrderAllowed; model.IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order); model.DisplayPdfInvoice = pdfSettings.Enabled; model.RenderOrderNotes = pdfSettings.RenderOrderNotes; // Shipping info. model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_services.Localization, _services.WorkContext); if (order.ShippingStatus != ShippingStatus.ShippingNotRequired) { model.IsShippable = true; model.ShippingAddress.PrepareModel(order.ShippingAddress, false, addressSettings); model.ShippingMethod = order.ShippingMethod; // Shipments (only already shipped). var shipments = order.Shipments.Where(x => x.ShippedDateUtc.HasValue).OrderBy(x => x.CreatedOnUtc).ToList(); foreach (var shipment in shipments) { var shipmentModel = new OrderDetailsModel.ShipmentBriefModel { Id = shipment.Id, TrackingNumber = shipment.TrackingNumber, }; if (shipment.ShippedDateUtc.HasValue) { shipmentModel.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc); } if (shipment.DeliveryDateUtc.HasValue) { shipmentModel.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); } model.Shipments.Add(shipmentModel); } } model.BillingAddress.PrepareModel(order.BillingAddress, false, addressSettings); model.VatNumber = order.VatNumber; // Payment method. var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); model.PaymentMethod = paymentMethod != null?_pluginMediator.GetLocalizedFriendlyName(paymentMethod.Metadata) : order.PaymentMethodSystemName; model.CanRePostProcessPayment = _paymentService.CanRePostProcessPayment(order); // Purchase order number (we have to find a better to inject this information because it's related to a certain plugin). if (paymentMethod != null && paymentMethod.Metadata.SystemName.Equals("SmartStore.PurchaseOrderNumber", StringComparison.InvariantCultureIgnoreCase)) { model.DisplayPurchaseOrderNumber = true; model.PurchaseOrderNumber = order.PurchaseOrderNumber; } // Totals. switch (order.CustomerTaxDisplayType) { case TaxDisplayType.ExcludingTax: { // Order subtotal. var orderSubtotalExclTax = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalExclTax, true, order.CustomerCurrencyCode, language, false, false); // Discount (applied to order subtotal). var orderSubTotalDiscountExclTax = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate); if (orderSubTotalDiscountExclTax > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTax, true, order.CustomerCurrencyCode, language, false, false); } // Order shipping. var orderShippingExclTax = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingExclTax, true, order.CustomerCurrencyCode, language, false, false); // Payment method additional fee. var paymentMethodAdditionalFeeExclTax = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeExclTax != decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTax, true, order.CustomerCurrencyCode, language, false, false); } } break; case TaxDisplayType.IncludingTax: { // Order subtotal. var orderSubtotalInclTax = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalInclTax, true, order.CustomerCurrencyCode, language, true, false); // Discount (applied to order subtotal). var orderSubTotalDiscountInclTax = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate); if (orderSubTotalDiscountInclTax > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTax, true, order.CustomerCurrencyCode, language, true, false); } // Order shipping. var orderShippingInclTax = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingInclTax, true, order.CustomerCurrencyCode, language, true, false); // Payment method additional fee. var paymentMethodAdditionalFeeInclTax = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeInclTax != decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTax, true, order.CustomerCurrencyCode, language, true, false); } } break; } // Tax. var displayTax = true; var displayTaxRates = true; if (taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { displayTax = false; displayTaxRates = false; } else { if (order.OrderTax == 0 && taxSettings.HideZeroTax) { displayTax = false; displayTaxRates = false; } else { displayTaxRates = taxSettings.DisplayTaxRates && order.TaxRatesDictionary.Count > 0; displayTax = !displayTaxRates; var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate); model.Tax = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false, language); foreach (var tr in order.TaxRatesDictionary) { var rate = _priceFormatter.FormatTaxRate(tr.Key); //var labelKey = "ShoppingCart.Totals.TaxRateLine" + (_services.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax ? "Incl" : "Excl"); var labelKey = (_services.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax ? "ShoppingCart.Totals.TaxRateLineIncl" : "ShoppingCart.Totals.TaxRateLineExcl"); model.TaxRates.Add(new OrderDetailsModel.TaxRate { Rate = rate, Label = T(labelKey).Text.FormatCurrent(rate), Value = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(tr.Value, order.CurrencyRate), true, order.CustomerCurrencyCode, false, language), }); } } } model.DisplayTaxRates = displayTaxRates; model.DisplayTax = displayTax; // Discount (applied to order total). var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate); if (orderDiscountInCustomerCurrency > decimal.Zero) { model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, language); } // Gift cards. foreach (var gcuh in order.GiftCardUsageHistory) { var remainingAmountBase = gcuh.GiftCard.GetGiftCardRemainingAmount(); var remainingAmount = _currencyService.ConvertCurrency(remainingAmountBase, order.CurrencyRate); var gcModel = new OrderDetailsModel.GiftCard { CouponCode = gcuh.GiftCard.GiftCardCouponCode, Amount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, language), Remaining = _priceFormatter.FormatPrice(remainingAmount, true, false) }; model.GiftCards.Add(gcModel); } // Reward points . if (order.RedeemedRewardPointsEntry != null) { model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points; model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, language); } // Credit balance. if (order.CreditBalance > decimal.Zero) { var convertedCreditBalance = _currencyService.ConvertCurrency(order.CreditBalance, order.CurrencyRate); model.CreditBalance = _priceFormatter.FormatPrice(-convertedCreditBalance, true, order.CustomerCurrencyCode, false, language); } // Total. var roundingAmount = decimal.Zero; var orderTotal = order.GetOrderTotalInCustomerCurrency(_currencyService, _paymentService, out roundingAmount); model.OrderTotal = _priceFormatter.FormatPrice(orderTotal, true, order.CustomerCurrencyCode, false, language); if (roundingAmount != decimal.Zero) { model.OrderTotalRounding = _priceFormatter.FormatPrice(roundingAmount, true, order.CustomerCurrencyCode, false, language); } // Checkout attributes. model.CheckoutAttributeInfo = HtmlUtils.ConvertPlainTextToTable(HtmlUtils.ConvertHtmlToPlainText(order.CheckoutAttributeDescription)); // Order notes. foreach (var orderNote in order.OrderNotes .Where(on => on.DisplayToCustomer) .OrderByDescending(on => on.CreatedOnUtc) .ToList()) { var createdOn = _dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc); model.OrderNotes.Add(new OrderDetailsModel.OrderNote { Note = orderNote.FormatOrderNoteText(), CreatedOn = createdOn, FriendlyCreatedOn = createdOn.RelativeFormat(false, "f") }); } // Purchased products. model.ShowSku = catalogSettings.ShowProductSku; model.ShowProductImages = shoppingCartSettings.ShowProductImagesOnShoppingCart; model.ShowProductBundleImages = shoppingCartSettings.ShowProductBundleImagesOnShoppingCart; model.BundleThumbSize = mediaSettings.CartThumbBundleItemPictureSize; var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null); foreach (var orderItem in orderItems) { var orderItemModel = PrepareOrderItemModel( order, orderItem, catalogSettings, shoppingCartSettings, mediaSettings); model.Items.Add(orderItemModel); } return(model); }
public async Task <OrderDetailsModel> PrepareOrderDetailsModelAsync(Order order) { Guard.NotNull(order, nameof(order)); var settingFactory = _services.SettingFactory; var store = await _db.Stores.FindByIdAsync(order.StoreId, false) ?? _services.StoreContext.CurrentStore; var language = _services.WorkContext.WorkingLanguage; var orderSettings = await settingFactory.LoadSettingsAsync <OrderSettings>(store.Id); var catalogSettings = await settingFactory.LoadSettingsAsync <CatalogSettings>(store.Id); var taxSettings = await settingFactory.LoadSettingsAsync <TaxSettings>(store.Id); var pdfSettings = await settingFactory.LoadSettingsAsync <PdfSettings>(store.Id); var addressSettings = await settingFactory.LoadSettingsAsync <AddressSettings>(store.Id); var companyInfoSettings = await settingFactory.LoadSettingsAsync <CompanyInformationSettings>(store.Id); var shoppingCartSettings = await settingFactory.LoadSettingsAsync <ShoppingCartSettings>(store.Id); var mediaSettings = await settingFactory.LoadSettingsAsync <MediaSettings>(store.Id); var model = new OrderDetailsModel { Id = order.Id, StoreId = order.StoreId, CustomerLanguageId = order.CustomerLanguageId, CustomerComment = order.CustomerOrderComment, OrderNumber = order.GetOrderNumber(), CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatus = await _services.Localization.GetLocalizedEnumAsync(order.OrderStatus), IsReOrderAllowed = orderSettings.IsReOrderAllowed, IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order), DisplayPdfInvoice = pdfSettings.Enabled, RenderOrderNotes = pdfSettings.RenderOrderNotes, // Shipping info. ShippingStatus = await _services.Localization.GetLocalizedEnumAsync(order.ShippingStatus) }; // TODO: refactor modelling for multi-order processing. var companyCountry = await _db.Countries.FindByIdAsync(companyInfoSettings.CountryId, false); model.MerchantCompanyInfo = companyInfoSettings; model.MerchantCompanyCountryName = companyCountry?.GetLocalized(x => x.Name); if (order.ShippingStatus != ShippingStatus.ShippingNotRequired) { model.IsShippable = true; await MapperFactory.MapAsync(order.ShippingAddress, model.ShippingAddress); model.ShippingMethod = order.ShippingMethod; // Shipments (only already shipped). var shipments = order.Shipments.Where(x => x.ShippedDateUtc.HasValue).OrderBy(x => x.CreatedOnUtc).ToList(); foreach (var shipment in shipments) { var shipmentModel = new OrderDetailsModel.ShipmentBriefModel { Id = shipment.Id, TrackingNumber = shipment.TrackingNumber, }; if (shipment.ShippedDateUtc.HasValue) { shipmentModel.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc); } if (shipment.DeliveryDateUtc.HasValue) { shipmentModel.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); } model.Shipments.Add(shipmentModel); } } await MapperFactory.MapAsync(order.BillingAddress, model.BillingAddress); model.VatNumber = order.VatNumber; // Payment method. var paymentMethod = await _paymentService.LoadPaymentMethodBySystemNameAsync(order.PaymentMethodSystemName); model.PaymentMethodSystemName = order.PaymentMethodSystemName; // TODO: (mh) (core) //model.PaymentMethod = paymentMethod != null ? _pluginMediator.GetLocalizedFriendlyName(paymentMethod.Metadata) : order.PaymentMethodSystemName; model.PaymentMethod = order.PaymentMethodSystemName; model.CanRePostProcessPayment = await _paymentService.CanRePostProcessPaymentAsync(order); // Purchase order number (we have to find a better to inject this information because it's related to a certain plugin). if (paymentMethod != null && paymentMethod.Metadata.SystemName.Equals("Smartstore.PurchaseOrderNumber", StringComparison.InvariantCultureIgnoreCase)) { model.DisplayPurchaseOrderNumber = true; model.PurchaseOrderNumber = order.PurchaseOrderNumber; } if (order.AllowStoringCreditCardNumber) { model.CardNumber = _encryptor.DecryptText(order.CardNumber); model.MaskedCreditCardNumber = _encryptor.DecryptText(order.MaskedCreditCardNumber); model.CardCvv2 = _encryptor.DecryptText(order.CardCvv2); model.CardExpirationMonth = _encryptor.DecryptText(order.CardExpirationMonth); model.CardExpirationYear = _encryptor.DecryptText(order.CardExpirationYear); } if (order.AllowStoringDirectDebit) { model.DirectDebitAccountHolder = _encryptor.DecryptText(order.DirectDebitAccountHolder); model.DirectDebitAccountNumber = _encryptor.DecryptText(order.DirectDebitAccountNumber); model.DirectDebitBankCode = _encryptor.DecryptText(order.DirectDebitBankCode); model.DirectDebitBankName = _encryptor.DecryptText(order.DirectDebitBankName); model.DirectDebitBIC = _encryptor.DecryptText(order.DirectDebitBIC); model.DirectDebitCountry = _encryptor.DecryptText(order.DirectDebitCountry); model.DirectDebitIban = _encryptor.DecryptText(order.DirectDebitIban); } // TODO: (mh) (core) Reimplement when pricing is ready. // Totals. var customerCurrency = await _db.Currencies .AsNoTracking() .Where(x => x.CurrencyCode == order.CustomerCurrencyCode) .FirstOrDefaultAsync(); switch (order.CustomerTaxDisplayType) { case TaxDisplayType.ExcludingTax: { // Order subtotal. var orderSubtotalExclTax = _currencyService.ConvertToExchangeRate(order.OrderSubtotalExclTax, order.CurrencyRate, customerCurrency); model.OrderSubtotal = orderSubtotalExclTax.ToString(); // Discount (applied to order subtotal). var orderSubTotalDiscountExclTax = _currencyService.ConvertToExchangeRate(order.OrderSubTotalDiscountExclTax, order.CurrencyRate, customerCurrency); if (orderSubTotalDiscountExclTax > 0) { model.OrderSubTotalDiscount = (orderSubTotalDiscountExclTax * -1).ToString(); } // Order shipping. var orderShippingExclTax = _currencyService.ConvertToExchangeRate(order.OrderShippingExclTax, order.CurrencyRate, customerCurrency); model.OrderShipping = orderShippingExclTax.ToString(); // Payment method additional fee. var paymentMethodAdditionalFeeExclTax = _currencyService.ConvertToExchangeRate(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate, customerCurrency); if (paymentMethodAdditionalFeeExclTax != 0) { model.PaymentMethodAdditionalFee = paymentMethodAdditionalFeeExclTax.ToString(); } } break; case TaxDisplayType.IncludingTax: { // Order subtotal. var orderSubtotalInclTax = _currencyService.ConvertToExchangeRate(order.OrderSubtotalInclTax, order.CurrencyRate, customerCurrency); model.OrderSubtotal = orderSubtotalInclTax.ToString(); // Discount (applied to order subtotal). var orderSubTotalDiscountInclTax = _currencyService.ConvertToExchangeRate(order.OrderSubTotalDiscountInclTax, order.CurrencyRate, customerCurrency); if (orderSubTotalDiscountInclTax > 0) { model.OrderSubTotalDiscount = (orderSubTotalDiscountInclTax * -1).ToString(); } // Order shipping. var orderShippingInclTax = _currencyService.ConvertToExchangeRate(order.OrderShippingInclTax, order.CurrencyRate, customerCurrency); model.OrderShipping = orderShippingInclTax.ToString(); // Payment method additional fee. var paymentMethodAdditionalFeeInclTax = _currencyService.ConvertToExchangeRate(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate, customerCurrency); if (paymentMethodAdditionalFeeInclTax != 0) { model.PaymentMethodAdditionalFee = paymentMethodAdditionalFeeInclTax.ToString(); } } break; } // Tax. var displayTax = true; var displayTaxRates = true; if (taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { displayTax = false; displayTaxRates = false; } else { if (order.OrderTax == 0 && taxSettings.HideZeroTax) { displayTax = false; displayTaxRates = false; } else { displayTaxRates = taxSettings.DisplayTaxRates && order.TaxRatesDictionary.Count > 0; displayTax = !displayTaxRates; var orderTaxInCustomerCurrency = _currencyService.ConvertToExchangeRate(order.OrderTax, order.CurrencyRate, customerCurrency); model.Tax = orderTaxInCustomerCurrency.ToString(); foreach (var tr in order.TaxRatesDictionary) { var rate = _taxService.FormatTaxRate(tr.Key); var labelKey = _services.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax ? "ShoppingCart.Totals.TaxRateLineIncl" : "ShoppingCart.Totals.TaxRateLineExcl"; model.TaxRates.Add(new OrderDetailsModel.TaxRate { Rate = rate, Label = T(labelKey, rate), Value = _currencyService.ConvertToExchangeRate(tr.Value, order.CurrencyRate, customerCurrency).ToString() }); } } } model.DisplayTaxRates = displayTaxRates; model.DisplayTax = displayTax; // Discount (applied to order total). var orderDiscountInCustomerCurrency = _currencyService.ConvertToExchangeRate(order.OrderDiscount, order.CurrencyRate, customerCurrency); if (orderDiscountInCustomerCurrency > 0) { model.OrderTotalDiscount = (orderDiscountInCustomerCurrency * -1).ToString(); } // Gift cards. foreach (var gcuh in order.GiftCardUsageHistory) { var remainingAmountBase = _giftCardService.GetRemainingAmount(gcuh.GiftCard); var remainingAmount = _currencyService.ConvertToExchangeRate(remainingAmountBase.Amount, order.CurrencyRate, customerCurrency); var usedAmount = _currencyService.ConvertToExchangeRate(gcuh.UsedValue, order.CurrencyRate, customerCurrency); var gcModel = new OrderDetailsModel.GiftCard { CouponCode = gcuh.GiftCard.GiftCardCouponCode, Amount = (usedAmount * -1).ToString(), Remaining = remainingAmount.ToString() }; model.GiftCards.Add(gcModel); } // Reward points . if (order.RedeemedRewardPointsEntry != null) { var usedAmount = _currencyService.ConvertToExchangeRate(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate, customerCurrency); model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points; model.RedeemedRewardPointsAmount = (usedAmount * -1).ToString(); } // Credit balance. if (order.CreditBalance > 0) { var convertedCreditBalance = _currencyService.ConvertToExchangeRate(order.CreditBalance, order.CurrencyRate, customerCurrency); model.CreditBalance = (convertedCreditBalance * -1).ToString(); } // Total. (var orderTotal, var roundingAmount) = await _orderService.GetOrderTotalInCustomerCurrencyAsync(order, customerCurrency); model.OrderTotal = orderTotal.ToString(); if (roundingAmount != 0) { model.OrderTotalRounding = roundingAmount.ToString(); } // Checkout attributes. model.CheckoutAttributeInfo = HtmlUtils.ConvertPlainTextToTable(HtmlUtils.ConvertHtmlToPlainText(order.CheckoutAttributeDescription)); // Order notes. await _db.LoadCollectionAsync(order, x => x.OrderNotes); var orderNotes = order.OrderNotes .Where(x => x.DisplayToCustomer) .OrderByDescending(x => x.CreatedOnUtc) .ToList(); foreach (var orderNote in orderNotes) { var createdOn = _dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc); model.OrderNotes.Add(new OrderDetailsModel.OrderNote { Note = orderNote.FormatOrderNoteText(), CreatedOn = createdOn, FriendlyCreatedOn = orderNote.CreatedOnUtc.Humanize() }); } // Purchased products. model.ShowSku = catalogSettings.ShowProductSku; model.ShowProductImages = shoppingCartSettings.ShowProductImagesOnShoppingCart; model.ShowProductBundleImages = shoppingCartSettings.ShowProductBundleImagesOnShoppingCart; model.BundleThumbSize = mediaSettings.CartThumbBundleItemPictureSize; await _db.LoadCollectionAsync(order, x => x.OrderItems, false, q => q.Include(x => x.Product)); foreach (var orderItem in order.OrderItems) { var orderItemModel = await PrepareOrderItemModelAsync(order, orderItem, catalogSettings, shoppingCartSettings, mediaSettings, customerCurrency); model.Items.Add(orderItemModel); } 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); }
private OrderDetailsModel PrepareOrderDetailsModel(Order order) { if (order == null) { throw new ArgumentNullException("order"); } var model = new OrderDetailsModel(); model.Id = order.Id; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc); model.Status = order.OrderStatus; model.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext); model.IsReOrderAllowed = _orderSettings.IsReOrderAllowed; model.IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order); model.DisplayPdfInvoice = _pdfSettings.Enabled; //shipping info model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext); if (order.ShippingStatus == ShippingStatus.Shipped) { model.OrderStatus = model.ShippingStatus; } if (order.ShippingStatus != ShippingStatus.ShippingNotRequired) { model.IsShippable = true; model.ShippingAddress = order.ShippingAddress.ToModel(); model.ShippingMethod = order.ShippingMethod; model.OrderWeight = order.OrderWeight; var baseWeight = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId); if (baseWeight != null) { model.BaseWeightIn = baseWeight.Name; } if (order.ShippedDateUtc.HasValue) { model.ShippedDate = _dateTimeHelper.ConvertToUserTime(order.ShippedDateUtc.Value, DateTimeKind.Utc).ToString("D"); } if (order.DeliveryDateUtc.HasValue) { model.DeliveryDate = _dateTimeHelper.ConvertToUserTime(order.DeliveryDateUtc.Value, DateTimeKind.Utc).ToString("D"); } model.TrackingNumber = order.TrackingNumber; model.TrackingUrl = order.GetTrackingUrl(); } //billing info model.BillingAddress = order.BillingAddress.ToModel(); //VAT number model.VatNumber = order.VatNumber; //payment method var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); model.PaymentMethod = paymentMethod != null ? paymentMethod.PluginDescriptor.FriendlyName : order.PaymentMethodSystemName; //totals switch (order.CustomerTaxDisplayType) { case TaxDisplayType.ExcludingTax: { //order subtotal var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); //discount (applied to order subtotal) var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate); if (orderSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } //order shipping var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); //payment method additional fee var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeExclTaxInCustomerCurrency > decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } } break; case TaxDisplayType.IncludingTax: { //order subtotal var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); //discount (applied to order subtotal) var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate); if (orderSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } //order shipping var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); //payment method additional fee var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeInclTaxInCustomerCurrency > decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } } break; } //tax bool displayTax = true; bool displayTaxRates = true; if (_taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { displayTax = false; displayTaxRates = false; } else { if (order.OrderTax == 0 && _taxSettings.HideZeroTax) { displayTax = false; displayTaxRates = false; } else { displayTaxRates = _taxSettings.DisplayTaxRates && order.TaxRatesDictionary.Count > 0; displayTax = !displayTaxRates; var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate); model.Tax = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); foreach (var tr in order.TaxRatesDictionary) { model.TaxRates.Add(new OrderDetailsModel.TaxRate() { Rate = _priceFormatter.FormatTaxRate(tr.Key), Value = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(tr.Value, order.CurrencyRate), true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false), }); } } } model.DisplayTaxRates = displayTaxRates; model.DisplayTax = displayTax; //discount (applied to order total) var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate); if (orderDiscountInCustomerCurrency > decimal.Zero) { model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); } //gift cards foreach (var gcuh in order.GiftCardUsageHistory) { model.GiftCards.Add(new OrderDetailsModel.GiftCard() { CouponCode = gcuh.GiftCard.GiftCardCouponCode, Amount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage), }); } //reward points if (order.RedeemedRewardPointsEntry != null) { model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points; model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); } //total var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); model.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); //checkout attributes model.CheckoutAttributeInfo = order.CheckoutAttributeDescription; //order notes foreach (var orderNote in order.OrderNotes .Where(on => on.DisplayToCustomer) .OrderByDescending(on => on.CreatedOnUtc) .ToList()) { model.OrderNotes.Add(new OrderDetailsModel.OrderNote() { Note = Nop.Core.Html.HtmlHelper.FormatText(orderNote.Note, false, true, false, false, false, false), CreatedOn = _dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc) }); } //purchased products model.ShowSku = _catalogSettings.ShowProductSku; var orderProductVariants = _orderService.GetAllOrderProductVariants(order.Id, null, null, null, null, null, null); foreach (var opv in orderProductVariants) { var opvModel = new OrderDetailsModel.OrderProductVariantModel() { Id = opv.Id, Sku = opv.ProductVariant.Sku, ProductId = opv.ProductVariant.ProductId, ProductSeName = opv.ProductVariant.Product.GetSeName(), Quantity = opv.Quantity, AttributeInfo = opv.AttributeDescription, }; //product name if (!String.IsNullOrEmpty(opv.ProductVariant.GetLocalized(x => x.Name))) { opvModel.ProductName = string.Format("{0} ({1})", opv.ProductVariant.Product.GetLocalized(x => x.Name), opv.ProductVariant.GetLocalized(x => x.Name)); } else { opvModel.ProductName = opv.ProductVariant.Product.GetLocalized(x => x.Name); } model.Items.Add(opvModel); //unit price, subtotal switch (order.CustomerTaxDisplayType) { case TaxDisplayType.ExcludingTax: { var opvUnitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(opv.UnitPriceExclTax, order.CurrencyRate); opvModel.UnitPrice = _priceFormatter.FormatPrice(opvUnitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); var opvPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(opv.PriceExclTax, order.CurrencyRate); opvModel.SubTotal = _priceFormatter.FormatPrice(opvPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false); } break; case TaxDisplayType.IncludingTax: { var opvUnitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(opv.UnitPriceInclTax, order.CurrencyRate); opvModel.UnitPrice = _priceFormatter.FormatPrice(opvUnitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); var opvPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(opv.PriceInclTax, order.CurrencyRate); opvModel.SubTotal = _priceFormatter.FormatPrice(opvPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true); } break; } //picture var picture = opv.ProductVariant.GetDefaultProductVariantPicture(_pictureService); if (picture == null) { picture = _pictureService.GetPicturesByProductId(opv.ProductVariant.Product.Id, 1).FirstOrDefault(); } var pictureModel = new PictureModel() { ImageUrl = _pictureService.GetPictureUrl(picture, _mediaSettings.CartThumbPictureSize, true), Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), opv.ProductVariant.Product.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), opv.ProductVariant.Name), }; opvModel.Picture = pictureModel; } //Order Items add Return Request var returnRequests = _orderService.SearchReturnRequests(_workContext.CurrentCustomer.Id, 0, null); model.HasReturnRequest = false; foreach (var returnRequest in returnRequests) { var opv = _orderService.GetOrderProductVariantById(returnRequest.OrderProductVariantId); if (opv.OrderId == model.Id) { model.HasReturnRequest = true; var pv = opv.ProductVariant; var request = new OrderDetailsModel.OrderProductVariantModel.OrderProductVariantReturnRequest() { RequestAction = returnRequest.RequestedAction, ReturnRequestStatusId = returnRequest.ReturnRequestStatusId, ReturnRequestStatus = returnRequest.ReturnRequestStatus.GetLocalizedEnum(_localizationService, _workContext), ReturnRequestDate = returnRequest.UpdatedOnUtc }; model.Items.Where(x => x.ProductId == pv.ProductId).FirstOrDefault().ItemsReturnRequest = request; } } return(model); }
protected OrderDetailsModel PrepareOrderDetailsModel(Order order) { if (order == null) { throw new ArgumentNullException("order"); } var store = _storeService.GetStoreById(order.StoreId) ?? _services.StoreContext.CurrentStore; var orderSettings = _services.Settings.LoadSetting <OrderSettings>(store.Id); var catalogSettings = _services.Settings.LoadSetting <CatalogSettings>(store.Id); var taxSettings = _services.Settings.LoadSetting <TaxSettings>(store.Id); var pdfSettings = _services.Settings.LoadSetting <PdfSettings>(store.Id); var addressSettings = _services.Settings.LoadSetting <AddressSettings>(store.Id); var companyInfoSettings = _services.Settings.LoadSetting <CompanyInformationSettings>(store.Id); var model = new OrderDetailsModel(); model.MerchantCompanyInfo = companyInfoSettings; model.Id = order.Id; model.StoreId = order.StoreId; model.OrderNumber = order.GetOrderNumber(); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc); model.OrderStatus = order.OrderStatus.GetLocalizedEnum(_services.Localization, _services.WorkContext); model.IsReOrderAllowed = orderSettings.IsReOrderAllowed; model.IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order); model.DisplayPdfInvoice = pdfSettings.Enabled; model.RenderOrderNotes = pdfSettings.RenderOrderNotes; //shipping info model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_services.Localization, _services.WorkContext); if (order.ShippingStatus != ShippingStatus.ShippingNotRequired) { model.IsShippable = true; model.ShippingAddress.PrepareModel(order.ShippingAddress, false, addressSettings); model.ShippingMethod = order.ShippingMethod; //shipments (only already shipped) var shipments = order.Shipments.Where(x => x.ShippedDateUtc.HasValue).OrderBy(x => x.CreatedOnUtc).ToList(); foreach (var shipment in shipments) { var shipmentModel = new OrderDetailsModel.ShipmentBriefModel() { Id = shipment.Id, TrackingNumber = shipment.TrackingNumber, }; if (shipment.ShippedDateUtc.HasValue) { shipmentModel.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc); } if (shipment.DeliveryDateUtc.HasValue) { shipmentModel.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc); } model.Shipments.Add(shipmentModel); } } //billing info model.BillingAddress.PrepareModel(order.BillingAddress, false, addressSettings); //VAT number model.VatNumber = order.VatNumber; //payment method var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); model.PaymentMethod = paymentMethod != null?_pluginMediator.GetLocalizedFriendlyName(paymentMethod.Metadata) : order.PaymentMethodSystemName; model.CanRePostProcessPayment = _paymentService.CanRePostProcessPayment(order); //purchase order number (we have to find a better to inject this information because it's related to a certain plugin) if (paymentMethod != null && paymentMethod.Metadata.SystemName.Equals("Payments.PurchaseOrder", StringComparison.InvariantCultureIgnoreCase)) { model.DisplayPurchaseOrderNumber = true; model.PurchaseOrderNumber = order.PurchaseOrderNumber; } // totals switch (order.CustomerTaxDisplayType) { case TaxDisplayType.ExcludingTax: { //order subtotal var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _services.WorkContext.WorkingLanguage, false, false); //discount (applied to order subtotal) var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate); if (orderSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _services.WorkContext.WorkingLanguage, false, false); } //order shipping var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _services.WorkContext.WorkingLanguage, false, false); //payment method additional fee var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeExclTaxInCustomerCurrency != decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _services.WorkContext.WorkingLanguage, false, false); } } break; case TaxDisplayType.IncludingTax: { //order subtotal var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate); model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _services.WorkContext.WorkingLanguage, true, false); //discount (applied to order subtotal) var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate); if (orderSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero) { model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _services.WorkContext.WorkingLanguage, true, false); } //order shipping var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate); model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _services.WorkContext.WorkingLanguage, true, false); //payment method additional fee var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate); if (paymentMethodAdditionalFeeInclTaxInCustomerCurrency != decimal.Zero) { model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _services.WorkContext.WorkingLanguage, true, false); } } break; } //tax bool displayTax = true; bool displayTaxRates = true; if (taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { displayTax = false; displayTaxRates = false; } else { if (order.OrderTax == 0 && taxSettings.HideZeroTax) { displayTax = false; displayTaxRates = false; } else { displayTaxRates = taxSettings.DisplayTaxRates && order.TaxRatesDictionary.Count > 0; displayTax = !displayTaxRates; var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate); //TODO pass languageId to _priceFormatter.FormatPrice model.Tax = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false, _services.WorkContext.WorkingLanguage); foreach (var tr in order.TaxRatesDictionary) { var rate = _priceFormatter.FormatTaxRate(tr.Key); var labelKey = "ShoppingCart.Totals.TaxRateLine" + (_services.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax ? "Incl" : "Excl"); model.TaxRates.Add(new OrderDetailsModel.TaxRate() { Rate = rate, Label = T(labelKey).Text.FormatCurrent(rate), //TODO pass languageId to _priceFormatter.FormatPrice Value = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(tr.Value, order.CurrencyRate), true, order.CustomerCurrencyCode, false, _services.WorkContext.WorkingLanguage), }); } } } model.DisplayTaxRates = displayTaxRates; model.DisplayTax = displayTax; //discount (applied to order total) var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate); if (orderDiscountInCustomerCurrency > decimal.Zero) { model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, _services.WorkContext.WorkingLanguage); } //gift cards foreach (var gcuh in order.GiftCardUsageHistory) { model.GiftCards.Add(new OrderDetailsModel.GiftCard() { CouponCode = gcuh.GiftCard.GiftCardCouponCode, Amount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _services.WorkContext.WorkingLanguage), }); } //reward points if (order.RedeemedRewardPointsEntry != null) { model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points; model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _services.WorkContext.WorkingLanguage); } //total var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); model.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _services.WorkContext.WorkingLanguage); //checkout attributes model.CheckoutAttributeInfo = HtmlUtils.ConvertPlainTextToTable(HtmlUtils.ConvertHtmlToPlainText(order.CheckoutAttributeDescription)); //order notes foreach (var orderNote in order.OrderNotes .Where(on => on.DisplayToCustomer) .OrderByDescending(on => on.CreatedOnUtc) .ToList()) { model.OrderNotes.Add(new OrderDetailsModel.OrderNote() { Note = orderNote.FormatOrderNoteText(), CreatedOn = _dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc) }); } //purchased products model.ShowSku = catalogSettings.ShowProductSku; var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null); foreach (var orderItem in orderItems) { var orderItemModel = PrepareOrderItemModel(order, orderItem); model.Items.Add(orderItemModel); } return(model); }
/// <summary> /// Check whether return request is allowed /// </summary> /// <param name="order">Order</param> /// <returns>Result</returns> public bool IsReturnRequestAllowed(Order order) { return(_orderProcessingService.IsReturnRequestAllowed(order)); }
public async Task <OrderDetailsModel> Handle(GetOrderDetails request, CancellationToken cancellationToken) { var model = new OrderDetailsModel(); model.Id = request.Order.Id; model.OrderNumber = request.Order.OrderNumber; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(request.Order.CreatedOnUtc, DateTimeKind.Utc); model.OrderStatus = request.Order.OrderStatus.GetLocalizedEnum(_localizationService, request.Language.Id); model.IsReOrderAllowed = _orderSettings.IsReOrderAllowed; model.IsReturnRequestAllowed = await _orderProcessingService.IsReturnRequestAllowed(request.Order); model.PdfInvoiceDisabled = _pdfSettings.DisablePdfInvoicesForPendingOrders && request.Order.OrderStatus == OrderStatus.Pending; model.ShowAddOrderNote = _orderSettings.AllowCustomerToAddOrderNote; //shipping info await PrepareShippingInfo(request, model); //billing info model.BillingAddress = await _mediator.Send(new GetAddressModel() { Language = request.Language, Model = null, Address = request.Order.BillingAddress, ExcludeProperties = false, }); //VAT number model.VatNumber = request.Order.VatNumber; //payment method await PreparePaymentMethod(request, model); //custom values model.CustomValues = request.Order.DeserializeCustomValues(); //order subtotal await PrepareOrderTotal(request, model); //tax await PrepareTax(request, model); //discount (applied to order total) await PrepareDiscount(request, model); //gift cards await PrepareGiftCards(request, model); //reward points await PrepareRewardPoints(request, model); //checkout attributes model.CheckoutAttributeInfo = request.Order.CheckoutAttributeDescription; //order notes await PrepareOrderNotes(request, model); //allow cancel order if (_orderSettings.UserCanCancelUnpaidOrder) { if (request.Order.OrderStatus == OrderStatus.Pending && request.Order.PaymentStatus == Core.Domain.Payments.PaymentStatus.Pending && (request.Order.ShippingStatus == ShippingStatus.ShippingNotRequired || request.Order.ShippingStatus == ShippingStatus.NotYetShipped)) { model.UserCanCancelUnpaidOrder = true; } } //purchased products await PrepareOrderItems(request, model); return(model); }