当前位置: 首页>>代码示例>>C#>>正文


C# Shipping.GetShippingOptionRequest类代码示例

本文整理汇总了C#中Nop.Services.Shipping.GetShippingOptionRequest的典型用法代码示例。如果您正苦于以下问题:C# GetShippingOptionRequest类的具体用法?C# GetShippingOptionRequest怎么用?C# GetShippingOptionRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GetShippingOptionRequest类属于Nop.Services.Shipping命名空间,在下文中一共展示了GetShippingOptionRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateShippingOptionRequests

        /// <summary>
        /// Create shipment packages (requests) from shopping cart
        /// </summary>
        /// <param name="cart">Shopping cart</param>
        /// <param name="shippingAddress">Shipping address</param>
        /// <returns>Shipment packages (requests)</returns>
        public virtual IList<GetShippingOptionRequest> CreateShippingOptionRequests(IList<ShoppingCartItem> cart, 
            Address shippingAddress)
        {
            //if we always ship from the default shipping origin, then there's only one request
            //if we ship from warehouses, then there could be several requests


            //key - warehouse identifier (0 - default shipping origin)
            //value - request
            var requests = new Dictionary<int, GetShippingOptionRequest>();

            foreach (var sci in cart)
            {
                if (!sci.IsShipEnabled)
                    continue;

                Warehouse warehouse = null;
                if (_shippingSettings.UseWarehouseLocation)
                {
                    warehouse = GetWarehouseById(sci.Product.WarehouseId);
                }
                GetShippingOptionRequest request = null;
                if (requests.ContainsKey(warehouse != null ? warehouse.Id : 0))
                {
                    request = requests[warehouse != null ? warehouse.Id : 0];
                    //add item
                    request.Items.Add(sci);
                }
                else
                {
                    request = new GetShippingOptionRequest();
                    //add item
                    request.Items.Add(sci);
                    //customer
                    request.Customer = cart.GetCustomer();
                    //ship to
                    request.ShippingAddress = shippingAddress;
                    //ship from
                    Address originAddress = null;
                    if (warehouse != null)
                    {
                        //warehouse address
                        originAddress = _addressService.GetAddressById(warehouse.AddressId);
                    }
                    if (originAddress == null)
                    {
                        //no warehouse address. in this case use the default shipping origin
                        originAddress = _addressService.GetAddressById(_shippingSettings.ShippingOriginAddressId);
                    }
                    if (originAddress != null)
                    {
                        request.CountryFrom = originAddress.Country;
                        request.StateProvinceFrom = originAddress.StateProvince;
                        request.ZipPostalCodeFrom = originAddress.ZipPostalCode;
                        request.CityFrom = originAddress.City;
                        request.AddressFrom = originAddress.Address1;
                    }

                    requests.Add(warehouse != null ? warehouse.Id : 0, request);
                }

            }

            return requests.Values.ToList();
        }
开发者ID:aleks279,项目名称:atrend-test,代码行数:71,代码来源:ShippingService.cs

示例2: can_calculate_with_multple_items_1

        public void can_calculate_with_multple_items_1()
        {
            var request = new GetShippingOptionRequest();
            request.Items.Add(new ShoppingCartItem()
                                  {
                                      Quantity = 3,
                                      ProductVariant = new ProductVariant()
                                                           {
                                                               Length = 2,
                                                               Width = 2,
                                                               Height = 2
                                                           }
                                  });
            request.Items.Add(new ShoppingCartItem()
                                  {
                                      Quantity = 1,
                                      ProductVariant = new ProductVariant()
                                                           {
                                                               Length = 3,
                                                               Width = 5,
                                                               Height = 2
                                                           }
                                  });

            decimal length, width, height = 0;
            request.GetDimensions(out width, out length, out height);
            Math.Round(length, 2).ShouldEqual(3.78);
            Math.Round(width, 2).ShouldEqual(5);    //preserve max width
            Math.Round(height, 2).ShouldEqual(3.78);
        }
开发者ID:emretiryaki,项目名称:paymill-nopcommerce,代码行数:30,代码来源:CalculateDimensionsTests.cs

示例3: GetFixedRate

        /// <summary>
        /// Gets fixed shipping rate (if shipping rate computation method allows it and the rate can be calculated before checkout).
        /// </summary>
        /// <param name="getShippingOptionRequest">A request for getting shipping options</param>
        /// <returns>Fixed shipping rate; or null in case there's no fixed shipping rate</returns>
        public decimal? GetFixedRate(GetShippingOptionRequest getShippingOptionRequest)
        {
            if (getShippingOptionRequest == null)
                throw new ArgumentNullException("getShippingOptionRequest");

            return GetRate();
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:12,代码来源:FixedRateTestShippingRateComputationMethod.cs

示例4: GetShippingOptions

        /// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="getShippingOptionRequest">A request for getting shipping options</param>
        /// <returns>Represents a response of getting shipping rate options</returns>
        public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest getShippingOptionRequest)
        {
            if (getShippingOptionRequest == null)
                throw new ArgumentNullException("getShippingOptionRequest");

            var response = new GetShippingOptionResponse();

            if (getShippingOptionRequest.Items == null || getShippingOptionRequest.Items.Count == 0)
            {
                response.AddError("No shipment items");
                return response;
            }

            int? restrictByCountryId = (getShippingOptionRequest.ShippingAddress != null && getShippingOptionRequest.ShippingAddress.Country != null) ? (int?)getShippingOptionRequest.ShippingAddress.Country.Id : null;
            var shippingMethods = this._shippingService.GetAllShippingMethods(restrictByCountryId);
            foreach (var shippingMethod in shippingMethods)
            {
                var shippingOption = new ShippingOption();
                shippingOption.Name = shippingMethod.GetLocalized(x => x.Name);
                shippingOption.Description = shippingMethod.GetLocalized(x => x.Description);
                shippingOption.Rate = GetRate(shippingMethod.Id);
                response.ShippingOptions.Add(shippingOption);
            }

            return response;
        }
开发者ID:haithemChkel,项目名称:nopCommerce_33,代码行数:31,代码来源:FixedRateShippingComputationMethod.cs

示例5: Can_get_shoppingCart_totalWeight_without_attributes

 public void Can_get_shoppingCart_totalWeight_without_attributes()
 {
     var request = new GetShippingOptionRequest
     {
         Items =
         {
             new GetShippingOptionRequest.PackageItem(new ShoppingCartItem
             {
                 AttributesXml = "",
                 Quantity = 3,
                 Product = new Product
                 {
                     Weight = 1.5M,
                     Height = 2.5M,
                     Length = 3.5M,
                     Width = 4.5M
                 }
             }),
             new GetShippingOptionRequest.PackageItem(new ShoppingCartItem
             {
                 AttributesXml = "",
                 Quantity = 4,
                 Product = new Product
                 {
                     Weight = 11.5M,
                     Height = 12.5M,
                     Length = 13.5M,
                     Width = 14.5M
                 }
             })
         }
     };
     _shippingService.GetTotalWeight(request).ShouldEqual(50.5M);
 }
开发者ID:rajendra1809,项目名称:nopCommerce,代码行数:34,代码来源:ShippingServiceTests.cs

示例6: IsDomesticRequest

 /// <summary>
 /// Is a request domestic
 /// </summary>
 /// <param name="getShippingOptionRequest">Request</param>
 /// <returns>Rsult</returns>
 protected bool IsDomesticRequest(GetShippingOptionRequest getShippingOptionRequest)
 {
     //Origin Country must be USA, Collect USA from list of countries
     bool result = true;
     if (getShippingOptionRequest != null &&
         getShippingOptionRequest.ShippingAddress != null &&
         getShippingOptionRequest.ShippingAddress.Country != null)
     {
         switch (getShippingOptionRequest.ShippingAddress.Country.ThreeLetterIsoCode)
         {
             case "USA": // United States
             case "PRI": // Puerto Rico
             case "UMI": // United States minor outlying islands
             case "ASM": // American Samoa
             case "GUM": // Guam
             case "MHL": // Marshall Islands
             case "FSM": // Micronesia
             case "MNP": // Northern Mariana Islands
             case "PLW": // Palau
             case "VIR": // Virgin Islands (U.S.)
                 result = true;
                 break;
             default:
                 result = false;
                 break;
         }
     }
     return result;
 }
开发者ID:minuzZ,项目名称:zelectroshop,代码行数:34,代码来源:USPSComputationMethod.cs

示例7: GetWeight

        private int GetWeight(GetShippingOptionRequest getShippingOptionRequest)
        {
            var totalWeigth = _shippingService.GetTotalWeight(getShippingOptionRequest.Items);

            int value = Convert.ToInt32(Math.Ceiling(this._measureService.ConvertFromPrimaryMeasureWeight(totalWeigth, this.GatewayMeasureWeight)));
            return (value < MIN_WEIGHT ? MIN_WEIGHT : value);
        }
开发者ID:haithemChkel,项目名称:nopCommerce_33,代码行数:7,代码来源:AustraliaPostComputationMethod.cs

示例8: GetWeight

        /// <summary>
        /// Calculate parcel weight in kgs
        /// </summary>
        /// <param name="getShippingOptionRequest">A request for getting shipping options</param>
        /// <param name="weight">Weight</param>
        private void GetWeight(GetShippingOptionRequest getShippingOptionRequest, out decimal weight)
        {
            var usedMeasureWeight = _measureService.GetMeasureWeightBySystemKeyword("kg");
            if (usedMeasureWeight == null)
                throw new NopException("CanadaPost shipping service. Could not load \"kg\" measure weight");

            weight = _shippingService.GetTotalWeight(getShippingOptionRequest);
            weight = _measureService.ConvertFromPrimaryMeasureWeight(weight, usedMeasureWeight);
        }
开发者ID:nvolpe,项目名称:raver,代码行数:14,代码来源:CanadaPostComputationMethod.cs

示例9: IsDomesticRequest

 /// <summary>
 /// Is a request domestic
 /// </summary>
 /// <param name="getShippingOptionRequest">Request</param>
 /// <returns>Rsult</returns>
 protected bool IsDomesticRequest(GetShippingOptionRequest getShippingOptionRequest)
 {
     //Origin Country must be USA, Collect USA from list of countries
     bool result = true;
     if (getShippingOptionRequest != null &&
         getShippingOptionRequest.ShippingAddress != null &&
         getShippingOptionRequest.ShippingAddress.Country != null)
     {
         result = getShippingOptionRequest.ShippingAddress.Country.ThreeLetterIsoCode == "USA";
     }
     return result;
 }
开发者ID:philipengland,项目名称:albionextrusions.co.uk,代码行数:17,代码来源:USPSComputationMethod.cs

示例10: CreateShippingOptionRequest

 /// <summary>
 /// Create shipment package from shopping cart
 /// </summary>
 /// <param name="cart">Shopping cart</param>
 /// <param name="shippingAddress">Shipping address</param>
 /// <returns>Shipment package</returns>
 public virtual GetShippingOptionRequest CreateShippingOptionRequest(IList<ShoppingCartItem> cart,
     Address shippingAddress)
 {
     var request = new GetShippingOptionRequest();
     request.Customer = cart.GetCustomer();
     request.Items = new List<ShoppingCartItem>();
     foreach (var sc in cart)
         if (sc.IsShipEnabled)
             request.Items.Add(sc);
     request.ShippingAddress = shippingAddress;
     //TODO set values from warehouses or shipping origin
     request.CountryFrom = null;
     request.StateProvinceFrom = null;
     request.ZipPostalCodeFrom = string.Empty;
     return request;
 }
开发者ID:cmcginn,项目名称:StoreFront,代码行数:22,代码来源:ShippingService.cs

示例11: can_calculate_with_cubic_item_and_multiple_qty

        public void can_calculate_with_cubic_item_and_multiple_qty()
        {
            var request = new GetShippingOptionRequest();
            request.Items.Add(new ShoppingCartItem()
                                  {
                                      Quantity = 3,
                                      ProductVariant = new ProductVariant()
                                                           {
                                                               Length = 2,
                                                               Width = 2,
                                                               Height = 2
                                                           }
                                  });

            decimal length, width, height = 0;
            request.GetDimensions(out width, out length, out height);
            Math.Round(length, 2).ShouldEqual(2.88);
            Math.Round(width, 2).ShouldEqual(2.88);
            Math.Round(height, 2).ShouldEqual(2.88);
        }
开发者ID:emretiryaki,项目名称:paymill-nopcommerce,代码行数:20,代码来源:CalculateDimensionsTests.cs

示例12: GetShippingOptions

        /// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="getShippingOptionRequest">A request for getting shipping options</param>
        /// <returns>Represents a response of getting shipping rate options</returns>
        public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest getShippingOptionRequest)
        {
            if (getShippingOptionRequest == null)
                throw new ArgumentNullException("getShippingOptionRequest");

            var response = new GetShippingOptionResponse();
            response.ShippingOptions.Add(new ShippingOption()
                {
                    Name = "Shipping option 1",
                    Description = "",
                    Rate = GetRate()
                });
            response.ShippingOptions.Add(new ShippingOption()
                {
                    Name = "Shipping option 2",
                    Description = "",
                    Rate = GetRate()
                });

            return response;
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:26,代码来源:FixedRateTestShippingRateComputationMethod.cs

示例13: GetFixedRate

        /// <summary>
        /// Gets fixed shipping rate (if shipping rate computation method allows it and the rate can be calculated before checkout).
        /// </summary>
        /// <param name="getShippingOptionRequest">A request for getting shipping options</param>
        /// <returns>Fixed shipping rate; or null in case there's no fixed shipping rate</returns>
        public decimal? GetFixedRate(GetShippingOptionRequest getShippingOptionRequest)
        {
            if (getShippingOptionRequest == null)
                throw new ArgumentNullException("getShippingOptionRequest");

            int? restrictByCountryId = (getShippingOptionRequest.ShippingAddress != null && getShippingOptionRequest.ShippingAddress.CountryId != 0) ? getShippingOptionRequest.ShippingAddress.CountryId : 0;
            var shippingMethods = this._shippingService.GetAllShippingMethods(restrictByCountryId);

            var rates = new List<decimal>();
            foreach (var shippingMethod in shippingMethods)
            {
                decimal rate = GetRate(shippingMethod.Id);
                if (!rates.Contains(rate))
                    rates.Add(rate);
            }

            //return default rate if all of them equal
            if (rates.Count == 1)
                return rates[0];

            return null;
        }
开发者ID:powareverb,项目名称:grandnode,代码行数:27,代码来源:FixedRateShippingComputationMethod.cs

示例14: can_calculate_with_multple_items_2

        public void can_calculate_with_multple_items_2()
        {
            //take 8 cubes of 1x1x1 which is "packed" as 2x2x2
            var request = new GetShippingOptionRequest();
            for (int i = 0; i < 8;i++)
                request.Items.Add(new ShoppingCartItem()
                {
                    Quantity = 1,
                    ProductVariant = new ProductVariant()
                    {
                        Length = 1,
                        Width = 1,
                        Height = 1
                    }
                });

            decimal length, width, height = 0;
            request.GetDimensions(out width, out length, out height);
            Math.Round(length, 2).ShouldEqual(2);
            Math.Round(width, 2).ShouldEqual(2);
            Math.Round(height, 2).ShouldEqual(2);
        }
开发者ID:emretiryaki,项目名称:paymill-nopcommerce,代码行数:22,代码来源:CalculateDimensionsTests.cs

示例15: SetIndividualPackageLineItemsOneItemPerPackage

        private void SetIndividualPackageLineItemsOneItemPerPackage(RateRequest request, GetShippingOptionRequest getShippingOptionRequest, decimal orderSubTotal, string currencyCode)
        {
            // Rate request setup - each Shopping Cart Item is a separate package

            var usedMeasureWeight = GetUsedMeasureWeight();
            var usedMeasureDimension = GetUsedMeasureDimension();

            var items = getShippingOptionRequest.Items;
            var totalItems = items.GetTotalProducts();
            request.RequestedShipment.PackageCount = totalItems.ToString();
            request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[totalItems];

            int i = 0;
            foreach (var sci in items)
            {
                int length = ConvertFromPrimaryMeasureDimension(sci.ProductVariant.Length, usedMeasureDimension);
                int height = ConvertFromPrimaryMeasureDimension(sci.ProductVariant.Height, usedMeasureDimension);
                int width = ConvertFromPrimaryMeasureDimension(sci.ProductVariant.Width, usedMeasureDimension);
                int weight = ConvertFromPrimaryMeasureWeight(sci.ProductVariant.Weight, usedMeasureWeight);
                if (length < 1)
                    length = 1;
                if (height < 1)
                    height = 1;
                if (width < 1)
                    width = 1;
                if (weight < 1)
                    weight = 1;

                for (int j = 0; j < sci.Quantity; j++)
                {
                    request.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem();
                    request.RequestedShipment.RequestedPackageLineItems[i].SequenceNumber = (i + 1).ToString(); // package sequence number
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight = new RateServiceWebReference.Weight(); // package weight
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight.Units = RateServiceWebReference.WeightUnits.LB;
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight.Value = (decimal)weight;

                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions = new RateServiceWebReference.Dimensions(); // package dimensions
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = length.ToString();
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = height.ToString();
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width = width.ToString();
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units = RateServiceWebReference.LinearUnits.IN;

                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue = new Money(); // insured value
                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Amount = sci.ProductVariant.Price;
                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Currency = currencyCode;

                    i++;
                }
            }
        }
开发者ID:emretiryaki,项目名称:paymill-nopcommerce,代码行数:50,代码来源:FedexComputationMethod.cs


注:本文中的Nop.Services.Shipping.GetShippingOptionRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。