示例#1
0
        private void PreparePaymentMethodEditModel(PaymentMethodEditModel model, PaymentMethod paymentMethod)
        {
            var customerRoles = _customerService.GetAllCustomerRoles(true);
            var shippingMethods = _shippingService.GetAllShippingMethods();
            var countries = _countryService.GetAllCountries(true);

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

            model.AvailableCountryExclusionContextTypes = CountryRestrictionContextType.BillingAddress.ToSelectList(false).ToList();
            model.AvailableAmountRestrictionContextTypes = AmountRestrictionContextType.SubtotalAmount.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 shippingMethod in shippingMethods.OrderBy(x => x.Name))
            {
                model.AvailableShippingMethods.Add(new SelectListItem { Text = shippingMethod.GetLocalized(x => x.Name), Value = shippingMethod.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 (paymentMethod != null)
            {
                model.ExcludedCustomerRoleIds = paymentMethod.ExcludedCustomerRoleIds.SplitSafe(",");
                model.ExcludedShippingMethodIds = paymentMethod.ExcludedShippingMethodIds.SplitSafe(",");
                model.ExcludedCountryIds = paymentMethod.ExcludedCountryIds.SplitSafe(",");

                model.MinimumOrderAmount = paymentMethod.MinimumOrderAmount;
                model.MaximumOrderAmount = paymentMethod.MaximumOrderAmount;

                model.CountryExclusionContext = paymentMethod.CountryExclusionContext;
                model.AmountRestrictionContext = paymentMethod.AmountRestrictionContext;

                model.FullDescription = paymentMethod.FullDescription;
            }
        }
        /// <summary>
        /// Updates payment method extra data
        /// </summary>
        /// <param name="paymentMethod">Payment method</param>
        public virtual void UpdatePaymentMethod(PaymentMethod paymentMethod)
        {
            if (paymentMethod == null)
                throw new ArgumentNullException("paymentMethod");

            _paymentMethodRepository.Update(paymentMethod);

            _services.EventPublisher.EntityUpdated(paymentMethod);
        }
示例#3
0
        public ActionResult Edit(string systemName, bool continueEditing, PaymentMethodEditModel model)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManagePaymentMethods))
                return AccessDeniedView();

            var provider = _paymentService.LoadPaymentMethodBySystemName(systemName);
            if (provider == null)
                return HttpNotFound();

            _pluginMediator.SetSetting(provider.Metadata, "FriendlyName", model.FriendlyName);
            _pluginMediator.SetSetting(provider.Metadata, "Description", model.Description);

            var paymentMethod = _paymentService.GetPaymentMethodBySystemName(systemName);

            if (paymentMethod == null)
                paymentMethod = new PaymentMethod { PaymentMethodSystemName = systemName };

            paymentMethod.ExcludedCustomerRoleIds = Request.Form["ExcludedCustomerRoleIds"];
            paymentMethod.ExcludedShippingMethodIds = Request.Form["ExcludedShippingMethodIds"];
            paymentMethod.ExcludedCountryIds = Request.Form["ExcludedCountryIds"];

            paymentMethod.MinimumOrderAmount = model.MinimumOrderAmount;
            paymentMethod.MaximumOrderAmount = model.MaximumOrderAmount;

            paymentMethod.CountryExclusionContext = model.CountryExclusionContext;
            paymentMethod.AmountRestrictionContext = model.AmountRestrictionContext;

            paymentMethod.FullDescription = model.FullDescription;

            if (paymentMethod.Id == 0)
                _paymentService.InsertPaymentMethod(paymentMethod);
            else
                _paymentService.UpdatePaymentMethod(paymentMethod);

            foreach (var localized in model.Locales)
            {
                _pluginMediator.SaveLocalizedValue(provider.Metadata, localized.LanguageId, "FriendlyName", localized.FriendlyName);
                _pluginMediator.SaveLocalizedValue(provider.Metadata, localized.LanguageId, "Description", localized.Description);

                _localizedEntityService.SaveLocalizedValue(paymentMethod, x => x.FullDescription, localized.FullDescription, localized.LanguageId);
            }

            NotifySuccess(_services.Localization.GetResource("Admin.Common.DataEditSuccess"));

            return (continueEditing ?
                RedirectToAction("Edit", "Payment", new { systemName = systemName }) :
                RedirectToAction("Providers", "Payment"));
        }