Esempio n. 1
0
        protected virtual AddressViewModel GetBillingAddressViewModel(CreateOrderDetailViewModelParam param)
        {
            var validPayment = param.Order.Cart.Payments.Where(x => !x.IsVoided()).FirstOrDefault();
            var payment      = validPayment ?? param.Order.Cart.Payments.FirstOrDefault();

            return(payment == null ? null : CartViewModelFactory.GetAddressViewModel(payment.BillingAddress, param.CultureInfo));
        }
        protected virtual AddressViewModel GetShippingAddressViewModel(CreateOrderDetailViewModelParam param)
        {
            Shipment shipment = GetActiveShipments(param.Order).FirstOrDefault();

            if (shipment == null)
            {
                return(new AddressViewModel());
            }

            // ReSharper disable once PossibleNullReferenceException (The address can be null we will create one)
            return(CartViewModelFactory.GetAddressViewModel(shipment.Address, param.CultureInfo));
        }
Esempio n. 3
0
        public virtual OrderSummaryPaymentViewModel BuildOrderSummaryPaymentViewModel(Overture.ServiceModel.Orders.Payment payment, CultureInfo cultureInfo)
        {
            var methodDisplayNames = LookupService.GetLookupDisplayNamesAsync(new GetLookupDisplayNamesParam
            {
                CultureInfo = cultureInfo,
                LookupType  = LookupType.Order,
                LookupName  = "PaymentMethodType",
            }).Result;

            var paymentMethodDisplayName = methodDisplayNames.FirstOrDefault(x => x.Key == payment.PaymentMethod.Type.ToString()).Value;

            var paymentVm = new OrderSummaryPaymentViewModel
            {
                FirstName         = payment.BillingAddress == null ? null: payment.BillingAddress.FirstName,
                LastName          = payment.BillingAddress == null? null : payment.BillingAddress.LastName,
                PaymentMethodName = paymentMethodDisplayName,
            };

            paymentVm.BillingAddress = CartViewModelFactory.GetAddressViewModel(payment.BillingAddress, cultureInfo);
            paymentVm.Amount         = LocalizationProvider.FormatPrice((decimal)payment.Amount, cultureInfo);

            return(paymentVm);
        }
        protected virtual OrderShipmentDetailViewModel GetOrderShipmentDetailViewModel(Shipment shipment, CreateOrderDetailViewModelParam param)
        {
            var shipmentVm = new OrderShipmentDetailViewModel();

            var index = param.Order.Cart.Shipments.IndexOf(shipment);

            if (index >= 0)
            {
                shipmentVm.Index = (index + 1).ToString();
            }

            if (shipment.FulfillmentScheduledTimeBeginDate.HasValue)
            {
                shipmentVm.ScheduledShipDate = LocalizationHelper.LocalizedFormat("General", "ShortDateFormat", shipment.FulfillmentScheduledTimeBeginDate.Value, param.CultureInfo);
            }

            shipmentVm.LineItems = LineItemViewModelFactory.CreateViewModel(new CreateListOfLineItemDetailViewModelParam
            {
                Cart        = param.Order.Cart,
                LineItems   = shipment.LineItems,
                CultureInfo = param.CultureInfo,
                ImageInfo   = param.ProductImageInfo,
                BaseUrl     = param.BaseUrl
            }).ToList();

            if (param.ShipmentsNotes != null && param.ShipmentsNotes.ContainsKey(shipment.Id))
            {
                var notes = param.ShipmentsNotes[shipment.Id];
                shipmentVm.Comments = notes;
            }

            shipmentVm.Rewards = RewardViewModelFactory.CreateViewModel(shipment.Rewards, param.CultureInfo, RewardLevel.FulfillmentMethod, RewardLevel.Shipment).ToList();

            shipmentVm.ShippingAddress = CartViewModelFactory.GetAddressViewModel(shipment.Address, param.CultureInfo);

            var fulfillmentMethodName    = shipment.FulfillmentMethod.Name;
            var shippingTrackingProvider = ShippingTrackingProviderFactory.ResolveProvider(fulfillmentMethodName);

            shipmentVm.TrackingInfo = shippingTrackingProvider.GetTrackingInfoViewModel(shipment, param.CultureInfo);
            shipmentVm.History      = GetOrderChangesViewModel(param.OrderChanges, param.CultureInfo, _shipmentStatus);
            if (!string.IsNullOrWhiteSpace(shipment.Status))
            {
                shipmentVm.ShipmentStatusName = shipment.Status;
                if (param.ShipmentStatuses.TryGetValue(shipment.Status, out string shipmentStatusLookup))
                {
                    shipmentVm.ShipmentStatus = shipmentStatusLookup;
                }

                if (shipmentVm.History.Any(h => h.NewValue.Equals(shipment.Status)))
                {
                    shipmentVm.ShipmentStatusDate = shipmentVm.History.OrderByDescending(x => x.Date).First(h => h.NewValue.Equals(shipment.Status)).Date;
                }
            }
            else
            {
                shipmentVm.ShipmentStatusName = string.Empty;
                shipmentVm.ShipmentStatus     = string.Empty;
                shipmentVm.ShipmentStatusDate = string.Empty;
            }

            shipmentVm.ShippingMethod = GetShippingMethodViewModel(shipment, param);
            return(shipmentVm);
        }
        public virtual OrderSummaryPaymentViewModel BuildOrderSummaryPaymentViewModel(Overture.ServiceModel.Orders.Payment payment, CultureInfo cultureInfo)
        {
            var creditCartNumber  = string.Empty;
            var expiryDate        = string.Empty;
            var paymentMethodName = string.Empty;

            if (payment.PaymentMethod.PropertyBag != null)
            {
                //TODO : use viewmodelmapper through cartviewmodelfactory ( already exist )
                if (payment.PaymentMethod.Type == PaymentMethodType.SavedCreditCard)
                {
                    if (payment.PaymentMethod.PropertyBag.ContainsKey(SavedCardMask))
                    {
                        creditCartNumber = payment.PaymentMethod.PropertyBag[SavedCardMask].ToString();
                    }

                    if (payment.PaymentMethod.PropertyBag.ContainsKey(SavedExpiryDate))
                    {
                        expiryDate = payment.PaymentMethod.PropertyBag[SavedExpiryDate].ToString();
                    }

                    if (payment.PaymentMethod.PropertyBag.ContainsKey(SavedCardType))
                    {
                        paymentMethodName = payment.PaymentMethod.PropertyBag[SavedCardType].ToString();
                    }
                }
                else
                {
                    if (payment.PaymentMethod.PropertyBag.ContainsKey(CreditCardPaymentProperties.CreditCardNumberLastDigitsKey))
                    {
                        creditCartNumber = payment.PaymentMethod.PropertyBag[CreditCardPaymentProperties.CreditCardNumberLastDigitsKey].ToString();
                    }

                    if (payment.PaymentMethod.PropertyBag.ContainsKey(CreditCardPaymentProperties.CreditCardExpiryDateKey))
                    {
                        expiryDate = payment.PaymentMethod.PropertyBag[CreditCardPaymentProperties.CreditCardExpiryDateKey].ToString();
                    }

                    if (payment.PaymentMethod.PropertyBag.ContainsKey(CreditCardPaymentProperties.CreditCardBrandKey))
                    {
                        paymentMethodName = payment.PaymentMethod.PropertyBag[CreditCardPaymentProperties.CreditCardBrandKey].ToString();
                    }
                }
            }

            DateTime expirationDate;
            bool     hasExpired = false;

            if (DateTime.TryParse(expiryDate, out expirationDate))
            {
                hasExpired = expirationDate < DateTime.UtcNow;
            }

            var paymentVm = new OrderSummaryPaymentViewModel
            {
                FirstName         = payment.BillingAddress.FirstName,
                LastName          = payment.BillingAddress.LastName,
                PaymentMethodName = paymentMethodName,
                CreditCardNumber  = creditCartNumber,
                ExpiryDate        = expiryDate,
                IsExpired         = hasExpired
            };

            paymentVm.BillingAddress = CartViewModelFactory.GetAddressViewModel(payment.BillingAddress, cultureInfo);
            paymentVm.Amount         = LocalizationProvider.FormatPrice((decimal)payment.Amount, cultureInfo);

            return(paymentVm);
        }