Esempio n. 1
0
        public bool IsAccept(OrderToTrackDTO orderToTrackInfo,
                             string status,
                             DateTime?statusDate,
                             IList <TrackingRecord> records)
        {
            var now   = _time.GetAppNowTime();
            var today = _time.GetAppNowTime().Date;

            var lastRecord    = records.FirstOrDefault();
            var packageGoBack = (lastRecord != null ? _addressService.IsMine(lastRecord.AsAddressDto()) : false) ||
                                orderToTrackInfo.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender;

            //почта после 60 дней за них не отвечает
            //старше 55 дней
            if (statusDate.HasValue &&
                statusDate.Value.AddDays(55) < today)
            {
                return(false);
            }

            if (packageGoBack)
            {
                return(false); //No actions if package go back
            }
            if (orderToTrackInfo.Carrier == ShippingServiceUtils.USPSCarrier)
            {
                if (statusDate.HasValue &&
                    !_time.IsBusinessDay(statusDate.Value) &&
                    _time.GetBizDaysCount(statusDate.Value, today) < 2)
                {
                    //TASK: Let’s not send Exception messages for First Class packages if they were not delivered on Weekends/holidays.
                    if (orderToTrackInfo.ShippingMethodId.HasValue
                        &&
                        ShippingUtils.GetShippingType(orderToTrackInfo.ShippingMethodId.Value) ==
                        ShippingTypeCode.Standard)
                    {
                        //Don’t send notice to first class orders which USPS tried to deliver on Saturday.
                        //They will automatically will redeliver it on the next business day.
                        return(false);
                    }


                    //TASK: if any package couldn’t be delivered to FF on weekends/holidays
                    if (AddressHelper.IsFFAddress(orderToTrackInfo.ShippingAddress))
                    {
                        return(false);
                    }
                }

                //TASK: If First Class order wasn’t delivered like 102-1600419-5915438 check again in 24 hours, and only then send notifications.
                if (orderToTrackInfo.ShippingMethodId.HasValue
                    &&
                    ShippingUtils.GetShippingType(orderToTrackInfo.ShippingMethodId.Value) == ShippingTypeCode.Standard)
                {
                    var statusNextBusiessDay = _time.AddBusinessDays(statusDate, 1);
                    if (statusNextBusiessDay > now)
                    {
                        return(false);
                    }
                }

                if (!String.IsNullOrEmpty(status) &&
                    (status.IndexOf("Notice Left", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Receptacle Blocked", StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Available for Pickup", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Business Closed", StringComparison.OrdinalIgnoreCase) >= 0 ||
                     status.IndexOf("Undeliverable as Addressed", StringComparison.OrdinalIgnoreCase) >= 0 ||
                     status.IndexOf("Addressee not available", StringComparison.OrdinalIgnoreCase) >= 0) &&
                    statusDate.HasValue)
                {
                    return(true);
                }
            }

            if (orderToTrackInfo.Carrier == ShippingServiceUtils.DHLCarrier ||
                orderToTrackInfo.Carrier == ShippingServiceUtils.DHLMXCarrier)
            {
                if (!String.IsNullOrEmpty(status) &&
                    status.IndexOf("Delivery attempted; recipient not home", StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                    statusDate.HasValue)
                {
                    return(true);
                }
            }

            return(false);
        }
        private bool UpdateOrder(IUnitOfWork db, ShippingDTO shipping)
        {
            _log.Info("Update order: id=" + shipping.OrderId + ", orderId=" + shipping.AmazonIdentifier + ", marketId=" + shipping.MarketOrderId);

            IList <OrderItemDTO> orderItems;

            if (shipping.IsFromMailPage)
            {
                orderItems = db.OrderItems.GetByOrderIdAsDto(shipping.OrderId)
                             //Remove canceled items with 0 price
                             .Where(m => m.ItemPrice > 0 || m.QuantityOrdered > 0).ToList();
            }
            else
            {
                orderItems = db.OrderItems.GetByShippingInfoIdAsDto(shipping.Id)
                             //Remove canceled items with 0 price
                             .Where(m => m.ItemPrice > 0 || m.QuantityOrdered > 0).ToList();
            }

            OrderHelper.PrepareSourceItemOrderId(orderItems);
            orderItems = OrderHelper.GroupBySourceItemOrderId(orderItems);

            DateTime?orderDate = null;

            if (shipping.OrderDate.HasValue)
            {
                orderDate = shipping.OrderDate.Value.ToUniversalTime();
            }
            var shippingDate = shipping.ShippingDate.ToUniversalTime();

            if (orderDate.HasValue && shippingDate < orderDate)
            {
                shippingDate = orderDate.Value.AddHours(2);
            }


            var result = _api.SubmitTrackingInfo(shipping.MarketOrderId,
                                                 shipping.TrackingNumber,
                                                 MarketUrlHelper.GetTrackingUrl(shipping.TrackingNumber, shipping.ShippingMethod.CarrierName),
                                                 shipping.ShippingMethod,
                                                 shipping.ShippingMethod.Name,
                                                 ShippingUtils.GetShippingType(shipping.ShippingMethodId),
                                                 ShippingUtils.FormattedToMarketCurrierName(shipping.ShippingMethod.CarrierName, shipping.ShippingMethod.IsInternational, _api.Market),
                                                 shippingDate,
                                                 orderItems,
                                                 shipping.MessageIdentifier.ToString());

            if (result.Status == CallStatus.Success)
            {
                _log.Info("Order was updated");
            }
            else
            {
                _log.Info("Order update errors: Message=" + result.Message);

                /*
                 * Walmart.Api.WalmartException: No response, statusCode=InternalServerError.
                 * Details: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns4:errors xmlns:ns2="http://walmart.com/mp/orders" xmlns:ns3="http://walmart.com/mp/v3/orders" xmlns:ns4="http://walmart.com/"><ns4:error><ns4:code>INVALID_REQUEST_CONTENT.GMP_ORDER_API</ns4:code><ns4:field>data</ns4:field><ns4:description>Unable to process this request. The Line: 4 of PO: 4576930294354 is in SHIPPED status</ns4:description><ns4:info>Request content is invalid.</ns4:info><ns4:severity>ERROR</ns4:severity><ns4:category>DATA</ns4:category><ns4:causes/><ns4:errorIdentifiers/></ns4:error></ns4:errors> ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
                 */
            }

            return(result.Status == CallStatus.Success);
        }
        private bool UpdateOrder(IUnitOfWork db, ShippingDTO shipping)
        {
            _log.Info("Update order: id=" + shipping.OrderId + ", orderId=" + shipping.AmazonIdentifier + ", marketId=" + shipping.MarketOrderId);

            IList <OrderItemDTO> orderItems;

            if (shipping.IsFromMailPage)
            {
                orderItems = db.OrderItems.GetByOrderIdAsDto(shipping.OrderId)
                             //Remove canceled items with 0 price
                             .Where(m => m.ItemPrice > 0 || m.QuantityOrdered > 0).ToList();
            }
            else
            {
                orderItems = db.OrderItems.GetByShippingInfoIdAsDto(shipping.Id)
                             //Remove canceled items with 0 price
                             .Where(m => m.ItemPrice > 0 || m.QuantityOrdered > 0).ToList();
            }

            OrderHelper.PrepareSourceItemOrderId(orderItems);
            orderItems = OrderHelper.GroupBySourceItemOrderId(orderItems);

            DateTime?orderDate = null;

            if (shipping.OrderDate.HasValue)
            {
                orderDate = shipping.OrderDate.Value.ToUniversalTime();
            }
            var shippingDate = shipping.ShippingDate.ToUniversalTime();

            if (orderDate.HasValue && shippingDate < orderDate)
            {
                shippingDate = orderDate.Value.AddHours(2);
            }

            var carrierName = shipping.ShippingMethod.CarrierName;

            if (!String.IsNullOrEmpty(shipping.CustomCurrier))
            {
                carrierName = shipping.CustomCurrier;
            }

            var result = _api.SubmitTrackingInfo(shipping.MarketOrderId,
                                                 shipping.TrackingNumber,
                                                 MarketUrlHelper.GetTrackingUrl(shipping.TrackingNumber, carrierName),
                                                 shipping.ShippingMethod.Name,
                                                 ShippingUtils.GetShippingType(shipping.ShippingMethodId),
                                                 ShippingUtils.FormattedToMarketCurrierName(carrierName, shipping.ShippingMethod.IsInternational, _api.Market),
                                                 shippingDate,
                                                 orderItems);

            if (result.Status == CallStatus.Success)
            {
                _log.Info("Order was updated");
            }
            else
            {
                _log.Fatal(_api.Market + ": Order update errors: Message=" + result.Message + ", Order=" + shipping.MarketOrderId);

                /*
                 * Walmart.Api.WalmartException: No response, statusCode=InternalServerError.
                 * Details: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns4:errors xmlns:ns2="http://walmart.com/mp/orders" xmlns:ns3="http://walmart.com/mp/v3/orders" xmlns:ns4="http://walmart.com/"><ns4:error><ns4:code>INVALID_REQUEST_CONTENT.GMP_ORDER_API</ns4:code><ns4:field>data</ns4:field><ns4:description>Unable to process this request. The Line: 4 of PO: 4576930294354 is in SHIPPED status</ns4:description><ns4:info>Request content is invalid.</ns4:info><ns4:severity>ERROR</ns4:severity><ns4:category>DATA</ns4:category><ns4:causes/><ns4:errorIdentifiers/></ns4:error></ns4:errors> ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
                 */

                if (StringHelper.ContainsNoCase(result.Exception?.Message, "doesn't have enough quantity to ship requested quantity"))
                {
                    var allUpdated = true;
                    //Send update by one items
                    foreach (var orderItem in orderItems)
                    {
                        var oneItemResult = _api.SubmitTrackingInfo(shipping.MarketOrderId,
                                                                    shipping.TrackingNumber,
                                                                    MarketUrlHelper.GetTrackingUrl(shipping.TrackingNumber, carrierName),
                                                                    shipping.ShippingMethod.Name,
                                                                    ShippingUtils.GetShippingType(shipping.ShippingMethodId),
                                                                    ShippingUtils.FormattedToMarketCurrierName(carrierName, shipping.ShippingMethod.IsInternational, _api.Market),
                                                                    shippingDate,
                                                                    new List <OrderItemDTO>()
                        {
                            orderItem
                        });

                        if (oneItemResult.Status == CallStatus.Success)
                        {
                            _log.Info("Order item " + orderItem.SKU + " was updated");
                        }
                        else
                        {
                            if (!StringHelper.ContainsNoCase(oneItemResult.Exception?.Message, "is in SHIPPED status") &&
                                !StringHelper.ContainsNoCase(oneItemResult.Exception?.Message, "qtyAvailableToShip :: 0"))
                            {
                                allUpdated = false;
                                _log.Fatal(_api.Market + ": Order item \"" + orderItem.SKU + "\" update errors: Message=" + oneItemResult.Message + ", Order=" + shipping.MarketOrderId);
                            }
                        }
                    }

                    if (allUpdated)
                    {
                        result = CallResult <DTOOrder> .Success(new DTOOrder());
                    }
                }
            }

            return(result.Status == CallStatus.Success);
        }
Esempio n. 4
0
        public bool IsAccept(OrderToTrackDTO orderToTrackInfo,
                             string status,
                             DateTime?statusDate,
                             IList <TrackingRecord> records)
        {
            var today = _time.GetAppNowTime().Date;

            if (orderToTrackInfo.LabelCanceled == true ||
                orderToTrackInfo.CancelLabelRequested == true)
            {
                return(false);
            }

            //почта после 60 дней за них не отвечает
            //старше 55 дней
            if (statusDate.HasValue &&
                statusDate.Value.AddDays(55) < today)
            {
                return(false);
            }

            if (orderToTrackInfo.LabelCanceled)
            {
                return(false);
            }

            if (orderToTrackInfo.ActualDeliveryDate.HasValue)
            {
                return(false);
            }

            if (status.IndexOf("Pre-Shipment Info Sent to USPS", StringComparison.InvariantCultureIgnoreCase) > 0)
            {
                return(false);
            }

            if (statusDate.HasValue && orderToTrackInfo.ShippingMethodId.HasValue)
            {
                var isInternational = ShippingUtils.IsInternationalShippingType(orderToTrackInfo.ShippingMethodId.Value);
                if (!isInternational)
                {
                    var shippingType = ShippingUtils.GetShippingType(orderToTrackInfo.ShippingMethodId.Value);

                    var periodDays = 4;
                    switch (shippingType)
                    {
                    case ShippingTypeCode.Standard:
                        periodDays = 4;
                        break;

                    case ShippingTypeCode.Priority:
                        periodDays = 2;
                        break;

                    case ShippingTypeCode.PriorityExpress:
                        periodDays = 1;
                        break;

                    case ShippingTypeCode.SameDay:
                        periodDays = 1;     //TODO: 0.5
                        break;
                    }

                    var dayCount = _time.GetBizDaysCount(statusDate.Value, today);
                    if (dayCount > periodDays)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public OrderChangeViewModel(OrderChangeHistoryDTO change, IList <EmailOrderDTO> emails)
        {
            //Value = change.ToValue;
            ChangedBy     = change.ChangedBy;
            ChangedByName = change.ChangedByName;
            ChangeDate    = change.ChangeDate;

            if (change.FieldName == OrderHistoryHelper.OnHoldKey && change.ToValue == "True")
            {
                ChangeType = OrderChangeTypes.Hold;
            }
            if (change.FieldName == OrderHistoryHelper.OnHoldKey && change.ToValue == "False")
            {
                ChangeType = OrderChangeTypes.UnHold;
            }
            if (change.FieldName == OrderHistoryHelper.ShippingMethodKey)
            {
                ChangeType = OrderChangeTypes.ChangeShippingMethod;
                Message    = "";
                int shippingMethodId;
                if (!String.IsNullOrEmpty(change.FromValue) && change.FromValue != "0")
                {
                    var parts = change.FromValue.Split(';');
                    if (Int32.TryParse(parts[0], out shippingMethodId))
                    {
                        Message = ShippingUtils.GetPackageType(shippingMethodId).ToString() + " - " +
                                  ShippingUtils.GetShippingType(shippingMethodId).ToString();
                    }
                }
                else
                {
                    Message = "-";
                }
                Message += " -> ";
                if (!String.IsNullOrEmpty(change.ToValue) && change.ToValue != "0")
                {
                    var parts = change.ToValue.Split(';');
                    if (Int32.TryParse(parts[0], out shippingMethodId))
                    {
                        Message += ShippingUtils.GetPackageType(shippingMethodId).ToString() + " - " +
                                   ShippingUtils.GetShippingType(shippingMethodId).ToString();
                    }
                }
                else
                {
                    Message += "-";
                }
            }
            if (change.FieldName == OrderHistoryHelper.EmailStatusChangedKey)
            {
                var toValue = (EmailResponseStatusEnum)Enum.Parse(typeof(EmailResponseStatusEnum), change.ToValue);
                if (toValue == EmailResponseStatusEnum.NoResponseNeeded)
                {
                    var email = emails.FirstOrDefault(e => e.Id.ToString() == change.ExtendFromValue);
                    ChangeType = OrderChangeTypes.EmailStatusChanged;
                    Message    = "Set No Response Needed";
                    if (email != null)
                    {
                        Value    = email.Subject;
                        ValueUrl = UrlHelper.GetViewEmailUrl(email.Id, email.OrderIdString);
                    }
                }
            }

            if (change.FieldName == OrderHistoryHelper.RecalculateRatesKey)
            {
                ChangeType = OrderChangeTypes.RatesRecalculated;
            }
            if (change.FieldName == OrderHistoryHelper.ShipmentProviderTypeKey)
            {
                ChangeType = OrderChangeTypes.ChangeShippingProvider;
                Message    = ""; //TODO:
            }

            if (change.FieldName == OrderHistoryHelper.AddToBatchKey && change.ToValue != null)
            {
                ChangeType = OrderChangeTypes.AddToBatch;
                Message    = StringHelper.GetFirstNotEmpty(change.ExtendToValue, "Orders page");
            }
            if (change.FieldName == OrderHistoryHelper.AddToBatchKey && change.ToValue == null)
            {
                ChangeType = OrderChangeTypes.RemoveFromBatch;
                Message    = "Name:" + (change.ExtendToValue ?? "-");
            }
            if (change.FieldName == OrderHistoryHelper.DismissAddressWarnKey)
            {
                ChangeType = OrderChangeTypes.DismissAddressWarn;
            }
            if (change.FieldName == OrderHistoryHelper.StatusChangedKey)
            {
                ChangeType = OrderChangeTypes.StatusChanged;
                Message    = change.FromValue + " -> " + change.ToValue;
            }

            if (change.FieldName == OrderHistoryHelper.ManuallyPersonNameKey ||
                change.FieldName == OrderHistoryHelper.ManuallyShippingAddress1Key ||
                change.FieldName == OrderHistoryHelper.ManuallyShippingAddress2Key ||
                change.FieldName == OrderHistoryHelper.ManuallyShippingCityKey ||
                change.FieldName == OrderHistoryHelper.ManuallyShippingCountryKey ||
                change.FieldName == OrderHistoryHelper.ManuallyShippingPhoneKey ||
                change.FieldName == OrderHistoryHelper.ManuallyShippingZipKey ||
                change.FieldName == OrderHistoryHelper.ManuallyShippingZipAddonKey)
            {
                ChangeType = OrderChangeTypes.ChangeAddress;
                Message    = OrderHistoryHelper.PrepareFieldName(change.FieldName) + ": " + OrderHistoryHelper.PrepareFieldValue(change.FromValue) + " -> " + OrderHistoryHelper.PrepareFieldValue(change.ToValue);
            }
        }
        public static CallResult <IList <SelectListShippingOption> > Apply(IUnitOfWork db,
                                                                           ILogService log,
                                                                           ITime time,
                                                                           IWeightService weightService,
                                                                           long orderId,
                                                                           IList <IShipmentApi> ratePrividers,
                                                                           AddressDTO returnAddress,
                                                                           AddressDTO pickupAddress,
                                                                           IList <CustomShippingItemViewModel> customShippingItems,
                                                                           bool isFulfilmentUser)
        {
            var order = db.Orders.GetById(orderId);

            var correctedInitialShippingType = ShippingUtils.CorrectInitialShippingService(order.InitialServiceType, order.SourceShippingService, (OrderTypeEnum)order.OrderType);
            var shippingService = ShippingUtils.InitialShippingServiceIncludeUpgrade(correctedInitialShippingType, order.UpgradeLevel);

            var shippingProviderType = (ShipmentProviderType)db.Orders.GetById(orderId).ShipmentProviderType;
            var rateProvider         = ratePrividers.FirstOrDefault(p => p.Type == shippingProviderType);

            var oldShippings          = db.OrderShippingInfos.GetByOrderId(orderId).ToList();
            var previousNumberInBatch = oldShippings.FirstOrDefault(sh => sh.IsActive)?.NumberInBatch;

            var items = db.OrderItems.GetWithListingInfo()
                        .Where(oi => oi.OrderId == orderId)
                        .Select(oi => new ListingOrderDTO()
            {
                ItemOrderId       = oi.ItemOrderId,
                OrderItemEntityId = oi.OrderItemEntityId,
                Weight            = oi.Weight
            }).ToList();

            if (items.Any(i => !i.Weight.HasValue || i.Weight == 0))
            {
                return(CallResult <IList <SelectListShippingOption> > .Fail("No rates. Order has items w/o weight.", null));
            }

            var packageDict = new Dictionary <string, PackageInfo>();

            foreach (var shippingItem in customShippingItems.OrderBy(sh => sh.PackageValue).ToList())
            {
                var packageValue = shippingItem.PackageValue;

                var orderItem = items.FirstOrDefault(oi => oi.OrderItemEntityId == shippingItem.OrderItemId);
                var package   = packageDict.ContainsKey(packageValue) ? packageDict[packageValue] : null;
                if (package == null)
                {
                    var shippingMethodId = int.Parse(shippingItem.PackageValue.Split('-')[0]);
                    var dbShippingMethod = db.ShippingMethods.GetAll().FirstOrDefault(m => m.Id == shippingMethodId);

                    package = new PackageInfo
                    {
                        Items = new List <OrderItemRateInfo>(),
                        RequiredServiceIdentifier = dbShippingMethod.ServiceIdentifier,
                        ServiceTypeUniversal      = ShippingUtils.GetShippingType(shippingMethodId),
                        PackageTypeUniversal      = ShippingUtils.GetPackageType(shippingMethodId),
                        GroupId = RateHelper.CustomPartialGroupId,
                    };

                    packageDict[packageValue] = package;
                }

                package.Items.Add(new OrderItemRateInfo()
                {
                    Quantity    = 1,
                    ItemOrderId = orderItem.ItemOrderId,
                    Weight      = orderItem.Weight ?? 0,
                });
            }

            var packages = packageDict.Values;

            var addressTo = db.Orders.GetAddressInfo(order.Id);
            var shipDate  = db.Dates.GetOrderShippingDate(null);

            var rates = new List <RateDTO>();

            foreach (var package in packages)
            {
                package.Weight = weightService.AdjustWeight(package.Items.Sum(i => i.Weight * i.Quantity),
                                                            package.Items.Sum(i => i.Quantity));

                GetRateResult rateResult = null;
                log.Info("GetSpecificLocalRate, orderId=" + orderId);
                rateResult = rateProvider.GetAllRate(returnAddress,
                                                     pickupAddress,
                                                     addressTo,
                                                     shipDate,
                                                     package.Weight ?? 1,
                                                     package.GetDimension(),
                                                     order.IsInsured ? order.TotalPrice : 0,
                                                     order.IsSignConfirmation,
                                                     new OrderRateInfo()
                {
                    OrderNumber = order.AmazonIdentifier,

                    Items       = package.Items,
                    SourceItems = package.Items,

                    EstimatedShipDate = ShippingUtils.AlignMarketDateByEstDayEnd(order.LatestShipDate, (MarketType)order.Market),
                    ShippingService   = shippingService,
                    TotalPrice        = order.TotalPrice,
                    Currency          = order.TotalPriceCurrency,
                },
                                                     RetryModeType.Random);

                if (rateResult.Result != GetRateResultType.Success)
                {
                    return(CallResult <IList <SelectListShippingOption> > .Fail("Error when get rates for package, serviceType=" + package.ServiceTypeUniversal.ToString() + ", packageType=" + package.PackageTypeUniversal.ToString(), null));
                }

                var rate = rateResult.Rates.FirstOrDefault(r => r.ServiceIdentifier == package.RequiredServiceIdentifier);
                if (rate == null)
                {
                    return(CallResult <IList <SelectListShippingOption> > .Fail("Not rates for package, serviceType=" + package.ServiceTypeUniversal.ToString() + ", packageType=" + package.PackageTypeUniversal.ToString(), null));
                }

                rate.GroupId = RateHelper.CustomPartialGroupId;

                RateHelper.GroupPackageItems(package);
                rate.ItemOrderIds = package.Items.Select(i => new RateItemDTO()
                {
                    OrderItemId = i.ItemOrderId,
                    Quantity    = i.Quantity
                }).ToList();

                rates.AddRange(new List <RateDTO>()
                {
                    rate
                });
            }

            foreach (var rate in rates)
            {
                rate.IsDefault = true;
                rate.IsVisible = true;
                if (previousNumberInBatch.HasValue)
                {
                    rate.NumberInBatch    = previousNumberInBatch;
                    previousNumberInBatch = null;
                }
            }

            //save
            var newShippings       = new List <OrderShippingInfo>();
            var shippingMethodList = db.ShippingMethods.GetAllAsDto().ToList();
            var lastShippingNumber = oldShippings.Any() ? oldShippings.Max(sh => sh.ShippingNumber) ?? 0 : 0;
            var shippingNumber     = lastShippingNumber;

            foreach (var rate in rates)
            {
                log.Debug("store rate, service" + rate.ServiceTypeUniversal
                          + ", package=" + rate.PackageTypeUniversal
                          + ", cost=" + rate.Amount
                          + ", defualt=" + rate.IsDefault
                          + ", visible=" + rate.IsVisible
                          + ", groupId=" + rate.GroupId
                          + ", shipDate=" + rate.ShipDate
                          + ", deliveryDate=" + rate.DeliveryDate
                          + ", daysInfo=" + rate.DeliveryDaysInfo
                          + ", items=" + (rate.ItemOrderIds != null ? String.Join(", ", rate.ItemOrderIds.Select(i => (i.OrderItemId.ToString() + "-" + i.Quantity.ToString())).ToList()) : ""));
                var currentRate = rate;

                shippingNumber++;
                var method = shippingMethodList.FirstOrDefault(m => m.ServiceIdentifier == currentRate.ServiceIdentifier);
                if (method != null)
                {
                    currentRate.DeliveryDays = time.GetBizDaysCount(currentRate.ShipDate,
                                                                    currentRate.DeliveryDate);

                    var shippingInfo = db.OrderShippingInfos.CreateShippingInfo(currentRate,
                                                                                orderId,
                                                                                shippingNumber,
                                                                                method.Id);
                    newShippings.Add(shippingInfo);

                    if (currentRate.ItemOrderIds != null && currentRate.ItemOrderIds.Any())
                    {
                        log.Debug("store partial, items="
                                  +
                                  String.Join(", ",
                                              currentRate.ItemOrderIds.Select(
                                                  i => (i.OrderItemId.ToString() + "-" + i.Quantity.ToString())).ToList()));
                        db.ItemOrderMappings.StorePartialShippingItemMappings(shippingInfo.Id,
                                                                              currentRate.ItemOrderIds,
                                                                              items,
                                                                              time.GetAppNowTime());
                    }
                    else
                    {
                        db.ItemOrderMappings.StoreShippingItemMappings(shippingInfo.Id,
                                                                       items,
                                                                       time.GetAppNowTime());
                    }
                }
            }

            foreach (var oldShipping in oldShippings)
            {
                if (oldShipping.ShippingGroupId == RateHelper.CustomPartialGroupId)
                {
                    db.OrderShippingInfos.Remove(oldShipping);
                }
                else
                {
                    oldShipping.IsActive = false;
                }
            }

            order.ShippingCalculationStatus = (int)ShippingCalculationStatusEnum.FullCalculation;

            db.Commit();

            //Return actual values
            var allShippings = db.OrderShippingInfos.GetByOrderIdAsDto(orderId);
            var results      = OrderViewModel.GetShippingOptions(allShippings,
                                                                 (MarketType)order.Market,
                                                                 order.IsSignConfirmation,
                                                                 order.IsInsured,
                                                                 isFulfilmentUser,
                                                                 showOptionsPrices: true,
                                                                 showProviderName: false);

            return(CallResult <IList <SelectListShippingOption> > .Success(results));
        }