internal static IList <OrderlineViewModel> GetOrderLineList(Ucommerce.EntitiesV2.PurchaseOrder basket, Guid productDetailsPageId) { var CatalogLibrary = ObjectFactory.Instance.Resolve <ICatalogLibrary>(); var result = new List <OrderlineViewModel>(); foreach (var orderLine in basket.OrderLines) { var product = CatalogLibrary.GetProduct(orderLine.Sku); var imageService = ObjectFactory.Instance.Resolve <IImageService>(); var currencyIsoCode = basket.BillingCurrency.ISOCode; var orderLineViewModel = new OrderlineViewModel { Quantity = orderLine.Quantity, ProductName = orderLine.ProductName, Sku = orderLine.Sku, VariantSku = orderLine.VariantSku, Total = new Money(orderLine.Total.GetValueOrDefault(), currencyIsoCode).ToString(), Discount = orderLine.Discount, Tax = new Money(orderLine.VAT, currencyIsoCode).ToString(), Price = new Money(orderLine.Price, currencyIsoCode).ToString(), ProductUrl = GetProductUrl(product, productDetailsPageId), PriceWithDiscount = new Money(orderLine.Price - orderLine.UnitDiscount.GetValueOrDefault(), currencyIsoCode).ToString(), OrderLineId = orderLine.OrderLineId, ThumbnailName = product.Name, ThumbnailUrl = product.ThumbnailImageUrl }; result.Add(orderLineViewModel); } return(result); }
private ConfirmationEmailViewModel MapPurchaseOrder(Ucommerce.EntitiesV2.PurchaseOrder purchaseOrder, ConfirmationEmailViewModel confirmationEmailViewModel) { confirmationEmailViewModel.BillingAddress = purchaseOrder.BillingAddress ?? new Ucommerce.EntitiesV2.OrderAddress(); confirmationEmailViewModel.ShipmentAddress = purchaseOrder.GetShippingAddress("Shipment") ?? new Ucommerce.EntitiesV2.OrderAddress(); foreach (var orderLine in purchaseOrder.OrderLines) { var orderLineCurrencyIsoCode = orderLine.PurchaseOrder.BillingCurrency.ISOCode; var orderLineModel = new ConfirmationEmailOrderLine { ProductName = orderLine.ProductName, Sku = orderLine.Sku, VariantSku = orderLine.VariantSku, Total = new Money(orderLine.Total.GetValueOrDefault(), orderLineCurrencyIsoCode).ToString(), Tax = new Money(orderLine.VAT, orderLineCurrencyIsoCode).ToString(), Price = new Money(orderLine.Price, orderLineCurrencyIsoCode).ToString(), PriceWithDiscount = new Money(orderLine.Price - orderLine.Discount, orderLineCurrencyIsoCode).ToString(), Quantity = orderLine.Quantity, Discount = orderLine.Discount }; confirmationEmailViewModel.OrderLines.Add(orderLineModel); } var currencyIsoCode = purchaseOrder.BillingCurrency.ISOCode; confirmationEmailViewModel.DiscountTotal = new Money(purchaseOrder.DiscountTotal.GetValueOrDefault(), currencyIsoCode).ToString(); confirmationEmailViewModel.DiscountAmount = purchaseOrder.DiscountTotal.GetValueOrDefault(); confirmationEmailViewModel.SubTotal = new Money(purchaseOrder.SubTotal.GetValueOrDefault(), currencyIsoCode).ToString(); confirmationEmailViewModel.OrderTotal = new Money(purchaseOrder.OrderTotal.GetValueOrDefault(), currencyIsoCode).ToString(); confirmationEmailViewModel.TaxTotal = new Money(purchaseOrder.TaxTotal.GetValueOrDefault(), currencyIsoCode).ToString(); confirmationEmailViewModel.ShippingTotal = new Money(purchaseOrder.ShippingTotal.GetValueOrDefault(), currencyIsoCode).ToString(); confirmationEmailViewModel.PaymentTotal = new Money(purchaseOrder.PaymentTotal.GetValueOrDefault(), currencyIsoCode).ToString(); confirmationEmailViewModel.OrderNumber = purchaseOrder.OrderNumber; confirmationEmailViewModel.CustomerName = purchaseOrder.Customer.FirstName; var shipment = purchaseOrder.Shipments.FirstOrDefault(); if (shipment != null) { confirmationEmailViewModel.ShipmentName = shipment.ShipmentName; confirmationEmailViewModel.ShipmentAmount = purchaseOrder.ShippingTotal.GetValueOrDefault(); } var payment = purchaseOrder.Payments.FirstOrDefault(); if (payment != null) { confirmationEmailViewModel.PaymentName = payment.PaymentMethodName; confirmationEmailViewModel.PaymentAmount = purchaseOrder.PaymentTotal.GetValueOrDefault(); } return(confirmationEmailViewModel); }
public virtual bool CanProcessRequest(Dictionary <string, object> parameters, out string message) { object mode = null; if (parameters.TryGetValue("mode", out mode) && mode != null) { if (mode.ToString() == "index") { if (Telerik.Sitefinity.Services.SystemManager.IsDesignMode) { message = "The widget is in Page Edit mode."; return(false); } } message = null; return(true); } else { Ucommerce.EntitiesV2.PurchaseOrder basketPurchaseOrder = null; try { basketPurchaseOrder = TransactionLibrary.GetBasket(); } catch (Exception ex) { Log.Write(ex, ConfigurationPolicy.ErrorLog); } if (basketPurchaseOrder != null) { var address = basketPurchaseOrder.GetAddress(Ucommerce.Constants.DefaultShipmentAddressName); if (address == null) { message = "Address must be specified"; return(false); } else { message = null; return(true); } } message = "The checkout is not started yet"; return(false); } }
private void GetDiscounts(CartRenderingViewModel basketVM, Ucommerce.EntitiesV2.PurchaseOrder basket) { foreach (var item in basket.Discounts) { if (!string.IsNullOrWhiteSpace(item.Description)) { if (item.Description.Contains(",")) { basketVM.Discounts = item.Description.Split(',').ToList(); } else { basketVM.Discounts.Add(item.Description); } } } }
private static CartUpdateBasketViewModel MapOrderline(Ucommerce.EntitiesV2.PurchaseOrder basket) { var updatedBasket = new CartUpdateBasketViewModel(); foreach (var orderLine in basket.OrderLines) { var currencyIsoCode = basket.BillingCurrency.ISOCode; var orderLineViewModel = new CartUpdateOrderline(); orderLineViewModel.OrderlineId = orderLine.OrderLineId; orderLineViewModel.Quantity = orderLine.Quantity; orderLineViewModel.Total = new Money(orderLine.Total.GetValueOrDefault(), currencyIsoCode).ToString(); orderLineViewModel.Discount = orderLine.Discount; orderLineViewModel.Tax = new Money(orderLine.VAT, currencyIsoCode).ToString(); orderLineViewModel.Price = new Money(orderLine.Price, currencyIsoCode).ToString(); orderLineViewModel.PriceWithDiscount = new Money(orderLine.Price - orderLine.Discount, currencyIsoCode).ToString(); updatedBasket.OrderLines.Add(orderLineViewModel); } return(updatedBasket); }
public virtual MiniBasketRenderingViewModel CreateViewModel(string refreshUrl) { var viewModel = new MiniBasketRenderingViewModel(); if (!TransactionLibrary.HasBasket()) { return(viewModel); } Ucommerce.EntitiesV2.PurchaseOrder basket = TransactionLibrary.GetBasket(false); viewModel.OrderLines = CartModel.GetOrderLineList(basket, this.productDetailsPageId); viewModel.NumberOfItems = GetNumberOfItemsInBasket(); viewModel.IsEmpty = IsBasketEmpty(viewModel); viewModel.Total = GetBasketTotal(); viewModel.RefreshUrl = refreshUrl; viewModel.CartPageUrl = GetPageAbsoluteUrl(this.cartPageId); viewModel.CheckoutPageUrl = GetPageAbsoluteUrl(this.checkoutPageId); return(viewModel); }
public virtual ShippingPickerViewModel GetViewModel() { var shipmentPickerViewModel = new ShippingPickerViewModel(); Ucommerce.EntitiesV2.PurchaseOrder basketPurchaseOrder = null; try { basketPurchaseOrder = TransactionLibrary.GetBasket(); } catch (Exception ex) { Log.Write(ex, ConfigurationPolicy.ErrorLog); return(null); } if (!basketPurchaseOrder.OrderLines.Any()) { return(null); } if (TransactionLibrary.HasBasket()) { var shippingCountry = basketPurchaseOrder.GetAddress(Ucommerce.Constants.DefaultShipmentAddressName)? .Country; if (shippingCountry != null) { shipmentPickerViewModel.ShippingCountry = shippingCountry.Name; var availableShippingMethods = TransactionLibrary.GetShippingMethods(shippingCountry); if (basketPurchaseOrder.Shipments.Count > 0) { shipmentPickerViewModel.SelectedShippingMethodId = basketPurchaseOrder.Shipments.FirstOrDefault()?.ShippingMethod.ShippingMethodId ?? 0; } else { shipmentPickerViewModel.SelectedShippingMethodId = -1; } foreach (var availableShippingMethod in availableShippingMethods) { var priceGroup = Ucommerce.EntitiesV2.PriceGroup.FirstOrDefault(x => x.Guid == CatalogContext.CurrentPriceGroup.Guid); var localizedShippingMethod = availableShippingMethod.ShippingMethodDescriptions.FirstOrDefault(s => s.CultureCode.Equals(CultureInfo.CurrentCulture.ToString())); var price = availableShippingMethod.GetPriceForPriceGroup(priceGroup); var formattedPrice = new Money((price == null ? 0 : price.Price), basketPurchaseOrder.BillingCurrency.ISOCode); if (localizedShippingMethod != null) { var displayName = localizedShippingMethod.DisplayName; if (string.IsNullOrWhiteSpace(displayName)) { displayName = availableShippingMethod.Name; } shipmentPickerViewModel.AvailableShippingMethods.Add(new SelectListItem() { Selected = shipmentPickerViewModel.SelectedShippingMethodId == availableShippingMethod.ShippingMethodId, Text = String.Format(" {0} ({1})", displayName, formattedPrice), Value = availableShippingMethod.ShippingMethodId.ToString() }); } } } } TransactionLibrary.ExecuteBasketPipeline(); shipmentPickerViewModel.NextStepUrl = GetNextStepUrl(nextStepId); shipmentPickerViewModel.PreviousStepUrl = GetPreviousStepUrl(previousStepId); return(shipmentPickerViewModel); }
private static void MapAddresses(Ucommerce.EntitiesV2.PurchaseOrder purchaseOrder, BasketPreviewViewModel basketPreviewViewModel) { if (purchaseOrder.BillingAddress != null) { if (!purchaseOrder.BillingAddress.FirstName.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.FirstName = purchaseOrder.BillingAddress.FirstName; } if (!purchaseOrder.BillingAddress.LastName.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.LastName = purchaseOrder.BillingAddress.LastName; } if (!purchaseOrder.BillingAddress.EmailAddress.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.EmailAddress = purchaseOrder.BillingAddress.EmailAddress; } if (!purchaseOrder.BillingAddress.PhoneNumber.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.PhoneNumber = purchaseOrder.BillingAddress.PhoneNumber; } if (!purchaseOrder.BillingAddress.MobilePhoneNumber.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.MobilePhoneNumber = purchaseOrder.BillingAddress.MobilePhoneNumber; } if (!purchaseOrder.BillingAddress.Line1.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.Line1 = purchaseOrder.BillingAddress.Line1; } if (!purchaseOrder.BillingAddress.Line2.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.Line2 = purchaseOrder.BillingAddress.Line2; } if (!purchaseOrder.BillingAddress.PostalCode.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.PostalCode = purchaseOrder.BillingAddress.PostalCode; } if (!purchaseOrder.BillingAddress.City.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.City = purchaseOrder.BillingAddress.City; } if (!purchaseOrder.BillingAddress.State.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.State = purchaseOrder.BillingAddress.State; } if (!purchaseOrder.BillingAddress.Attention.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.Attention = purchaseOrder.BillingAddress.Attention; } if (!purchaseOrder.BillingAddress.CompanyName.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.CompanyName = purchaseOrder.BillingAddress.CompanyName; } if (purchaseOrder.BillingAddress.Country.CountryId > 0) { basketPreviewViewModel.BillingAddress.Country.CountryId = purchaseOrder.BillingAddress.Country.CountryId; } if (!purchaseOrder.BillingAddress.Country.Name.IsNullOrWhitespace()) { basketPreviewViewModel.BillingAddress.Country.Name = purchaseOrder.BillingAddress.Country.Name; } } var shipmentAddress = purchaseOrder.GetShippingAddress(Ucommerce.Constants.DefaultShipmentAddressName); if (shipmentAddress != null) { if (!shipmentAddress.FirstName.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.FirstName = shipmentAddress.FirstName; } if (!shipmentAddress.LastName.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.LastName = shipmentAddress.LastName; } if (!shipmentAddress.EmailAddress.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.EmailAddress = shipmentAddress.EmailAddress; } if (!shipmentAddress.PhoneNumber.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.PhoneNumber = shipmentAddress.PhoneNumber; } if (!shipmentAddress.MobilePhoneNumber.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.MobilePhoneNumber = shipmentAddress.MobilePhoneNumber; } if (!shipmentAddress.Line1.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.Line1 = shipmentAddress.Line1; } if (!shipmentAddress.Line2.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.Line2 = shipmentAddress.Line2; } if (!shipmentAddress.PostalCode.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.PostalCode = shipmentAddress.PostalCode; } if (!shipmentAddress.City.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.City = shipmentAddress.City; } if (!shipmentAddress.State.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.State = shipmentAddress.State; } if (!shipmentAddress.Attention.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.Attention = shipmentAddress.Attention; } if (!shipmentAddress.CompanyName.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.CompanyName = shipmentAddress.CompanyName; } if (shipmentAddress.Country.CountryId > 0) { basketPreviewViewModel.ShipmentAddress.Country.CountryId = shipmentAddress.Country.CountryId; } if (!shipmentAddress.Country.Name.IsNullOrWhitespace()) { basketPreviewViewModel.ShipmentAddress.Country.Name = shipmentAddress.Country.Name; } } }