/// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="shipmentPackage">Shipment package</param>
        /// <param name="error">Error</param>
        /// <returns>Shipping options</returns>
        public List <ShippingOption> GetShippingOptions(ShipmentPackage shipmentPackage, ref string error)
        {
            var shippingOptions = new List <ShippingOption>();

            if (shipmentPackage == null)
            {
                throw new ArgumentNullException("shipmentPackage");
            }
            if (shipmentPackage.Items == null)
            {
                throw new NopException("No shipment items");
            }
            if (shipmentPackage.ShippingAddress == null)
            {
                error = "Shipping address is not set";
                return(shippingOptions);
            }
            if (shipmentPackage.ShippingAddress.Country == null)
            {
                error = "Shipping country is not set";
                return(shippingOptions);
            }

            decimal subTotal = decimal.Zero;

            foreach (var shoppingCartItem in shipmentPackage.Items)
            {
                if (shoppingCartItem.IsFreeShipping)
                {
                    continue;
                }
                subTotal += PriceHelper.GetSubTotal(shoppingCartItem, shipmentPackage.Customer, true);
            }

            var shippingMethods = IoC.Resolve <IShippingService>().GetAllShippingMethods(shipmentPackage.ShippingAddress.CountryId);

            foreach (var shippingMethod in shippingMethods)
            {
                decimal?rate = GetRate(subTotal, shippingMethod.ShippingMethodId);
                if (rate.HasValue)
                {
                    var shippingOption = new ShippingOption();
                    shippingOption.Name        = shippingMethod.Name;
                    shippingOption.Description = shippingMethod.Description;
                    shippingOption.Rate        = rate.Value;
                    shippingOptions.Add(shippingOption);
                }
            }

            return(shippingOptions);
        }
        /// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="shipmentPackage">Shipment package</param>
        /// <param name="error">Error</param>
        /// <returns>Shipping options</returns>
        public ShippingOptionCollection GetShippingOptions(ShipmentPackage shipmentPackage, ref string error)
        {
            var shippingOptions = new ShippingOptionCollection();

            if (shipmentPackage == null)
            {
                throw new ArgumentNullException("shipmentPackage");
            }
            if (shipmentPackage.Items == null)
            {
                throw new NopException("No shipment items");
            }
            if (shipmentPackage.ShippingAddress == null)
            {
                error = "Shipping address is not set";
                return(shippingOptions);
            }
            if (shipmentPackage.ShippingAddress.Country == null)
            {
                error = "Shipping country is not set";
                return(shippingOptions);
            }

            decimal subTotal = decimal.Zero;

            foreach (var shoppingCartItem in shipmentPackage.Items)
            {
                if (shoppingCartItem.IsFreeShipping)
                {
                    continue;
                }
                subTotal += PriceHelper.GetSubTotal(shoppingCartItem, shipmentPackage.Customer, true);
            }

            decimal weight = ShippingManager.GetShoppingCartTotalWeigth(shipmentPackage.Items, shipmentPackage.Customer);

            var shippingMethods = ShippingMethodManager.GetAllShippingMethods(shipmentPackage.ShippingAddress.CountryId);

            foreach (var shippingMethod in shippingMethods)
            {
                var shippingOption = new ShippingOption();
                shippingOption.Name        = shippingMethod.Name;
                shippingOption.Description = shippingMethod.Description;
                shippingOption.Rate        = GetRate(subTotal, weight, shippingMethod.ShippingMethodId);
                shippingOptions.Add(shippingOption);
            }

            return(shippingOptions);
        }
Beispiel #3
0
        /// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="ShipmentPackage">Shipment package</param>
        /// <param name="Error">Error</param>
        /// <returns>Shipping options</returns>
        public ShippingOptionCollection GetShippingOptions(ShipmentPackage ShipmentPackage, ref string Error)
        {
            ShippingOptionCollection shippingOptions = new ShippingOptionCollection();

            if (ShipmentPackage == null)
            {
                throw new ArgumentNullException("ShipmentPackage");
            }
            if (ShipmentPackage.Items == null)
            {
                throw new NopException("No shipment items");
            }

            decimal subTotal = decimal.Zero;

            foreach (ShoppingCartItem shoppingCartItem in ShipmentPackage.Items)
            {
                if (shoppingCartItem.IsFreeShipping)
                {
                    continue;
                }
                subTotal += PriceHelper.GetSubTotal(shoppingCartItem, ShipmentPackage.Customer, true);
            }

            decimal weight = ShippingManager.GetShoppingCartTotalWeigth(ShipmentPackage.Items);

            ShippingMethodCollection shippingMethods = ShippingMethodManager.GetAllShippingMethods();

            foreach (ShippingMethod shippingMethod in shippingMethods)
            {
                ShippingOption shippingOption = new ShippingOption();
                shippingOption.Name        = shippingMethod.Name;
                shippingOption.Description = shippingMethod.Description;
                shippingOption.Rate        = GetRate(subTotal, weight, shippingMethod.ShippingMethodID);
                shippingOptions.Add(shippingOption);
            }

            return(shippingOptions);
        }
        public string GetShoppingCartItemSubTotalString(ShoppingCartItem shoppingCartItem)
        {
            var sb = new StringBuilder();

            if (shoppingCartItem.ProductVariant.CallForPrice)
            {
                sb.Append("<span class=\"productPrice\">");
                sb.Append(GetLocaleResourceString("Products.CallForPrice"));
                sb.Append("</span>");
            }
            else
            {
                //sub total
                decimal taxRate = decimal.Zero;
                decimal shoppingCartItemSubTotalWithDiscountBase = this.TaxService.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, true), out taxRate);
                decimal shoppingCartItemSubTotalWithDiscount     = this.CurrencyService.ConvertCurrency(shoppingCartItemSubTotalWithDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                string  subTotalString = PriceHelper.FormatPrice(shoppingCartItemSubTotalWithDiscount);

                sb.Append("<span class=\"productPrice\">");
                sb.Append(subTotalString);
                sb.Append("</span>");

                //display an applied discount amount
                decimal shoppingCartItemSubTotalWithoutDiscountBase = this.TaxService.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, false), out taxRate);
                decimal shoppingCartItemDiscountBase = shoppingCartItemSubTotalWithoutDiscountBase - shoppingCartItemSubTotalWithDiscountBase;
                if (shoppingCartItemDiscountBase > decimal.Zero)
                {
                    decimal shoppingCartItemDiscount = this.CurrencyService.ConvertCurrency(shoppingCartItemDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    string  discountString           = PriceHelper.FormatPrice(shoppingCartItemDiscount);

                    sb.Append("<br />");
                    sb.Append(GetLocaleResourceString("Wishlist.ItemYouSave"));
                    sb.Append("&nbsp;&nbsp;");
                    sb.Append(discountString);
                }
            }
            return(sb.ToString());
        }
Beispiel #5
0
        public string GetShoppingCartItemSubTotalString(ShoppingCartItem shoppingCartItem)
        {
            var     sb = new StringBuilder();
            decimal shoppingCartItemSubTotalWithDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, true));
            decimal shoppingCartItemSubTotalWithDiscount     = CurrencyManager.ConvertCurrency(shoppingCartItemSubTotalWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            string  subTotalString = PriceHelper.FormatPrice(shoppingCartItemSubTotalWithDiscount);

            sb.Append("<span class=\"productPrice\">");
            sb.Append(subTotalString);
            sb.Append("</span>");

            decimal shoppingCartItemDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetDiscountAmount(shoppingCartItem));

            if (shoppingCartItemDiscountBase > decimal.Zero)
            {
                decimal shoppingCartItemDiscount = CurrencyManager.ConvertCurrency(shoppingCartItemDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                string  discountString           = PriceHelper.FormatPrice(shoppingCartItemDiscount);

                sb.Append("<br />");
                sb.Append(GetLocaleResourceString("Wishlist.ItemYouSave"));
                sb.Append("&nbsp;&nbsp;");
                sb.Append(discountString);
            }
            return(sb.ToString());
        }
        public string GetShoppingCartItemSubTotalString(ShoppingCartItem shoppingCartItem)
        {
            StringBuilder sb      = new StringBuilder();
            decimal       taxRate = decimal.Zero;
            decimal       shoppingCartItemSubTotalWithDiscountBase = this.TaxService.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), customer, out taxRate);
            decimal       shoppingCartItemSubTotalWithDiscount     = this.CurrencyService.ConvertCurrency(shoppingCartItemSubTotalWithDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            string        subTotalString = PriceHelper.FormatPrice(shoppingCartItemSubTotalWithDiscount);

            sb.Append(subTotalString);

            decimal shoppingCartItemDiscountBase = this.TaxService.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetDiscountAmount(shoppingCartItem, customer), customer, out taxRate);

            if (shoppingCartItemDiscountBase > decimal.Zero)
            {
                decimal shoppingCartItemDiscount = this.CurrencyService.ConvertCurrency(shoppingCartItemDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                string  discountString           = PriceHelper.FormatPrice(shoppingCartItemDiscount);

                sb.Append("<br />");
                //sb.Append(GetLocaleResourceString("ShoppingCart.ItemYouSave"));
                sb.Append("Saved:");
                sb.Append("&nbsp;&nbsp;");
                sb.Append(discountString);
            }
            return(sb.ToString());
        }
        string CreateRequest(string siteid, string password, string cityFrom, string divisionFrom, ShipmentPackage shipmentPackage)
        {
            var usedMeasureWeight = MeasureManager.GetMeasureWeightBySystemKeyword(MEASUREWEIGHTSYSTEMKEYWORD);

            if (usedMeasureWeight == null)
            {
                throw new NopException(string.Format("UPS shipping service. Could not load \"{0}\" measure weight", MEASUREWEIGHTSYSTEMKEYWORD));
            }

            var usedMeasureDimension = MeasureManager.GetMeasureDimensionBySystemKeyword(MEASUREDIMENSIONSYSTEMKEYWORD);

            if (usedMeasureDimension == null)
            {
                throw new NopException(string.Format("UPS shipping service. Could not load \"{0}\" measure dimension", MEASUREDIMENSIONSYSTEMKEYWORD));
            }

            int     length = Convert.ToInt32(Math.Ceiling(MeasureManager.ConvertDimension(shipmentPackage.GetTotalLength(), MeasureManager.BaseDimensionIn, usedMeasureDimension)));
            int     height = Convert.ToInt32(Math.Ceiling(MeasureManager.ConvertDimension(shipmentPackage.GetTotalHeight(), MeasureManager.BaseDimensionIn, usedMeasureDimension)));
            int     width  = Convert.ToInt32(Math.Ceiling(MeasureManager.ConvertDimension(shipmentPackage.GetTotalWidth(), MeasureManager.BaseDimensionIn, usedMeasureDimension)));
            int     weight;
            decimal totalPrice = decimal.Zero;

            foreach (ShoppingCartItem item in shipmentPackage.Items)
            {
                totalPrice += PriceHelper.GetSubTotal(item, true);
            }
            ShippingConvertionBiz convertionBiz = new ShippingConvertionBiz();

            weight = convertionBiz.GetWeightFromTotalPrice(totalPrice, ShippingConvertionType.DHL);

            if (length < 1)
            {
                length = 1;
            }
            if (height < 1)
            {
                height = 1;
            }
            if (width < 1)
            {
                width = 1;
            }
            if (weight < 1)
            {
                weight = 1;
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sb.Append("<req:ShipmentBookRatingRequest xmlns:req=\"http://www.dhl.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.dhl.com ship-book-rate-req.xsd\">");

            // header
            sb.Append("<Request>");
            sb.Append("<ServiceHeader>");
            sb.Append(string.Format("<MessageTime>{0}</MessageTime>", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz")));
            sb.Append(string.Format("<MessageReference>{0}</MessageReference>", Guid.NewGuid().ToString().Replace("-", "")));
            sb.Append(string.Format("<SiteID>{0}</SiteID>", siteid));
            sb.Append(string.Format("<Password>{0}</Password>", password));
            sb.Append("</ServiceHeader>");
            sb.Append("</Request>");

            //Shipper
            sb.Append("<Shipper>");
            sb.Append(string.Format("<City>{0}</City>", cityFrom));
            sb.Append(string.Format("<Division>{0}</Division>", divisionFrom));
            sb.Append(string.Format("<PostalCode>{0}</PostalCode>", shipmentPackage.ZipPostalCodeFrom));
            sb.Append(string.Format("<CountryCode>{0}</CountryCode>", shipmentPackage.CountryFrom.TwoLetterIsoCode));
            sb.Append("</Shipper>");

            //Consignee
            sb.Append("<Consignee>");
            sb.Append(string.Format("<City>{0}</City>", shipmentPackage.ShippingAddress.City));
            sb.Append(string.Format("<Division>{0}</Division>", shipmentPackage.ShippingAddress.StateProvince != null ? shipmentPackage.ShippingAddress.StateProvince.Name : string.Empty));
            sb.Append(string.Format("<PostalCode>{0}</PostalCode>", shipmentPackage.ShippingAddress.ZipPostalCode));
            sb.Append(string.Format("<CountryCode>{0}</CountryCode>", shipmentPackage.ShippingAddress.Country.TwoLetterIsoCode));
            sb.Append("</Consignee>");

            //Shipment Details
            sb.Append("<ShipmentDetails>");
            sb.Append("<NumberOfPieces>1</NumberOfPieces>");
            sb.Append("<Pieces>");
            sb.Append("<Piece>");
            sb.Append("<PieceID>1</PieceID>");
            sb.Append("<PackageType>OD</PackageType>");
            sb.Append(string.Format("<Weight>{0}</Weight>", weight));
            sb.Append("<DimWeight>1</DimWeight>");
            sb.Append(string.Format("<Width>{0}</Width>", width));
            sb.Append(string.Format("<Height>{0}</Height>", height));
            sb.Append(string.Format("<Depth>{0}</Depth>", length));
            sb.Append("</Piece>");
            sb.Append("</Pieces>");
            sb.Append("<WeightUnit>L</WeightUnit>");
            sb.Append("<DimensionUnit>I</DimensionUnit>");
            sb.Append(string.Format("<Weight>{0}</Weight>", weight));
            sb.Append(string.Format("<ProductCode>{0}</ProductCode>", ProductCodeToken));
            sb.Append("</ShipmentDetails>");


            sb.Append("</req:ShipmentBookRatingRequest>");
            return(sb.ToString());
        }
        public string GetShoppingCartItemSubTotalString(ShoppingCartItem shoppingCartItem)
        {
            StringBuilder sb = new StringBuilder();
            decimal       shoppingCartItemSubTotalWithDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), customer);
            decimal       shoppingCartItemSubTotalWithDiscount     = CurrencyManager.ConvertCurrency(shoppingCartItemSubTotalWithDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
            string        subTotalString = PriceHelper.FormatPrice(shoppingCartItemSubTotalWithDiscount);

            sb.Append(subTotalString);

            decimal shoppingCartItemDiscountBase = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetDiscountAmount(shoppingCartItem, customer), customer);

            if (shoppingCartItemDiscountBase > decimal.Zero)
            {
                decimal shoppingCartItemDiscount = CurrencyManager.ConvertCurrency(shoppingCartItemDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                string  discountString           = PriceHelper.FormatPrice(shoppingCartItemDiscount);

                sb.Append("<br />");
                //sb.Append(GetLocaleResourceString("ShoppingCart.ItemYouSave"));
                sb.Append("Saved:");
                sb.Append("&nbsp;&nbsp;");
                sb.Append(discountString);
                sb.Append("<br />");
                sb.Append("<em>NOTE: This discount is applied to the current user</em>");
            }
            return(sb.ToString());
        }
        private string CreateRequest(string AccessKey, string Username, string Password,
                                     ShipmentPackage ShipmentPackage, UPSCustomerClassification customerClassification,
                                     UPSPickupType pickupType, UPSPackagingType packagingType)
        {
            var usedMeasureWeight = MeasureManager.GetMeasureWeightBySystemKeyword(MEASUREWEIGHTSYSTEMKEYWORD);

            if (usedMeasureWeight == null)
            {
                throw new NopException(string.Format("UPS shipping service. Could not load \"{0}\" measure weight", MEASUREWEIGHTSYSTEMKEYWORD));
            }

            var usedMeasureDimension = MeasureManager.GetMeasureDimensionBySystemKeyword(MEASUREDIMENSIONSYSTEMKEYWORD);

            if (usedMeasureDimension == null)
            {
                throw new NopException(string.Format("UPS shipping service. Could not load \"{0}\" measure dimension", MEASUREDIMENSIONSYSTEMKEYWORD));
            }

            int length = Convert.ToInt32(Math.Ceiling(MeasureManager.ConvertDimension(ShipmentPackage.GetTotalLength(), MeasureManager.BaseDimensionIn, usedMeasureDimension)));
            int height = Convert.ToInt32(Math.Ceiling(MeasureManager.ConvertDimension(ShipmentPackage.GetTotalHeight(), MeasureManager.BaseDimensionIn, usedMeasureDimension)));
            int width  = Convert.ToInt32(Math.Ceiling(MeasureManager.ConvertDimension(ShipmentPackage.GetTotalWidth(), MeasureManager.BaseDimensionIn, usedMeasureDimension)));

            #region modify as customer request: convert total items price to weight to calculate shipping fee
            int     weight;// = Convert.ToInt32(Math.Ceiling(MeasureManager.ConvertWeight(ShippingManager.GetShoppingCartTotalWeigth(ShipmentPackage.Items, ShipmentPackage.Customer), MeasureManager.BaseWeightIn, usedMeasureWeight)));
            decimal totalPrice = decimal.Zero;
            foreach (ShoppingCartItem item in ShipmentPackage.Items)
            {
                totalPrice += PriceHelper.GetSubTotal(item, true);
            }
            ShippingConvertionBiz convertionBiz = new ShippingConvertionBiz();
            weight = convertionBiz.GetWeightFromTotalPrice(totalPrice, ShippingConvertionType.UPS);
            #endregion

            if (length < 1)
            {
                length = 1;
            }
            if (height < 1)
            {
                height = 1;
            }
            if (width < 1)
            {
                width = 1;
            }
            if (weight < 1)
            {
                weight = 1;
            }

            string zipPostalCodeFrom = ShipmentPackage.ZipPostalCodeFrom;
            string zipPostalCodeTo   = ShipmentPackage.ShippingAddress.ZipPostalCode;
            string countryCodeFrom   = ShipmentPackage.CountryFrom.TwoLetterIsoCode;
            string countryCodeTo     = ShipmentPackage.ShippingAddress.Country.TwoLetterIsoCode;

            var sb = new StringBuilder();
            sb.Append("<?xml version='1.0'?>");
            sb.Append("<AccessRequest xml:lang='en-US'>");
            sb.AppendFormat("<AccessLicenseNumber>{0}</AccessLicenseNumber>", AccessKey);
            sb.AppendFormat("<UserId>{0}</UserId>", Username);
            sb.AppendFormat("<Password>{0}</Password>", Password);
            sb.Append("</AccessRequest>");
            sb.Append("<?xml version='1.0'?>");
            sb.Append("<RatingServiceSelectionRequest xml:lang='en-US'>");
            sb.Append("<Request>");
            sb.Append("<TransactionReference>");
            sb.Append("<CustomerContext>Bare Bones Rate Request</CustomerContext>");
            sb.Append("<XpciVersion>1.0001</XpciVersion>");
            sb.Append("</TransactionReference>");
            sb.Append("<RequestAction>Rate</RequestAction>");
            sb.Append("<RequestOption>Shop</RequestOption>");
            sb.Append("</Request>");
            sb.Append("<PickupType>");
            sb.AppendFormat("<Code>{0}</Code>", GetPickupTypeCode(pickupType));
            sb.Append("</PickupType>");
            sb.Append("<CustomerClassification>");
            sb.AppendFormat("<Code>{0}</Code>", GetCustomerClassificationCode(customerClassification));
            sb.Append("</CustomerClassification>");
            sb.Append("<Shipment>");
            sb.Append("<Shipper>");
            sb.Append("<Address>");
            sb.AppendFormat("<PostalCode>{0}</PostalCode>", zipPostalCodeFrom);
            sb.AppendFormat("<CountryCode>{0}</CountryCode>", countryCodeFrom);
            sb.Append("</Address>");
            sb.Append("</Shipper>");
            sb.Append("<ShipTo>");
            sb.Append("<Address>");
            sb.Append("<ResidentialAddressIndicator/>");
            sb.AppendFormat("<PostalCode>{0}</PostalCode>", zipPostalCodeTo);
            sb.AppendFormat("<CountryCode>{0}</CountryCode>", countryCodeTo);
            sb.Append("</Address>");
            sb.Append("</ShipTo>");
            sb.Append("<ShipFrom>");
            sb.Append("<Address>");
            sb.AppendFormat("<PostalCode>{0}</PostalCode>", zipPostalCodeFrom);
            sb.AppendFormat("<CountryCode>{0}</CountryCode>", countryCodeFrom);
            sb.Append("</Address>");
            sb.Append("</ShipFrom>");
            sb.Append("<Service>");
            sb.Append("<Code>03</Code>");
            sb.Append("</Service>");


            if ((!IsPackageTooHeavy(weight)) && (!IsPackageTooLarge(length, height, width)))
            {
                sb.Append("<Package>");
                sb.Append("<PackagingType>");
                sb.AppendFormat("<Code>{0}</Code>", GetPackagingTypeCode(packagingType));
                sb.Append("</PackagingType>");
                sb.Append("<Dimensions>");
                sb.AppendFormat("<Length>{0}</Length>", length);
                sb.AppendFormat("<Width>{0}</Width>", width);
                sb.AppendFormat("<Height>{0}</Height>", height);
                sb.Append("</Dimensions>");
                sb.Append("<PackageWeight>");
                sb.AppendFormat("<Weight>{0}</Weight>", weight);
                sb.Append("</PackageWeight>");
                sb.Append("</Package>");
            }
            else
            {
                int totalPackages        = 1;
                int totalPackagesDims    = 1;
                int totalPackagesWeights = 1;
                if (IsPackageTooHeavy(weight))
                {
                    totalPackagesWeights = Convert.ToInt32(Math.Ceiling((decimal)weight / (decimal)MAXPACKAGEWEIGHT));
                }
                if (IsPackageTooLarge(length, height, width))
                {
                    totalPackagesDims = Convert.ToInt32(Math.Ceiling((decimal)TotalPackageSize(length, height, width) / (decimal)108));
                }
                totalPackages = totalPackagesDims > totalPackagesWeights ? totalPackagesDims : totalPackagesWeights;
                if (totalPackages == 0)
                {
                    totalPackages = 1;
                }

                int weight2 = weight / totalPackages;
                int height2 = height / totalPackages;
                int width2  = width / totalPackages;
                int length2 = length / totalPackages;
                if (weight2 < 1)
                {
                    weight2 = 1;
                }
                if (height2 < 1)
                {
                    height2 = 1;
                }
                if (width2 < 1)
                {
                    width2 = 1;
                }
                if (length2 < 1)
                {
                    length2 = 1;
                }

                for (int i = 0; i < totalPackages; i++)
                {
                    sb.Append("<Package>");
                    sb.Append("<PackagingType>");
                    sb.AppendFormat("<Code>{0}</Code>", GetPackagingTypeCode(packagingType));
                    sb.Append("</PackagingType>");
                    sb.Append("<Dimensions>");
                    sb.AppendFormat("<Length>{0}</Length>", length2);
                    sb.AppendFormat("<Width>{0}</Width>", width2);
                    sb.AppendFormat("<Height>{0}</Height>", height2);
                    sb.Append("</Dimensions>");
                    sb.Append("<PackageWeight>");
                    sb.AppendFormat("<Weight>{0}</Weight>", weight2);
                    sb.Append("</PackageWeight>");
                    sb.Append("</Package>");
                }
            }


            sb.Append("</Shipment>");
            sb.Append("</RatingServiceSelectionRequest>");
            string requestString = sb.ToString();
            return(requestString);
        }
Beispiel #10
0
        /// <summary>
        /// Gets tax
        /// </summary>
        /// <param name="cart">Shopping cart</param>
        /// <param name="paymentMethodId">Payment method identifier</param>
        /// <param name="customer">Customer</param>
        /// <param name="error">Error</param>
        /// <returns>Tax total</returns>
        public static decimal GetTaxTotal(ShoppingCart cart, int paymentMethodId,
                                          Customer customer, ref string error)
        {
            decimal taxTotal = decimal.Zero;

            //items
            decimal itemsTaxTotal = decimal.Zero;

            foreach (var shoppingCartItem in cart)
            {
                string  error1 = string.Empty;
                string  error2 = string.Empty;
                decimal subTotalWithoutDiscountExclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), false, customer, ref error1);
                decimal subTotalWithoutDiscountInclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), true, customer, ref error2);
                if (!String.IsNullOrEmpty(error1))
                {
                    error = error1;
                }
                if (!String.IsNullOrEmpty(error2))
                {
                    error = error2;
                }

                decimal shoppingCartItemTax = subTotalWithoutDiscountInclTax - subTotalWithoutDiscountExclTax;
                itemsTaxTotal += shoppingCartItemTax;
            }

            //checkout attributes
            decimal checkoutAttributesTax = decimal.Zero;

            if (customer != null)
            {
                var caValues = CheckoutAttributeHelper.ParseCheckoutAttributeValues(customer.CheckoutAttributes);
                foreach (var caValue in caValues)
                {
                    string  error1    = string.Empty;
                    string  error2    = string.Empty;
                    decimal caExclTax = TaxManager.GetCheckoutAttributePrice(caValue, false, customer, ref error1);
                    decimal caInclTax = TaxManager.GetCheckoutAttributePrice(caValue, true, customer, ref error2);
                    if (!String.IsNullOrEmpty(error1))
                    {
                        error = error1;
                    }
                    if (!String.IsNullOrEmpty(error2))
                    {
                        error = error2;
                    }

                    decimal caTax = caInclTax - caExclTax;
                    checkoutAttributesTax += caTax;
                }
            }

            //shipping
            decimal shippingTax = decimal.Zero;

            if (TaxManager.ShippingIsTaxable)
            {
                string  error1          = string.Empty;
                string  error2          = string.Empty;
                decimal?shippingExclTax = ShippingManager.GetShoppingCartShippingTotal(cart, customer, false, ref error1);
                decimal?shippingInclTax = ShippingManager.GetShoppingCartShippingTotal(cart, customer, true, ref error2);
                if (!String.IsNullOrEmpty(error1))
                {
                    error = error1;
                }
                if (!String.IsNullOrEmpty(error2))
                {
                    error = error2;
                }
                if (shippingExclTax.HasValue && shippingInclTax.HasValue)
                {
                    shippingTax = shippingInclTax.Value - shippingExclTax.Value;
                }
            }

            //payment method additional fee
            decimal paymentMethodAdditionalFeeTax = decimal.Zero;

            if (TaxManager.PaymentMethodAdditionalFeeIsTaxable)
            {
                string  error1 = string.Empty;
                string  error2 = string.Empty;
                decimal paymentMethodAdditionalFee        = PaymentManager.GetAdditionalHandlingFee(paymentMethodId);
                decimal?paymentMethodAdditionalFeeExclTax = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, false, customer, ref error1);
                decimal?paymentMethodAdditionalFeeInclTax = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, true, customer, ref error2);
                if (!String.IsNullOrEmpty(error1))
                {
                    error = error1;
                }
                if (!String.IsNullOrEmpty(error2))
                {
                    error = error2;
                }
                if (paymentMethodAdditionalFeeExclTax.HasValue && paymentMethodAdditionalFeeInclTax.HasValue)
                {
                    paymentMethodAdditionalFeeTax = paymentMethodAdditionalFeeInclTax.Value - paymentMethodAdditionalFeeExclTax.Value;
                }
            }

            taxTotal = itemsTaxTotal + checkoutAttributesTax + shippingTax + paymentMethodAdditionalFeeTax;
            taxTotal = Math.Round(taxTotal, 2);
            return(taxTotal);
        }
Beispiel #11
0
        /// <summary>
        /// Gets tax
        /// </summary>
        /// <param name="Cart">Shopping cart</param>
        /// <param name="PaymentMethodID">Payment method identifier</param>
        /// <param name="customer">Customer</param>
        /// <param name="Error">Error</param>
        /// <returns>Tax total</returns>
        public static decimal GetTaxTotal(ShoppingCart Cart, int PaymentMethodID,
                                          Customer customer, ref string Error)
        {
            decimal taxTotal = decimal.Zero;

            //items
            decimal itemsTaxTotal = decimal.Zero;

            foreach (ShoppingCartItem shoppingCartItem in Cart)
            {
                decimal subTotalWithoutDiscountExclTax = decimal.Zero;
                decimal subTotalWithoutDiscountInclTax = decimal.Zero;

                string Error1 = string.Empty;
                string Error2 = string.Empty;
                subTotalWithoutDiscountExclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), false, customer, ref Error1);
                subTotalWithoutDiscountInclTax = TaxManager.GetPrice(shoppingCartItem.ProductVariant, PriceHelper.GetSubTotal(shoppingCartItem, customer, true), true, customer, ref Error2);
                if (!String.IsNullOrEmpty(Error1))
                {
                    Error = Error1;
                }
                if (!String.IsNullOrEmpty(Error2))
                {
                    Error = Error2;
                }

                decimal shoppingCartItemTax = subTotalWithoutDiscountInclTax - subTotalWithoutDiscountExclTax;
                itemsTaxTotal += shoppingCartItemTax;
            }

            //shipping
            decimal shippingTax = decimal.Zero;

            if (TaxManager.ShippingIsTaxable)
            {
                string  Error3          = string.Empty;
                string  Error4          = string.Empty;
                decimal?shippingExclTax = ShippingManager.GetShoppingCartShippingTotal(Cart, customer, false, ref Error3);
                decimal?shippingInclTax = ShippingManager.GetShoppingCartShippingTotal(Cart, customer, true, ref Error4);
                if (!String.IsNullOrEmpty(Error3))
                {
                    Error = Error3;
                }
                if (!String.IsNullOrEmpty(Error4))
                {
                    Error = Error4;
                }
                if (shippingExclTax.HasValue && shippingInclTax.HasValue)
                {
                    shippingTax = shippingInclTax.Value - shippingExclTax.Value;
                }
            }

            //payment method additional fee
            decimal paymentMethodAdditionalFeeTax = decimal.Zero;

            if (TaxManager.PaymentMethodAdditionalFeeIsTaxable)
            {
                string  Error5 = string.Empty;
                string  Error6 = string.Empty;
                decimal paymentMethodAdditionalFee        = PaymentManager.GetAdditionalHandlingFee(PaymentMethodID);
                decimal?paymentMethodAdditionalFeeExclTax = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, false, customer, ref Error5);
                decimal?paymentMethodAdditionalFeeInclTax = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, true, customer, ref Error6);
                if (!String.IsNullOrEmpty(Error5))
                {
                    Error = Error5;
                }
                if (!String.IsNullOrEmpty(Error6))
                {
                    Error = Error6;
                }
                if (paymentMethodAdditionalFeeExclTax.HasValue && paymentMethodAdditionalFeeInclTax.HasValue)
                {
                    paymentMethodAdditionalFeeTax = paymentMethodAdditionalFeeInclTax.Value - paymentMethodAdditionalFeeExclTax.Value;
                }
            }

            taxTotal = itemsTaxTotal + shippingTax + paymentMethodAdditionalFeeTax;
            taxTotal = Math.Round(taxTotal, 2);
            return(taxTotal);
        }