/// <summary> /// Get the shipping cost. /// </summary> /// <param name="shippingMethod">The shipping method.</param> /// <param name="shipment">The shipment.</param> /// <param name="currency">The currency.</param> /// <returns>The shipping cost.</returns> public static Money GetShippingCost(Mediachase.Commerce.Orders.Dto.ShippingMethodDto.ShippingMethodRow shippingMethod, Shipment shipment, Currency currency) { Money result = new Money(0, currency); var type = Type.GetType(shippingMethod.ShippingOptionRow.ClassName); if (type == null) { throw new TypeInitializationException(shippingMethod.ShippingOptionRow.ClassName, null); } var message = string.Empty; var provider = (IShippingGateway)Activator.CreateInstance(type, new MarketStorage().GetCurrentMarket()); var shipmentRate = provider.GetRate(shippingMethod.ShippingMethodId, shipment, ref message); if (shipmentRate != null) { var shipmentRateMoney = shipmentRate.Money; if (!shipmentRateMoney.Currency.Equals(currency)) { //The shipment and the shipping method base price are in different currency, need to convert first result = CurrencyFormatter.ConvertCurrency(shipmentRateMoney, currency); } else { result = shipmentRateMoney; } } return(result); }
/// <summary> /// Get the shipping cost. /// </summary> /// <param name="shippingMethod">The shipping method.</param> /// <param name="shipment">The shipment.</param> /// <returns>The shipping cost.</returns> public static Money GetShippingCost(Mediachase.Commerce.Orders.Dto.ShippingMethodDto.ShippingMethodRow shippingMethod, Shipment shipment) { return(GetShippingCost(shippingMethod, shipment, SiteContext.Current.Currency)); }