public void CanLoadDiscountRequirementRules() { var rules = _discountPluginManager.LoadAllPlugins(); rules.Should().NotBeNull(); rules.Any().Should().BeTrue(); }
public void Can_load_discountRequirementRules() { RunWithTestServiceProvider(() => { var rules = _discountPluginManager.LoadAllPlugins(); rules.Should().NotBeNull(); rules.Any().Should().BeTrue(); }); }
/// <summary> /// Prepare discount model /// </summary> /// <param name="model">Discount model</param> /// <param name="discount">Discount</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Discount model</returns> public virtual DiscountModel PrepareDiscountModel(DiscountModel model, Discount discount, bool excludeProperties = false) { if (discount != null) { //fill in model values from the entity model ??= discount.ToModel <DiscountModel>(); //prepare available discount requirement rules var discountRules = _discountPluginManager.LoadAllPlugins(); foreach (var discountRule in discountRules) { model.AvailableDiscountRequirementRules.Add(new SelectListItem { Text = discountRule.PluginDescriptor.FriendlyName, Value = discountRule.PluginDescriptor.SystemName }); } model.AvailableDiscountRequirementRules.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Promotions.Discounts.Requirements.DiscountRequirementType.AddGroup"), Value = "AddGroup" }); model.AvailableDiscountRequirementRules.Insert(0, new SelectListItem { Text = _localizationService.GetResource("Admin.Promotions.Discounts.Requirements.DiscountRequirementType.Select"), Value = string.Empty }); //prepare available requirement groups var requirementGroups = _discountService.GetAllDiscountRequirements(discount.Id).Where(requirement => requirement.IsGroup); model.AvailableRequirementGroups = requirementGroups.Select(requirement => new SelectListItem { Value = requirement.Id.ToString(), Text = requirement.DiscountRequirementRuleSystemName }).ToList(); //prepare nested search models PrepareDiscountUsageHistorySearchModel(model.DiscountUsageHistorySearchModel, discount); PrepareDiscountProductSearchModel(model.DiscountProductSearchModel, discount); PrepareDiscountCategorySearchModel(model.DiscountCategorySearchModel, discount); PrepareDiscountManufacturerSearchModel(model.DiscountManufacturerSearchModel, discount); } model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; //get URL of discount with coupon code if (model.RequiresCouponCode && !string.IsNullOrEmpty(model.CouponCode)) { model.DiscountUrl = QueryHelpers.AddQueryString(_webHelper.GetStoreLocation().TrimEnd('/'), NopDiscountDefaults.DiscountCouponQueryParameter, model.CouponCode); } //set default values for the new model if (discount == null) { model.LimitationTimes = 1; } return(model); }