/// <summary>
        /// get inventory for china store
        /// </summary>
        /// <param name="storeID"></param>
        /// <returns></returns>
        public static Inventory_V01 GetInventory(string storeID)
        {
            string cachekey = string.Format("{0}{1}", INVENTORY_CACHE_PREFIX, storeID);

            CatalogInterfaceClient proxy = null;

            using (proxy = ServiceClientProvider.GetCatalogServiceProxy())
            {
                try
                {
                    var response =
                        proxy.GetInventory(new GetInventoryRequest1(new GetInventoryRequest_V01 {
                        CountryCode = "CN", StoreID = storeID
                    })).GetInventoryResult as
                        GetInventoryResponse_V01;

                    // Check response for error.
                    if (response == null || response.Status != ServiceResponseStatusType.Success ||
                        response.Inventory == null)
                    {
                        throw new ApplicationException(
                                  "CatalogProvider.GetInventory error. GetInventoryResponse indicates error. storeID : " +
                                  storeID);
                    }
                    HttpRuntime.Cache.Insert(cachekey,
                                             response.Inventory,
                                             null,
                                             DateTime.Now.AddMinutes(INVENTORY_CACHE_MINUTES),
                                             Cache.NoSlidingExpiration,
                                             CacheItemPriority.NotRemovable,
                                             null);

                    if (Settings.GetRequiredAppSetting("LogCatalogCN", "false").ToLower() == "true")
                    {
                        LogRequest(string.Format("Store ID: {0}", storeID));
                        LogRequest(string.Format("GetInventory service response: {0}",
                                                 OrderCreationHelper.Serialize(response.Inventory)));
                    }

                    return(response.Inventory);
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(
                        string.Format("ChinaGetInventory error, storeID: {0} {1}", storeID, ex));
                }
            }
            return(null);
        }
        public FreightSimulationResult CalculateFreight(ServiceProvider.OrderChinaSvc.ShippingInfo_V01 shippingInfo, decimal weight)
        {
            var freightSimulationResult = new FreightSimulationResult();

            if (shippingInfo == null || shippingInfo.Address == null || weight == 0)
            {
                return(freightSimulationResult);
            }

            if (Settings.GetRequiredAppSetting("LogShipping", "false").ToLower() == "true")
            {
                LogRequest(string.Format("ShippingInfo before CalculateFreight:  {0}",
                                         OrderCreationHelper.Serialize(shippingInfo)));
            }

            if (!string.IsNullOrEmpty(shippingInfo.Address.StateProvinceTerritory) &&
                !string.IsNullOrEmpty(shippingInfo.Address.City) &&
                !string.IsNullOrEmpty(shippingInfo.Address.CountyDistrict))
            {
                if (string.IsNullOrEmpty(shippingInfo.ShippingMethodID))
                {
                    var mappings = GetProvinceStoreMapping();
                    if (mappings != null)
                    {
                        var mapping = mappings.Find(m => m.ProvinceName == shippingInfo.Address.StateProvinceTerritory);
                        if (mapping != null)
                        {
                            shippingInfo.ShippingMethodID = mapping.StoreID.ToString();
                        }
                    }
                }

                if (string.IsNullOrEmpty(shippingInfo.WarehouseCode))
                {
                    shippingInfo.WarehouseCode =
                        HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultFreightCode;
                }

                var proxy = ServiceClientProvider.GetChinaOrderServiceProxy();

                var result = proxy.GetFreightCharge(new ServiceProvider.OrderChinaSvc.GetFreightChargeRequest1(new ServiceProvider.OrderChinaSvc.GetFreightChargeRequest_V01()
                {
                    ShippingInfo = shippingInfo,
                    Weight       = weight
                })).GetFreightChargeResult as ServiceProvider.OrderChinaSvc.GetFreightChargeResponse_V01;

                if (result != null && result.Status == ServiceProvider.OrderChinaSvc.ServiceResponseStatusType.Success)
                {
                    freightSimulationResult.EstimatedFreight = result.Freight;
                    freightSimulationResult.StoreName        = result.StoreName;
                }
            }

            if (Settings.GetRequiredAppSetting("LogShipping", "false").ToLower() == "true")
            {
                LogRequest(string.Format("ShippingInfo after CalculateFreight: {0}",
                                         OrderCreationHelper.Serialize(shippingInfo)));
            }

            return(freightSimulationResult);
        }
        public override ShippingInfo GetShippingInfoFromID(string distributorID, string locale, DeliveryOptionType type,
                                                           int deliveryOptionID, int shippingAddressID)
        {
            if (type == DeliveryOptionType.Shipping)
            {
                var shippingAddresses = GetDSShippingAddresses(distributorID, locale);
                ShippingAddress_V02 shippingAddress = shippingAddresses.Find(s => s.ID == shippingAddressID);
                DeliveryOption      deliveryOption  = null;
                var freightCodeAndWarehouse         = GetFreightCodeAndWarehouseFromAddress(shippingAddress, null);
                if (freightCodeAndWarehouse != null)
                {
                    deliveryOption = new DeliveryOption(freightCodeAndWarehouse[1], freightCodeAndWarehouse[0],
                                                        DeliveryOptionType.Shipping,
                                                        string.Empty);
                }

                if (deliveryOption == null || shippingAddress == null)
                {
                    return(null);
                }
                ShippingInfo shippingInfo = new ShippingInfo(deliveryOption, shippingAddress);
                shippingInfo.AddressType = "EXP"; // this is address type for shipping

                if (Settings.GetRequiredAppSetting("LogShipping", "false").ToLower() == "true")
                {
                    LogRequest(string.Format("GetShippingInfoFromID for shipping option: {0}",
                                             OrderCreationHelper.Serialize(shippingInfo)));
                }
                return(shippingInfo);
            }
            else if (type == DeliveryOptionType.Pickup)
            {
                ShippingInfo shippingInfo = base.GetShippingInfoFromID(distributorID, locale, type, deliveryOptionID, shippingAddressID);

                if (shippingInfo != null)
                {
                    shippingInfo.FreightCode = "0";
                    shippingInfo.AddressType = "SD"; // this is address type for pickup
                }

                //Stores Pickup Location phone in session and sets shippingInfo phone to DS phone
                //var sessionInfo = SessionInfo.GetSessionInfo(distributorID, locale);

                //sessionInfo.SelectedPickupLocationPhone = shippingInfo.Address.Phone;
                //shippingInfo.Address.Phone = String.Empty;

                return(shippingInfo);
            }
            if (type == DeliveryOptionType.PickupFromCourier)
            {
                string countryCode = locale.Substring(3, 2);
                var    pickupLocationPreference = GetPickupLocationsPreferences(distributorID, countryCode);
                if (pickupLocationPreference != null && pickupLocationPreference.Count > 0)
                {
                    var vPickupLocation = pickupLocationPreference.Find(p => p.ID == deliveryOptionID);
                    if (vPickupLocation != null)
                    {
                        int pickupLocationID = vPickupLocation.PickupLocationID;
                        var doList           = GetDeliveryOptions(type,
                                                                  new ShippingAddress_V01
                        {
                            Address = new Address_V01 {
                                Country = "CN"
                            }
                        });
                        if (doList != null)
                        {
                            var deliveryOption = doList.Find(d => d.Id == pickupLocationID);
                            if (deliveryOption != null)
                            {
                                var shippingInfo = new ShippingInfo(deliveryOption);
                                shippingInfo.Id          = deliveryOptionID; // this is ID field from PickUpStore
                                shippingInfo.AddressType = "PUC" + deliveryOption.AddressType;
                                return(shippingInfo);
                            }
                        }
                    }
                }
            }
            return(null);
        }