public void Can_save_and_load_shippingMethod()
        {
            var shippingMethod = new ShippingMethod
                               {
                                   Name = "Name 1",
                                   Description = "Description 1",
                                   DisplayOrder = 1
                               };

            var fromDb = SaveAndLoadEntity(shippingMethod);
            fromDb.ShouldNotBeNull();
            fromDb.Name.ShouldEqual("Name 1");
            fromDb.Description.ShouldEqual("Description 1");
            fromDb.DisplayOrder.ShouldEqual(1);
        }
        protected void UpdateLocales(ShippingMethod shippingMethod, ShippingMethodModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(shippingMethod,
                                                               x => x.Name,
                                                               localized.Name,
                                                               localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(shippingMethod,
                                                           x => x.Description,
                                                           localized.Description,
                                                           localized.LanguageId);
            }
        }
        public void Can_save_and_load_shippingMethod_with_restriction()
        {
            var shippingMethod = new ShippingMethod
            {
                Name = "Name 1",
                DisplayOrder = 1
            };
            shippingMethod.RestrictedCountries.Add(GetTestCountry());

            var fromDb = SaveAndLoadEntity(shippingMethod);
            fromDb.ShouldNotBeNull();


            fromDb.RestrictedCountries.ShouldNotBeNull();
            (fromDb.RestrictedCountries.Count == 1).ShouldBeTrue();
            fromDb.RestrictedCountries.First().Name.ShouldEqual("United States");
        }
示例#4
0
        private void PrepareShippingMethodModel(ShippingMethodModel model, ShippingMethod shippingMethod)
        {
            var customerRoles = _customerService.GetAllCustomerRoles(true);
            var countries = _countryService.GetAllCountries(true);

            model.AvailableCustomerRoles = new List<SelectListItem>();
            model.AvailableCountries = new List<SelectListItem>();

            model.AvailableCountryExclusionContextTypes = CountryRestrictionContextType.BillingAddress.ToSelectList(false).ToList();

            foreach (var role in customerRoles.OrderBy(x => x.Name))
            {
                model.AvailableCustomerRoles.Add(new SelectListItem { Text = role.Name, Value = role.Id.ToString() });
            }

            foreach (var country in countries.OrderBy(x => x.Name))
            {
                model.AvailableCountries.Add(new SelectListItem { Text = country.GetLocalized(x => x.Name), Value = country.Id.ToString() });
            }

            if (shippingMethod != null)
            {
                model.ExcludedCustomerRoleIds = shippingMethod.ExcludedCustomerRoleIds.SplitSafe(",");
                model.ExcludedCountryIds = shippingMethod.RestrictedCountries.Select(x => x.Id.ToString()).ToArray();

                model.CountryExclusionContext = shippingMethod.CountryExclusionContext;
            }
        }
示例#5
0
        private void ApplyRestrictions(ShippingMethod shippingMethod, ShippingMethodModel model)
        {
            var countries = _countryService.GetAllCountries(true);

            shippingMethod.ExcludedCustomerRoleIds = Request.Form["ExcludedCustomerRoleIds"];
            shippingMethod.CountryExclusionContext = model.CountryExclusionContext;

            string[] excludedCountryIds = Request.Form["ExcludedCountryIds"].SplitSafe(",");

            foreach (var country in countries)
            {
                if (excludedCountryIds.Contains(country.Id.ToString()))
                {
                    if (shippingMethod.RestrictedCountries.Where(c => c.Id == country.Id).FirstOrDefault() == null)
                    {
                        shippingMethod.RestrictedCountries.Add(country);
                        _shippingService.UpdateShippingMethod(shippingMethod);
                    }
                }
                else
                {
                    if (shippingMethod.RestrictedCountries.Where(c => c.Id == country.Id).FirstOrDefault() != null)
                    {
                        shippingMethod.RestrictedCountries.Remove(country);
                        _shippingService.UpdateShippingMethod(shippingMethod);
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Updates the shipping method
        /// </summary>
        /// <param name="shippingMethod">Shipping method</param>
        public virtual void UpdateShippingMethod(ShippingMethod shippingMethod)
        {
            if (shippingMethod == null)
                throw new ArgumentNullException("shippingMethod");

            _shippingMethodRepository.Update(shippingMethod);

            //event notification
            _eventPublisher.EntityUpdated(shippingMethod);
        }
 public static ShippingMethod ToEntity(this ShippingMethodModel model, ShippingMethod destination)
 {
     return Mapper.Map(model, destination);
 }
        private void PrepareShippingMethodModel(ShippingMethodModel model, ShippingMethod shippingMethod)
        {
            var allFilters = _shippingService.GetAllShippingMethodFilters();

            if (shippingMethod != null)
            {
                model.FilterConfigurationUrls = allFilters
                    .Select(x => "'" + x.GetConfigurationUrl(shippingMethod.Id) + "'")
                    .OrderBy(x => x)
                    .ToList();
            }
            else
            {
                model.FilterConfigurationUrls = new List<string>();
            }
        }