public ActionResult CompleteOrder(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) return RedirectToAction("List"); try { _orderProcessingService.CompleteOrder(order); } catch (Exception exc) { NotifyError(exc, false); } var model = new OrderModel(); PrepareOrderDetailsModel(model, order); return View(model); }
public ActionResult DeleteLicenseFilePopup(string btnId, string formId, OrderModel.UploadLicenseModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(model.OrderId); if (order == null) //No order found with the specified id return RedirectToAction("List"); var orderItem = order.OrderItems.Where(x => x.Id == model.OrderItemId).FirstOrDefault(); if (orderItem == null) throw new ArgumentException("No order item found with the specified id"); //attach license orderItem.LicenseDownloadId = null; _orderService.UpdateOrder(order); //success ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; return View(model); }
public ActionResult AddReturnRequest(int id, FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageReturnRequests)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) return RedirectToAction("List"); //get order item identifier int orderItemId = 0; foreach (var formValue in form.AllKeys) if (formValue.StartsWith("btnAddReturnRequest", StringComparison.InvariantCultureIgnoreCase)) orderItemId = Convert.ToInt32(formValue.Substring("btnAddReturnRequest".Length)); var orderItem = order.OrderItems.Where(x => x.Id == orderItemId).FirstOrDefault(); if (orderItem == null) throw new ArgumentException("No order item found with the specified id"); if (orderItem.Quantity > 0) { var returnRequest = new ReturnRequest() { StoreId = order.StoreId, OrderItemId = orderItem.Id, Quantity = orderItem.Quantity, CustomerId = order.CustomerId, ReasonForReturn = "", RequestedAction = "", StaffNotes = "", ReturnRequestStatus = ReturnRequestStatus.Pending, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow }; order.Customer.ReturnRequests.Add(returnRequest); _customerService.UpdateCustomer(order.Customer); return RedirectToAction("Edit", "ReturnRequest", new { id = returnRequest.Id }); } var model = new OrderModel(); PrepareOrderDetailsModel(model, order); return View(model); }
public ActionResult CaptureOrder(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) //No order found with the specified id return RedirectToAction("List"); try { var errors = _orderProcessingService.Capture(order); var model = new OrderModel(); PrepareOrderDetailsModel(model, order); foreach (var error in errors) NotifyError(error, false); return View(model); } catch (Exception exc) { //error var model = new OrderModel(); PrepareOrderDetailsModel(model, order); NotifyError(exc, false); return View(model); } }
protected void PrepareOrderDetailsModel(OrderModel model, Order order) { if (order == null) throw new ArgumentNullException("order"); if (model == null) throw new ArgumentNullException("model"); var store = _storeService.GetStoreById(order.StoreId); var primaryStoreCurrency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId); model.Id = order.Id; model.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext); model.OrderNumber = order.GetOrderNumber(); model.OrderGuid = order.OrderGuid; model.StoreName = (store != null ? store.Name : "".NaIfEmpty()); model.CustomerId = order.CustomerId; model.CustomerName = order.Customer.GetFullName(); model.CustomerIp = order.CustomerIp; model.VatNumber = order.VatNumber; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc); model.UpdatedOn = _dateTimeHelper.ConvertToUserTime(order.UpdatedOnUtc, DateTimeKind.Utc); model.DisplayPdfInvoice = _pdfSettings.Enabled; model.AllowCustomersToSelectTaxDisplayType = _taxSettings.AllowCustomersToSelectTaxDisplayType; model.TaxDisplayType = _taxSettings.TaxDisplayType; model.AffiliateId = order.AffiliateId; model.CustomerComment = order.CustomerOrderComment; if (order.AffiliateId != 0) { var affiliate = _affiliateService.GetAffiliateById(order.AffiliateId); if (affiliate != null && affiliate.Address != null) model.AffiliateFullName = affiliate.Address.GetFullName(); } #region Order totals //subtotal model.OrderSubtotalInclTax = _priceFormatter.FormatPrice(order.OrderSubtotalInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true); model.OrderSubtotalExclTax = _priceFormatter.FormatPrice(order.OrderSubtotalExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); model.OrderSubtotalInclTaxValue = order.OrderSubtotalInclTax; model.OrderSubtotalExclTaxValue = order.OrderSubtotalExclTax; //discount (applied to order subtotal) string orderSubtotalDiscountInclTaxStr = _priceFormatter.FormatPrice(order.OrderSubTotalDiscountInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true); string orderSubtotalDiscountExclTaxStr = _priceFormatter.FormatPrice(order.OrderSubTotalDiscountExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); if (order.OrderSubTotalDiscountInclTax > decimal.Zero) model.OrderSubTotalDiscountInclTax = orderSubtotalDiscountInclTaxStr; if (order.OrderSubTotalDiscountExclTax > decimal.Zero) model.OrderSubTotalDiscountExclTax = orderSubtotalDiscountExclTaxStr; model.OrderSubTotalDiscountInclTaxValue = order.OrderSubTotalDiscountInclTax; model.OrderSubTotalDiscountExclTaxValue = order.OrderSubTotalDiscountExclTax; //shipping model.OrderShippingInclTax = _priceFormatter.FormatShippingPrice(order.OrderShippingInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true); model.OrderShippingExclTax = _priceFormatter.FormatShippingPrice(order.OrderShippingExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); model.OrderShippingInclTaxValue = order.OrderShippingInclTax; model.OrderShippingExclTaxValue = order.OrderShippingExclTax; //payment method additional fee if (order.PaymentMethodAdditionalFeeInclTax != decimal.Zero) { model.PaymentMethodAdditionalFeeInclTax = _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true); model.PaymentMethodAdditionalFeeExclTax = _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); } model.PaymentMethodAdditionalFeeInclTaxValue = order.PaymentMethodAdditionalFeeInclTax; model.PaymentMethodAdditionalFeeExclTaxValue = order.PaymentMethodAdditionalFeeExclTax; //tax model.Tax = _priceFormatter.FormatPrice(order.OrderTax, true, false); SortedDictionary<decimal, decimal> taxRates = order.TaxRatesDictionary; bool displayTaxRates = _taxSettings.DisplayTaxRates && taxRates.Count > 0; bool displayTax = !displayTaxRates; foreach (var tr in order.TaxRatesDictionary) { model.TaxRates.Add(new OrderModel.TaxRate() { Rate = _priceFormatter.FormatTaxRate(tr.Key), Value = _priceFormatter.FormatPrice(tr.Value, true, false), }); } model.DisplayTaxRates = displayTaxRates; model.DisplayTax = displayTax; model.TaxValue = order.OrderTax; model.TaxRatesValue = order.TaxRates; //discount if (order.OrderDiscount > 0) model.OrderTotalDiscount = _priceFormatter.FormatPrice(-order.OrderDiscount, true, false); model.OrderTotalDiscountValue = order.OrderDiscount; //gift cards foreach (var gcuh in order.GiftCardUsageHistory) { model.GiftCards.Add(new OrderModel.GiftCard() { CouponCode = gcuh.GiftCard.GiftCardCouponCode, Amount = _priceFormatter.FormatPrice(-gcuh.UsedValue, true, false), }); } //reward points if (order.RedeemedRewardPointsEntry != null) { model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points; model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-order.RedeemedRewardPointsEntry.UsedAmount, true, false); } //total model.OrderTotal = _priceFormatter.FormatPrice(order.OrderTotal, true, false); model.OrderTotalValue = order.OrderTotal; //refunded amount if (order.RefundedAmount > decimal.Zero) model.RefundedAmount = _priceFormatter.FormatPrice(order.RefundedAmount, true, false); #endregion #region Payment info if (order.AllowStoringCreditCardNumber) { //card type model.CardType = _encryptionService.DecryptText(order.CardType); //cardholder name model.CardName = _encryptionService.DecryptText(order.CardName); //card number model.CardNumber = _encryptionService.DecryptText(order.CardNumber); //cvv model.CardCvv2 = _encryptionService.DecryptText(order.CardCvv2); //expiry date string cardExpirationMonthDecrypted = _encryptionService.DecryptText(order.CardExpirationMonth); if (!String.IsNullOrEmpty(cardExpirationMonthDecrypted) && cardExpirationMonthDecrypted != "0") model.CardExpirationMonth = cardExpirationMonthDecrypted; string cardExpirationYearDecrypted = _encryptionService.DecryptText(order.CardExpirationYear); if (!String.IsNullOrEmpty(cardExpirationYearDecrypted) && cardExpirationYearDecrypted != "0") model.CardExpirationYear = cardExpirationYearDecrypted; model.AllowStoringCreditCardNumber = true; } else { string maskedCreditCardNumberDecrypted = _encryptionService.DecryptText(order.MaskedCreditCardNumber); if (!String.IsNullOrEmpty(maskedCreditCardNumberDecrypted)) model.CardNumber = maskedCreditCardNumberDecrypted; } if (order.AllowStoringDirectDebit) { model.DirectDebitAccountHolder = _encryptionService.DecryptText(order.DirectDebitAccountHolder); model.DirectDebitAccountNumber = _encryptionService.DecryptText(order.DirectDebitAccountNumber); model.DirectDebitBankCode = _encryptionService.DecryptText(order.DirectDebitBankCode); model.DirectDebitBankName = _encryptionService.DecryptText(order.DirectDebitBankName); model.DirectDebitBIC = _encryptionService.DecryptText(order.DirectDebitBIC); model.DirectDebitCountry = _encryptionService.DecryptText(order.DirectDebitCountry); model.DirectDebitIban = _encryptionService.DecryptText(order.DirectDebitIban); model.AllowStoringDirectDebit = true; } //purchase order number (we have to find a better to inject this information because it's related to a certain plugin) var pm = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); if (pm != null) { if (pm.Metadata.SystemName.Equals("Payments.PurchaseOrder", StringComparison.InvariantCultureIgnoreCase)) { model.DisplayPurchaseOrderNumber = true; model.PurchaseOrderNumber = order.PurchaseOrderNumber; } model.PaymentMethod = _pluginMediator.GetLocalizedFriendlyName(pm.Metadata); model.PaymentMethodSystemName = order.PaymentMethodSystemName; } else { model.PaymentMethod = order.PaymentMethodSystemName; } //payment transaction info model.AuthorizationTransactionId = order.AuthorizationTransactionId; model.CaptureTransactionId = order.CaptureTransactionId; model.SubscriptionTransactionId = order.SubscriptionTransactionId; model.AuthorizationTransactionResult = order.AuthorizationTransactionResult; model.CaptureTransactionResult = order.CaptureTransactionResult; //payment method info model.PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext); //payment method buttons model.CanCancelOrder = _orderProcessingService.CanCancelOrder(order); model.CanCompleteOrder = _orderProcessingService.CanCompleteOrder(order); model.CanCapture = _orderProcessingService.CanCapture(order); model.CanMarkOrderAsPaid = _orderProcessingService.CanMarkOrderAsPaid(order); model.CanRefund = _orderProcessingService.CanRefund(order); model.CanRefundOffline = _orderProcessingService.CanRefundOffline(order); model.CanPartiallyRefund = _orderProcessingService.CanPartiallyRefund(order, decimal.Zero); model.CanPartiallyRefundOffline = _orderProcessingService.CanPartiallyRefundOffline(order, decimal.Zero); model.CanVoid = _orderProcessingService.CanVoid(order); model.CanVoidOffline = _orderProcessingService.CanVoidOffline(order); model.MaxAmountToRefund = order.OrderTotal - order.RefundedAmount; model.MaxAmountToRefundFormatted = _priceFormatter.FormatPrice(model.MaxAmountToRefund, true, primaryStoreCurrency, _workContext.WorkingLanguage, false, false); //recurring payment record var recurringPayment = _orderService.SearchRecurringPayments(0, 0, order.Id, null, true).FirstOrDefault(); if (recurringPayment != null) { model.RecurringPaymentId = recurringPayment.Id; } #endregion #region Billing & shipping info model.BillingAddress = order.BillingAddress.ToModel(); model.BillingAddress.FirstNameEnabled = true; model.BillingAddress.FirstNameRequired = true; model.BillingAddress.LastNameEnabled = true; model.BillingAddress.LastNameRequired = true; model.BillingAddress.EmailEnabled = true; model.BillingAddress.EmailRequired = true; model.BillingAddress.CompanyEnabled = _addressSettings.CompanyEnabled; model.BillingAddress.CompanyRequired = _addressSettings.CompanyRequired; model.BillingAddress.CountryEnabled = _addressSettings.CountryEnabled; model.BillingAddress.StateProvinceEnabled = _addressSettings.StateProvinceEnabled; model.BillingAddress.CityEnabled = _addressSettings.CityEnabled; model.BillingAddress.CityRequired = _addressSettings.CityRequired; model.BillingAddress.StreetAddressEnabled = _addressSettings.StreetAddressEnabled; model.BillingAddress.StreetAddressRequired = _addressSettings.StreetAddressRequired; model.BillingAddress.StreetAddress2Enabled = _addressSettings.StreetAddress2Enabled; model.BillingAddress.StreetAddress2Required = _addressSettings.StreetAddress2Required; model.BillingAddress.ZipPostalCodeEnabled = _addressSettings.ZipPostalCodeEnabled; model.BillingAddress.ZipPostalCodeRequired = _addressSettings.ZipPostalCodeRequired; model.BillingAddress.PhoneEnabled = _addressSettings.PhoneEnabled; model.BillingAddress.PhoneRequired = _addressSettings.PhoneRequired; model.BillingAddress.FaxEnabled = _addressSettings.FaxEnabled; model.BillingAddress.FaxRequired = _addressSettings.FaxRequired; model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext); ; if (order.ShippingStatus != ShippingStatus.ShippingNotRequired) { model.IsShippable = true; model.ShippingAddress = order.ShippingAddress.ToModel(); model.ShippingAddress.FirstNameEnabled = true; model.ShippingAddress.FirstNameRequired = true; model.ShippingAddress.LastNameEnabled = true; model.ShippingAddress.LastNameRequired = true; model.ShippingAddress.EmailEnabled = true; model.ShippingAddress.EmailRequired = true; model.ShippingAddress.CompanyEnabled = _addressSettings.CompanyEnabled; model.ShippingAddress.CompanyRequired = _addressSettings.CompanyRequired; model.ShippingAddress.CountryEnabled = _addressSettings.CountryEnabled; model.ShippingAddress.StateProvinceEnabled = _addressSettings.StateProvinceEnabled; model.ShippingAddress.CityEnabled = _addressSettings.CityEnabled; model.ShippingAddress.CityRequired = _addressSettings.CityRequired; model.ShippingAddress.StreetAddressEnabled = _addressSettings.StreetAddressEnabled; model.ShippingAddress.StreetAddressRequired = _addressSettings.StreetAddressRequired; model.ShippingAddress.StreetAddress2Enabled = _addressSettings.StreetAddress2Enabled; model.ShippingAddress.StreetAddress2Required = _addressSettings.StreetAddress2Required; model.ShippingAddress.ZipPostalCodeEnabled = _addressSettings.ZipPostalCodeEnabled; model.ShippingAddress.ZipPostalCodeRequired = _addressSettings.ZipPostalCodeRequired; model.ShippingAddress.PhoneEnabled = _addressSettings.PhoneEnabled; model.ShippingAddress.PhoneRequired = _addressSettings.PhoneRequired; model.ShippingAddress.FaxEnabled = _addressSettings.FaxEnabled; model.ShippingAddress.FaxRequired = _addressSettings.FaxRequired; model.ShippingMethod = order.ShippingMethod; model.ShippingAddressGoogleMapsUrl = string.Format("http://maps.google.com/maps?f=q&hl=en&ie=UTF8&oe=UTF8&geocode=&q={0}", Server.UrlEncode(order.ShippingAddress.Address1 + " " + order.ShippingAddress.ZipPostalCode + " " + order.ShippingAddress.City + " " + (order.ShippingAddress.Country != null ? order.ShippingAddress.Country.Name : ""))); model.CanAddNewShipments = order.HasItemsToAddToShipment(); } #endregion #region Products model.CheckoutAttributeInfo = HtmlUtils.ConvertPlainTextToTable(HtmlUtils.ConvertHtmlToPlainText(order.CheckoutAttributeDescription)); //model.CheckoutAttributeInfo = order.CheckoutAttributeDescription; //model.CheckoutAttributeInfo = _checkoutAttributeFormatter.FormatAttributes(_workContext.CurrentCustomer.CheckoutAttributes, _workContext.CurrentCustomer, "", false); bool hasDownloadableItems = false; foreach (var orderItem in order.OrderItems) { if (orderItem.Product.IsDownload) hasDownloadableItems = true; orderItem.Product.MergeWithCombination(orderItem.AttributesXml); var orderItemModel = new OrderModel.OrderItemModel() { Id = orderItem.Id, ProductId = orderItem.ProductId, ProductName = orderItem.Product.GetLocalized(x => x.Name), Sku = orderItem.Product.Sku, ProductType = orderItem.Product.ProductType, ProductTypeName = orderItem.Product.GetProductTypeLabel(_localizationService), ProductTypeLabelHint = orderItem.Product.ProductTypeLabelHint, Quantity = orderItem.Quantity, IsDownload = orderItem.Product.IsDownload, DownloadCount = orderItem.DownloadCount, DownloadActivationType = orderItem.Product.DownloadActivationType, IsDownloadActivated = orderItem.IsDownloadActivated, LicenseDownloadId = orderItem.LicenseDownloadId }; if (orderItem.Product.ProductType == ProductType.BundledProduct && orderItem.BundleData.HasValue()) { var bundleData = orderItem.GetBundleData(); orderItemModel.BundlePerItemPricing = orderItem.Product.BundlePerItemPricing; orderItemModel.BundlePerItemShoppingCart = bundleData.Any(x => x.PerItemShoppingCart); foreach (var bundleItem in bundleData) { var bundleItemModel = new OrderModel.BundleItemModel() { ProductId = bundleItem.ProductId, Sku = bundleItem.Sku, ProductName = bundleItem.ProductName, ProductSeName = bundleItem.ProductSeName, VisibleIndividually = bundleItem.VisibleIndividually, Quantity = bundleItem.Quantity, DisplayOrder = bundleItem.DisplayOrder, AttributeInfo = bundleItem.AttributesInfo }; if (orderItemModel.BundlePerItemShoppingCart) { bundleItemModel.PriceWithDiscount = _priceFormatter.FormatPrice(bundleItem.PriceWithDiscount, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); } orderItemModel.BundleItems.Add(bundleItemModel); } } //unit price orderItemModel.UnitPriceInclTaxValue = orderItem.UnitPriceInclTax; orderItemModel.UnitPriceExclTaxValue = orderItem.UnitPriceExclTax; orderItemModel.UnitPriceInclTax = _priceFormatter.FormatPrice(orderItem.UnitPriceInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true, true); orderItemModel.UnitPriceExclTax = _priceFormatter.FormatPrice(orderItem.UnitPriceExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false, true); //discounts orderItemModel.DiscountInclTaxValue = orderItem.DiscountAmountInclTax; orderItemModel.DiscountExclTaxValue = orderItem.DiscountAmountExclTax; orderItemModel.DiscountInclTax = _priceFormatter.FormatPrice(orderItem.DiscountAmountInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true, true); orderItemModel.DiscountExclTax = _priceFormatter.FormatPrice(orderItem.DiscountAmountExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false, true); //subtotal orderItemModel.SubTotalInclTaxValue = orderItem.PriceInclTax; orderItemModel.SubTotalExclTaxValue = orderItem.PriceExclTax; orderItemModel.SubTotalInclTax = _priceFormatter.FormatPrice(orderItem.PriceInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true, true); orderItemModel.SubTotalExclTax = _priceFormatter.FormatPrice(orderItem.PriceExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false, true); orderItemModel.AttributeInfo = orderItem.AttributeDescription; if (orderItem.Product.IsRecurring) { orderItemModel.RecurringInfo = string.Format(_localizationService.GetResource("Admin.Orders.Products.RecurringPeriod"), orderItem.Product.RecurringCycleLength, orderItem.Product.RecurringCyclePeriod.GetLocalizedEnum(_localizationService, _workContext)); } //return requests orderItemModel.ReturnRequests = _orderService.SearchReturnRequests(0, 0, orderItem.Id, null, 0, int.MaxValue).Select(x => { return new OrderModel.ReturnRequestModel() { Id = x.Id, Quantity = x.Quantity, Status = x.ReturnRequestStatus, StatusString = x.ReturnRequestStatus.GetLocalizedEnum(_localizationService, _workContext) }; }) .ToList(); //gift cards orderItemModel.PurchasedGiftCardIds = _giftCardService.GetGiftCardsByPurchasedWithOrderItemId(orderItem.Id) .Select(gc => gc.Id).ToList(); model.Items.Add(orderItemModel); } model.HasDownloadableProducts = hasDownloadableItems; model.AutoUpdateOrderItem.Caption = _localizationService.GetResource("Admin.Orders.EditOrderDetails"); model.AutoUpdateOrderItem.ShowUpdateTotals = (order.OrderStatusId <= (int)OrderStatus.Pending); // UpdateRewardPoints only visible for unpending orders (see RewardPointsSettingsValidator). model.AutoUpdateOrderItem.ShowUpdateRewardPoints = (order.OrderStatusId > (int)OrderStatus.Pending && order.RewardPointsWereAdded); model.AutoUpdateOrderItem.UpdateTotals = model.AutoUpdateOrderItem.ShowUpdateTotals; model.AutoUpdateOrderItem.UpdateRewardPoints = order.RewardPointsWereAdded; model.AutoUpdateOrderItemInfo = TempData[AutoUpdateOrderItemContext.InfoKey] as string; #endregion }
public ActionResult AddProductToOrder(GridCommand command, OrderModel.AddOrderProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var gridModel = new GridModel(); var searchContext = new ProductSearchContext() { CategoryIds = new List<int>() { model.SearchCategoryId }, ManufacturerId = model.SearchManufacturerId, Keywords = model.SearchProductName, PageIndex = command.Page - 1, PageSize = command.PageSize, ShowHidden = true, ProductType = model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null }; var products = _productService.SearchProducts(searchContext); gridModel.Data = products.Select(x => { var productModel = new OrderModel.AddOrderProductModel.ProductModel() { Id = x.Id, Name = x.Name, Sku = x.Sku, ProductTypeName = x.GetProductTypeLabel(_localizationService), ProductTypeLabelHint = x.ProductTypeLabelHint }; return productModel; }); gridModel.Total = products.TotalCount; return new JsonResult { Data = gridModel }; }
public ActionResult PartiallyRefundOrderPopup(string btnId, string formId, int id, bool online, OrderModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) //No order found with the specified id return RedirectToAction("List"); try { decimal amountToRefund = model.AmountToRefund; if (amountToRefund <= decimal.Zero) throw new SmartException("Enter amount to refund"); decimal maxAmountToRefund = order.OrderTotal - order.RefundedAmount; if (amountToRefund > maxAmountToRefund) amountToRefund = maxAmountToRefund; var errors = new List<string>(); if (online) errors = _orderProcessingService.PartiallyRefund(order, amountToRefund).ToList(); else _orderProcessingService.PartiallyRefundOffline(order, amountToRefund); if (errors.Count == 0) { //success ViewBag.RefreshPage = true; ViewBag.btnId = btnId; ViewBag.formId = formId; PrepareOrderDetailsModel(model, order); return View(model); } else { //error PrepareOrderDetailsModel(model, order); foreach (var error in errors) NotifyError(error, false); return View(model); } } catch (Exception exc) { //error PrepareOrderDetailsModel(model, order); NotifyError(exc, false); return View(model); } }
public ActionResult ActivateDownloadOrderItem(int id, FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) //No order found with the specified id return RedirectToAction("List"); //get order item identifier int orderItemId = 0; foreach (var formValue in form.AllKeys) if (formValue.StartsWith("btnPvActivateDownload", StringComparison.InvariantCultureIgnoreCase)) orderItemId = Convert.ToInt32(formValue.Substring("btnPvActivateDownload".Length)); var orderItem = order.OrderItems.Where(x => x.Id == orderItemId).FirstOrDefault(); if (orderItem == null) throw new ArgumentException("No order item found with the specified id"); orderItem.IsDownloadActivated = !orderItem.IsDownloadActivated; _orderService.UpdateOrder(order); var model = new OrderModel(); PrepareOrderDetailsModel(model, order); return View(model); }
public ActionResult OrderList(GridCommand command, OrderListModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); DateTime? startDateValue = (model.StartDate == null) ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone); DateTime? endDateValue = (model.EndDate == null) ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1); var orderStatusIds = model.OrderStatusIds.ToIntArray(); var paymentStatusIds = model.PaymentStatusIds.ToIntArray(); var shippingStatusIds = model.ShippingStatusIds.ToIntArray(); var orders = _orderService.SearchOrders(model.StoreId, 0, startDateValue, endDateValue, orderStatusIds, paymentStatusIds, shippingStatusIds, model.CustomerEmail, model.OrderGuid, model.OrderNumber, command.Page - 1, command.PageSize, model.CustomerName); var gridModel = new GridModel<OrderModel> { Data = orders.Select(x => { var store = _storeService.GetStoreById(x.StoreId); return new OrderModel() { Id = x.Id, OrderNumber = x.GetOrderNumber(), StoreName = store != null ? store.Name : "Unknown", OrderTotal = _priceFormatter.FormatPrice(x.OrderTotal, true, false), OrderStatus = x.OrderStatus.GetLocalizedEnum(_localizationService, _workContext), PaymentStatus = x.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext), ShippingStatus = x.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext), CustomerEmail = x.BillingAddress.Email, CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc) }; }), Total = orders.TotalCount }; //summary report //implemented as a workaround described here: http://www.telerik.com/community/forums/aspnet-mvc/grid/gridmodel-aggregates-how-to-use.aspx var reportSummary = _orderReportService.GetOrderAverageReportLine(model.StoreId, orderStatusIds, paymentStatusIds, shippingStatusIds, startDateValue, endDateValue, model.CustomerEmail); var profit = _orderReportService.ProfitReport(model.StoreId, orderStatusIds, paymentStatusIds, shippingStatusIds, startDateValue, endDateValue, model.CustomerEmail); var aggregator = new OrderModel() { aggregatorprofit = _priceFormatter.FormatPrice(profit, true, false), aggregatortax = _priceFormatter.FormatPrice(reportSummary.SumTax, true, false), aggregatortotal = _priceFormatter.FormatPrice(reportSummary.SumOrders, true, false) }; gridModel.Aggregates = aggregator; return new JsonResult { Data = gridModel }; }
public ActionResult PartiallyRefundOrderPopup(int id, bool online) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) //No order found with the specified id return RedirectToAction("List"); var model = new OrderModel(); PrepareOrderDetailsModel(model, order); return View(model); }
public ActionResult EditOrderTotals(int id, OrderModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) //No order found with the specified id return RedirectToAction("List"); order.OrderSubtotalInclTax = model.OrderSubtotalInclTaxValue; order.OrderSubtotalExclTax = model.OrderSubtotalExclTaxValue; order.OrderSubTotalDiscountInclTax = model.OrderSubTotalDiscountInclTaxValue; order.OrderSubTotalDiscountExclTax = model.OrderSubTotalDiscountExclTaxValue; order.OrderShippingInclTax = model.OrderShippingInclTaxValue; order.OrderShippingExclTax = model.OrderShippingExclTaxValue; order.PaymentMethodAdditionalFeeInclTax = model.PaymentMethodAdditionalFeeInclTaxValue; order.PaymentMethodAdditionalFeeExclTax = model.PaymentMethodAdditionalFeeExclTaxValue; order.TaxRates = model.TaxRatesValue; order.OrderTax = model.TaxValue; order.OrderDiscount = model.OrderTotalDiscountValue; order.OrderTotal = model.OrderTotalValue; _orderService.UpdateOrder(order); PrepareOrderDetailsModel(model, order); return View(model); }
public ActionResult EditDirectDebitInfo(int id, OrderModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) //No order found with the specified id return RedirectToAction("List"); if (order.AllowStoringDirectDebit) { string accountHolder = model.DirectDebitAccountHolder; string accountNumber = model.DirectDebitAccountNumber; string bankCode = model.DirectDebitBankCode; string bankName = model.DirectDebitBankName; string bic = model.DirectDebitBIC; string country = model.DirectDebitCountry; string iban = model.DirectDebitIban; order.DirectDebitAccountHolder = _encryptionService.EncryptText(accountHolder); order.DirectDebitAccountNumber = _encryptionService.EncryptText(accountNumber); order.DirectDebitBankCode = _encryptionService.EncryptText(bankCode); order.DirectDebitBankName = _encryptionService.EncryptText(bankName); order.DirectDebitBIC = _encryptionService.EncryptText(bic); order.DirectDebitCountry = _encryptionService.EncryptText(country); order.DirectDebitIban = _encryptionService.EncryptText(iban); _orderService.UpdateOrder(order); } PrepareOrderDetailsModel(model, order); return View(model); }
public ActionResult EditCreditCardInfo(int id, OrderModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) //No order found with the specified id return RedirectToAction("List"); if (order.AllowStoringCreditCardNumber) { string cardType = model.CardType; string cardName = model.CardName; string cardNumber = model.CardNumber; string cardCvv2 = model.CardCvv2; string cardExpirationMonth = model.CardExpirationMonth; string cardExpirationYear = model.CardExpirationYear; order.CardType = _encryptionService.EncryptText(cardType); order.CardName = _encryptionService.EncryptText(cardName); order.CardNumber = _encryptionService.EncryptText(cardNumber); order.MaskedCreditCardNumber = _encryptionService.EncryptText(_paymentService.GetMaskedCreditCardNumber(cardNumber)); order.CardCvv2 = _encryptionService.EncryptText(cardCvv2); order.CardExpirationMonth = _encryptionService.EncryptText(cardExpirationMonth); order.CardExpirationYear = _encryptionService.EncryptText(cardExpirationYear); _orderService.UpdateOrder(order); } PrepareOrderDetailsModel(model, order); return View(model); }
public ActionResult EditOrderItem(int id, FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null) //No order found with the specified id return RedirectToAction("List"); ViewData["selectedTab"] = "products"; //get order item identifier int orderItemId = 0; foreach (var formValue in form.AllKeys) if (formValue.StartsWith("btnSaveOrderItem", StringComparison.InvariantCultureIgnoreCase)) orderItemId = Convert.ToInt32(formValue.Substring("btnSaveOrderItem".Length)); var orderItem = order.OrderItems.Where(x => x.Id == orderItemId).FirstOrDefault(); if (orderItem == null) throw new ArgumentException("No order item found with the specified id"); decimal unitPriceInclTax, unitPriceExclTax, discountInclTax, discountExclTax,priceInclTax,priceExclTax; int quantity; if (!decimal.TryParse(form["pvUnitPriceInclTax" + orderItemId], out unitPriceInclTax)) unitPriceInclTax =orderItem.UnitPriceInclTax; if (!decimal.TryParse(form["pvUnitPriceExclTax" + orderItemId], out unitPriceExclTax)) unitPriceExclTax = orderItem.UnitPriceExclTax; if (!int.TryParse(form["pvQuantity" + orderItemId], out quantity)) quantity = orderItem.Quantity; if (!decimal.TryParse(form["pvDiscountInclTax" + orderItemId], out discountInclTax)) discountInclTax = orderItem.DiscountAmountInclTax; if (!decimal.TryParse(form["pvDiscountExclTax" + orderItemId], out discountExclTax)) discountExclTax = orderItem.DiscountAmountExclTax; if (!decimal.TryParse(form["pvPriceInclTax" + orderItemId], out priceInclTax)) priceInclTax = orderItem.PriceInclTax; if (!decimal.TryParse(form["pvPriceExclTax" + orderItemId], out priceExclTax)) priceExclTax = orderItem.PriceExclTax; if (quantity > 0) { orderItem.UnitPriceInclTax = unitPriceInclTax; orderItem.UnitPriceExclTax = unitPriceExclTax; orderItem.Quantity = quantity; orderItem.DiscountAmountInclTax = discountInclTax; orderItem.DiscountAmountExclTax = discountExclTax; orderItem.PriceInclTax = priceInclTax; orderItem.PriceExclTax = priceExclTax; _orderService.UpdateOrder(order); } else { _orderService.DeleteOrderItem(orderItem); } var model = new OrderModel(); PrepareOrderDetailsModel(model, order); return View(model); }
public ActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var order = _orderService.GetOrderById(id); if (order == null || order.Deleted) return RedirectToAction("List"); var model = new OrderModel(); PrepareOrderDetailsModel(model, order); return View(model); }