コード例 #1
0
        public static CallResult <List <ShippingMethodViewModel> > GetShippingOptionsWithRate(IUnitOfWork db,
                                                                                              ILogService log,
                                                                                              ITime time,
                                                                                              IShipmentApi rateProvider,
                                                                                              IShippingService shippingService,
                                                                                              AddressDTO fromAddress,
                                                                                              AddressDTO toAddress,
                                                                                              DateTime shipDate,
                                                                                              int weightLb,
                                                                                              decimal weightOz,
                                                                                              decimal insuredValue,
                                                                                              OrderRateInfo orderInfo)
        {
            var result        = new CallResult <List <ShippingMethodViewModel> >();
            var pickupAddress = fromAddress;

            var rateResult = rateProvider.GetAllRate(
                fromAddress,
                pickupAddress,
                toAddress,
                shipDate,
                (double)(weightLb * 16 + weightOz),
                null,
                0,
                false,
                orderInfo,
                RetryModeType.Fast);

            if (rateResult.Result != GetRateResultType.Success)
            {
                result.Status  = CallStatus.Fail;
                result.Message = rateResult.Message;
                return(result);
            }

            var methodList = GetShippingMethods(db,
                                                fromAddress.FinalCountry,
                                                toAddress.FinalCountry,
                                                weightLb,
                                                weightOz,
                                                rateProvider.Type);


            result.Data   = new List <ShippingMethodViewModel>();
            result.Status = CallStatus.Success;

            foreach (var method in methodList)
            {
                var rate = rateResult.Rates.FirstOrDefault(r => r.ServiceIdentifier == method.ServiceIdentifier);

                if (rate != null)
                {
                    //var deliveryDays = time.GetBizDaysCount(rate.ShipDate, rate.DeliveryDate);
                    var    deliveryDaysInfo = rate.DeliveryDaysInfo;
                    string providerPrefix   = "";
                    switch ((ShipmentProviderType)method.ShipmentProviderType)
                    {
                    case ShipmentProviderType.Amazon:
                        providerPrefix = "AMZ ";
                        break;

                    case ShipmentProviderType.Stamps:
                        providerPrefix = "";
                        break;

                    case ShipmentProviderType.Dhl:
                        providerPrefix = "";
                        break;

                    case ShipmentProviderType.DhlECom:
                        providerPrefix = "";
                        break;
                    }

                    var adjustedAmount = shippingService.ApplyCharges(method.Id, rate.Amount);

                    result.Data.Add(new ShippingMethodViewModel()
                    {
                        Id             = method.Id,
                        ProviderPrefix = providerPrefix,
                        Carrier        = method.CarrierName,
                        Name           = ShippingUtils.PrepareMethodNameToDisplay(method.Name, deliveryDaysInfo),
                        Rate           = adjustedAmount,
                    });
                }
            }

            return(result);
        }
コード例 #2
0
        public static OrderQuickSummaryViewModel GetByOrderId(IUnitOfWork db,
                                                              ILogService log,
                                                              IWeightService weightService,
                                                              string orderId)
        {
            DTOOrder order = null;

            if (!String.IsNullOrEmpty(orderId))
            {
                orderId = orderId.RemoveWhitespaces();
                var orderNumber = OrderHelper.RemoveOrderNumberFormat(orderId);
                var filter      = new OrderSearchFilter()
                {
                    EqualOrderNumber = orderNumber,
                    IncludeMailInfos = true,
                    IncludeNotify    = false,

                    UnmaskReferenceStyles = false,
                };

                order = db.ItemOrderMappings
                        .GetFilteredOrdersWithItems(weightService, filter)
                        .FirstOrDefault();
            }

            if (order == null)
            {
                return(null);
            }
            else
            {
                var refundRequestList = RefundViewModel.GetByOrderId(db, order.OrderId);

                var shippingPrice = 0M;

                var activeShippings = order.ShippingInfos.Where(i => i.IsActive).ToList();
                activeShippings.AddRange(order.MailInfos);
                activeShippings = activeShippings.OrderBy(sh => sh.LabelPurchaseDate).ToList();
                //if (order.MailInfos.Any(m => !m.LabelCanceled)
                //    && order.ShippingInfos.All(sh => String.IsNullOrEmpty(sh.LabelPath) || sh.LabelCanceled))
                //{
                //    var mailShipping = order.MailInfos.OrderBy(m => m.LabelPurchaseDate).FirstOrDefault(l => !l.LabelCanceled);
                //    activeShippings = new List<OrderShippingInfoDTO>() { mailShipping };
                //}
                //var mainActiveShipping = activeShippings.FirstOrDefault();
                //var shipmentProviderType = mainActiveShipping != null ? mainActiveShipping.ShipmentProviderType : (int)Core.Models.Settings.ShipmentProviderType.Stamps;
                var address = order.GetAddressDto();

                return(new OrderQuickSummaryViewModel()
                {
                    OrderID = order.OrderId,
                    OrderEntityId = order.Id,
                    OrderDate = order.OrderDate,
                    OrderStatus = order.OrderStatus,
                    Market = (MarketType)order.Market,
                    MarketplaceId = order.MarketplaceId,

                    OrderIsOnHold = order.OnHold,

                    WeightLb = (int)Math.Floor(order.WeightD / 16),
                    WeightOz = order.WeightD % 16,

                    TrackingNumbers = activeShippings.Where(t => !String.IsNullOrEmpty(t.TrackingNumber)).Select(t => new LabelViewModel()
                    {
                        TrackingNumber = t.TrackingNumber,
                        Carrier = t.ShippingMethod.CarrierName,
                        FromType = (LabelFromType)t.LabelFromType,
                        TrackingStatusSource = t.TrackingStateSource,
                        ShippingDate = t.ShippingDate,
                        EstDeliveryDate = t.EstimatedDeliveryDate,
                        ActualDeliveryDate = t.ActualDeliveryDate,
                        LastTrackingStateUpdateDate = t.LastTrackingRequestDate,
                        IsCanceled = t.CancelLabelRequested || t.LabelCanceled,
                        DeliveryStatusMessage = GetDeliveryStatus(order.LatestDeliveryDate,
                                                                  t.ActualDeliveryDate,
                                                                  t.TrackingStateDate,
                                                                  t.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender),
                        ShippingMethodName = t.ShippingMethod != null
                            ? ShippingUtils.PrepareMethodNameToDisplay(t.ShippingMethod.Name, t.DeliveryDaysInfo) : string.Empty,
                        ShippingProviderName = ShipmentProviderHelper.GetName((ShipmentProviderType)t.ShipmentProviderType),
                    }).ToList(),

                    PriceCurrency = PriceHelper.FormatCurrency(order.TotalPriceCurrency),

                    ExpectedShipDate = order.LatestShipDate,
                    ExpectedDeliveryDate = order.LatestDeliveryDate,

                    //ShippingMethodName = mainActiveShipping != null && mainActiveShipping.ShippingMethod != null
                    //    ? ShippingUtils.PrepareMethodNameToDisplay(mainActiveShipping.ShippingMethod.Name, mainActiveShipping.DeliveryDaysInfo) : string.Empty,
                    //ShippingProviderName = ShipmentProviderHelper.GetName((ShipmentProviderType)shipmentProviderType),
                    //ShippingDate = activeShippings.Where(i => i.IsActive).Max(i => i.ShippingDate),

                    //DeliveryDate = mainActiveShipping != null ? mainActiveShipping.ActualDeliveryDate : null,
                    //DeliveryStatus = GetDeliveryStatus(order.LatestDeliveryDate,
                    //    mainActiveShipping != null ? mainActiveShipping.ActualDeliveryDate : null,
                    //    mainActiveShipping != null ? mainActiveShipping.TrackingStateDate : null,
                    //    mainActiveShipping != null ? mainActiveShipping.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender : false),

                    Refunds = refundRequestList,

                    Items = order.Items.Select(i => new OrderItemViewModel(i, false, false)).ToList(),

                    ToAddress = address,
                });
            }
        }