/// <summary> /// Get all shipping providers for current order /// </summary> /// <returns></returns> public static XPathNavigator GetAllShippingProvidersForCurrentOrder() { var currentOrderInfo = OrderHelper.GetOrder(); var doc = new XmlDocument(); if (currentOrderInfo == null) { return(doc.CreateNavigator()); } var shippingProviderforOrderList = ShippingProviderHelper.GetShippingProvidersForOrder(currentOrderInfo); var stream1 = new MemoryStream(); //Serialize the Record object to a memory stream using DataContractSerializer. var serializer = new DataContractSerializer(typeof(List <ShippingProvider>), "ShippingProviders", ""); serializer.WriteObject(stream1, shippingProviderforOrderList); stream1.Position = 0; var result = new StreamReader(stream1).ReadToEnd(); doc.LoadXml(result); return(doc.CreateNavigator()); }
public List <OrderValidationError> ValidateShipping(OrderInfo orderInfo) { var errors = new List <OrderValidationError>(); if (orderInfo.ShippingInfo.Id != 0) { var shippingProvider = ShippingProviderHelper.GetShippingProvider(orderInfo.ShippingInfo.Id); var shippingCountryCode = orderInfo.CustomerInfo.ShippingCountryCode; // if shipping country is empty on the order, then use customercountry for validation if (string.IsNullOrEmpty(shippingCountryCode)) { shippingCountryCode = orderInfo.CustomerInfo.CountryCode; } if (shippingProvider.Type != ShippingProviderType.Pickup && !shippingProvider.Zone.CountryCodes.Contains(shippingCountryCode)) { Log.Instance.LogWarning("ORDERVALIDATIONERROR: SHIPPING COUNTRY DOES NOT MATCH SHIPPING PROVIDER"); errors.Add(new OrderValidationError { Id = orderInfo.ShippingInfo.Id, Key = "ValidationShippingCountryShippingProviderMismatch", Value = "The Shipping Country Does Not Match Countries Allowed For The Chosen Shipping Provider" }); } errors.AddRange(ShippingProviderHelper.GetPaymentValidationResults(orderInfo).Where(e => e.Id == orderInfo.ShippingInfo.Id)); } if (orderInfo.ConfirmValidationFailed && orderInfo.ShippingInfo.Id == 0 && ShippingProviderHelper.GetShippingProvidersForOrder(orderInfo).Count > 0) { Log.Instance.LogWarning("ORDERVALIDATIONERROR: SHIPPING PROVIDERS AVAILABLE BUT NOT CHOSEN"); errors.Add(new OrderValidationError { Id = 0, Key = "ValidationNoShippingProviderChosen", Value = "No Shipping Provider Chosen" }); } return(errors); }
/// <summary> /// Loads the shipping methods. /// </summary> /// <returns></returns> public IEnumerable <ShippingProviderMethod> LoadShippingMethods() { //var shippingMethodList = new List<ShippingProviderMethod>(); var shippingProviders = ShippingProviderHelper.GetAllShippingProvidersIncludingCustomProviders(); return(shippingProviders.Where(shippingProvider => shippingProvider.GetName().ToLowerInvariant() == Title.ToLowerInvariant()).SelectMany(shippingProvider => shippingProvider.GetAllShippingMethods(Id))); }
public ActionResult AddShippingProvider(int shippingProviderId, string shippingProviderMethodId, bool autoselect = false) { var orderInfo = OrderHelper.GetOrder() ?? OrderHelper.CreateOrder(); if (autoselect) { ShippingProviderHelper.AutoSelectShippingProvider(orderInfo); orderInfo.Save(); } else { if (shippingProviderId == 0 || string.IsNullOrEmpty(shippingProviderMethodId)) { Session.Add(Constants.ShippingProviderSessionKey, ProviderActionResult.NoCorrectInput); return(CurrentUmbracoPage()); } var result = orderInfo.AddShippingProvider(shippingProviderId, shippingProviderMethodId); orderInfo.Save(); Session.Add(Constants.ShippingProviderSessionKey, result); } return(CurrentUmbracoPage()); }
/// <summary> /// Gets the fulfillment providers. (ie shipping/pickup/etc) /// </summary> /// <param name="useZone">if set to <c>true</c> use zone/countries.</param> /// <param name="storeAlias">The store alias.</param> /// <param name="currencyCode">The currency code.</param> /// <returns></returns> public static IEnumerable <IFulfillmentProvider> GetFulfillmentProviders(bool useZone = true, string storeAlias = null, string currencyCode = null) { var localization = StoreHelper.GetLocalizationOrCurrent(storeAlias, currencyCode); var inclVat = IO.Container.Resolve <ISettingsService>().IncludingVat; var currentOrder = OrderHelper.GetOrder(); return(ShippingProviderHelper.GetShippingProvidersForOrder(currentOrder, useZone, storeAlias, currencyCode).Select(s => new ShippingFulfillmentAdaptor(s, inclVat, localization, currentOrder))); }
/// <summary> /// Gets the fulfillment providers. (ie shipping/pickup/etc) for a given country /// </summary> /// <param name="countryCode">the code of the country</param> /// <param name="storeAlias">The store alias.</param> /// <param name="currencyCode">The currency code.</param> /// <returns></returns> public static IEnumerable <IFulfillmentProvider> GetFulfillmentProvidersForCountry(string countryCode, string storeAlias = null, string currencyCode = null) { var localization = StoreHelper.GetLocalizationOrCurrent(storeAlias, currencyCode); var inclVat = IO.Container.Resolve <ISettingsService>().IncludingVat; return(ShippingProviderHelper.GetAllShippingProviders(storeAlias, currencyCode).Where(x => x.Zone.CountryCodes.Contains(countryCode)).Select(p => new ShippingFulfillmentAdaptor(p, inclVat, localization, null))); }
/// <summary> /// Gets the fulfillment providers. (ie shipping/pickup/etc) for a basket /// </summary> /// <param name="order">the order to match the fulfillment providers with</param> /// <param name="useZone">if set to <c>true</c> use zone/countries.</param> /// <param name="storeAlias">The store alias.</param> /// <param name="currencyCode">The currency code.</param> /// <returns></returns> public static IEnumerable <IFulfillmentProvider> GetFulfillmentProvidersForOrder(IBasket order, bool useZone = true, string storeAlias = null, string currencyCode = null) { var localization = StoreHelper.GetLocalizationOrCurrent(storeAlias, currencyCode); var orderInfo = Basket.GetOrderInfoFromOrderBasket(order); var currentOrder = OrderHelper.GetOrder(); return(ShippingProviderHelper.GetShippingProvidersForOrder(orderInfo, useZone, storeAlias, currencyCode) .Select(p => new ShippingFulfillmentAdaptor(p, orderInfo.PricesAreIncludingVAT, localization, currentOrder))); }
private void LoadShippingMethods() { List <IShippingProvider> shippingProviders = ShippingProviderHelper.GetAllShippingProvidersIncludingCustomProviders(); //if (shippingProviders == null || shippingProviders.Count <= 0) return; foreach (var shippingProvider in shippingProviders.Where(shippingProvider => shippingProvider.GetName() == Name)) { _ShippingMethods = shippingProvider.GetAllShippingMethods(0).ToList(); break; } }
public ProviderActionResult AddShippingProvider(OrderInfo order, int shippingProviderId, string shippingProviderMethodId, ILocalization localization) { if (ChangeOrderToIncompleteAndReturnTrueIfNotAllowed(order)) { Log.Instance.LogDebug("AddShippingMethod: " + ProviderActionResult.NotPermitted); return(ProviderActionResult.NotPermitted); } if (shippingProviderId == 0) { Log.Instance.LogDebug("AddShippingMethod: " + ProviderActionResult.ProviderIdZero); return(ProviderActionResult.ProviderIdZero); } // todo: move logic and update API var shippingProvider = ShippingProviderHelper.GetAllShippingProviders(localization.StoreAlias, localization.CurrencyCode).FirstOrDefault(x => x.Id == shippingProviderId); if (shippingProvider == null) { Log.Instance.LogDebug("AddShippingMethod shippingProvider " + ProviderActionResult.NoCorrectInput + " shippingProviderId: " + shippingProviderId); return(ProviderActionResult.NoCorrectInput); } order.ShippingInfo.Id = shippingProviderId; order.ShippingInfo.Title = shippingProvider.Title; order.ShippingInfo.ShippingType = shippingProvider.Type; var shippingMethod = shippingProvider.ShippingProviderMethods.FirstOrDefault(x => x.Id == shippingProviderMethodId); if (shippingMethod == null) { Log.Instance.LogDebug("AddShippingMethod shippingMethod " + ProviderActionResult.NoCorrectInput + " shippingProviderMethodId: " + shippingProviderMethodId); return(ProviderActionResult.NoCorrectInput); } order.ShippingInfo.MethodId = shippingProviderMethodId; order.ShippingInfo.MethodTitle = shippingMethod.Title; shippingMethod.UpdatePriceFromCustomShippingProvider(order); order.ResetDiscounts(); return(ProviderActionResult.Success); }
public static XPathNavigator GetAllShippingProviders() { var stream1 = new MemoryStream(); //Serialize the Record object to a memory stream using DataContractSerializer. var serializer = new DataContractSerializer(typeof(List <ShippingProvider>), "ShippingProviders", ""); serializer.WriteObject(stream1, ShippingProviderHelper.GetAllShippingProviders().ToList()); stream1.Position = 0; string result = new StreamReader(stream1).ReadToEnd(); var doc = new XmlDocument(); doc.LoadXml(result); return(doc.CreateNavigator()); }
public List <OrderValidationError> ValidateGlobalValidations(OrderInfo orderInfo) { var errors = new List <OrderValidationError>(); if (orderInfo.ConfirmValidationFailed) { if (!orderInfo.TermsAccepted) { Log.Instance.LogWarning("ORDERVALIDATIONERROR: TERMS NOT ACCEPTED"); errors.Add(new OrderValidationError { Key = "AcceptTermsError", Value = "Terms Not Accepted" }); } var shippingProvidersForOrder = ShippingProviderHelper.GetShippingProvidersForOrder(orderInfo); if (orderInfo.Status == OrderStatus.Confirmed && orderInfo.ShippingCostsMightBeOutdated && shippingProvidersForOrder.Count > 0 && shippingProvidersForOrder.All(shipPro => shipPro.Id != orderInfo.ShippingInfo.Id)) { Log.Instance.LogWarning("ORDERVALIDATIONERROR: ShippingCostOutdatedError"); errors.Add(new OrderValidationError { Key = "ShippingCostOutdatedError", Value = "Shipping Not Updated Since Last Basket Change" }); } if (orderInfo.Status == OrderStatus.Confirmed && orderInfo.StoreInfo.Store == null) { Log.Instance.LogWarning("ORDERVALIDATIONERROR: NoStoreConnectedToThisOrder"); errors.Add(new OrderValidationError { Key = "NoStoreConnectedToThisOrder", Value = "There Is No Store Connected To This Order" }); } } return(errors); }
public IEnumerable <ShippingProviderMethod> GetAllShippingMethods(int id) { var methods = new List <ShippingProviderMethod>(); var provider = ShippingProviderHelper.GetShippingProvider(id); var helper = new ShippingConfigHelper(provider); var request = new ShippingRequest(); var orderInfo = OrderHelper.GetOrderInfo(); var postalCodeFrom = helper.Settings["zipPostalCodeFrom"]; var customerPostalCode = OrderHelper.CustomerInformationValue(orderInfo, "customerPostalCode"); if (string.IsNullOrEmpty(customerPostalCode)) { Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: customerPostalCode IsNullOrEmpty: CUSTOMER SHOULD ENTER A POSTALCODE FIRST!"); return(methods); } var orderWeight = orderInfo.OrderLines.Sum(x => x.OrderLineWeight) / 1000; if (orderWeight < 0.1) { orderWeight = 0.1; } if (orderWeight > 20) { Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Weight > 20: Weight should be in grams"); return(methods); } var orderWeightCulture = decimal.Parse(orderWeight.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU")); var orderWidth = orderInfo.OrderLines.Sum(x => x.ProductInfo.Weight); if (orderWidth < 5) { orderWidth = 5; } if (orderWidth > 105) { Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Wide > 105: width should be in cm"); return(methods); } var orderWidthCulture = decimal.Parse(orderWidth.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU")); var orderHeight = orderInfo.OrderLines.Sum(x => x.ProductInfo.Height); if (orderHeight < 5) { orderHeight = 5; } if (orderHeight > 105) { Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Hight > 105: height should be in cm"); return(methods); } var orderHeightCulture = decimal.Parse(orderHeight.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU")); var orderLength = orderInfo.OrderLines.Sum(x => x.ProductInfo.Length); if (orderLength < 5) { orderLength = 5; } if (orderLength > 105) { Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Length > 105: length should be in cm"); return(methods); } var widthOrLength = orderWidth; if (orderLength > orderWidth) { widthOrLength = orderLength; } var girth = 2 * (Math.Round(widthOrLength, MidpointRounding.AwayFromZero) + Math.Round(orderHeight, MidpointRounding.AwayFromZero)); if (girth < 16) { Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Girth < 16 (sizes should be in cm)"); return(methods); } if (girth > 140) { Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Girth > 140 (sizes should be in cm)"); return(methods); } var orderLengthCulture = decimal.Parse(orderLength.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU")); if (orderInfo.CustomerInfo.CountryCode.ToUpper() == "AU") { request.ShippingUrlBase = helper.Settings["ServiceUrlDomestic"]; request.Parameters.Add("from_postcode", postalCodeFrom); request.Parameters.Add("to_postcode", customerPostalCode); request.Parameters.Add("length", Math.Round(orderLengthCulture, 2).ToString()); request.Parameters.Add("width", Math.Round(orderWidthCulture, 2).ToString()); request.Parameters.Add("height", Math.Round(orderHeightCulture, 2).ToString()); } else { request.ShippingUrlBase = helper.Settings["ServiceUrlInternational"]; request.Parameters.Add("country_code", orderInfo.CustomerInfo.CountryCode); } request.Parameters.Add("weight", Math.Round(orderWeightCulture, 2).ToString()); var requestHeader = new WebHeaderCollection { { "AUTH-KEY", helper.Settings["authKey"] } }; Log.Instance.LogDebug("AUSPOST API URL: " + request.ShippingUrlBase); Log.Instance.LogDebug("AUSPOST API ParametersAsString: " + request.ParametersAsString); Log.Instance.LogDebug("AUSPOST API requestHeader AUTH-KEY: " + requestHeader.GetValues("AUTH-KEY")); var issuerRequest = _requestSender.GetRequest(request.ShippingUrlBase, request.ParametersAsString, requestHeader); XNamespace ns = string.Empty; var issuerXml = XDocument.Parse(issuerRequest); foreach (var service in issuerXml.Descendants(ns + "service")) { var issuerId = service.Descendants(ns + "code").First().Value; var issuerName = service.Descendants(ns + "name").First().Value; var issuerPriceValue = service.Descendants(ns + "price").First().Value; decimal issuerPrice; decimal.TryParse(issuerPriceValue, out issuerPrice); var priceInCents = issuerPrice * 100; var paymentImageId = 0; var logoDictionaryItem = library.GetDictionaryItem(issuerId + "LogoId"); if (string.IsNullOrEmpty(logoDictionaryItem)) { int.TryParse(library.GetDictionaryItem(issuerId + "LogoId"), out paymentImageId); } methods.Add(new ShippingProviderMethod { Id = issuerId, Description = issuerName, Title = issuerName, Name = issuerName, ProviderName = GetName(), ImageId = paymentImageId, PriceInCents = (int)priceInCents, Vat = 21 }); } return(methods); }
/// <summary> /// Return a list of shipping providers /// </summary> /// <returns> /// All list of all the Shipping Providers in uWebshop /// </returns> public static List <ShippingProvider> GetAllShippingProviders() { return(ShippingProviderHelper.GetAllShippingProviders().ToList()); }
/// <summary> /// Returns Shipping Providers for this order /// </summary> /// <returns></returns> public static List <ShippingProvider> GetShippingProvidersForOrder(bool useCountry = true) { return(ShippingProviderHelper.GetShippingProvidersForOrder(useCountry)); }