本文整理汇总了C#中Nop.Core.Domain.Discounts.Discount类的典型用法代码示例。如果您正苦于以下问题:C# Discount类的具体用法?C# Discount怎么用?C# Discount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Discount类属于Nop.Core.Domain.Discounts命名空间,在下文中一共展示了Discount类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetShoppingCartTotal
/// <summary>
/// Gets shopping cart total
/// </summary>
/// <param name="cart">Cart</param>
/// <param name="appliedGiftCards">Applied gift cards</param>
/// <param name="discountAmount">Applied discount amount</param>
/// <param name="appliedDiscount">Applied discount</param>
/// <param name="redeemedRewardPoints">Reward points to redeem</param>
/// <param name="redeemedRewardPointsAmount">Reward points amount in primary store currency to redeem</param>
/// <param name="ignoreRewardPonts">A value indicating whether we should ignore reward points (if enabled and a customer is going to use them)</param>
/// <param name="usePaymentMethodAdditionalFee">A value indicating whether we should use payment method additional fee when calculating order total</param>
/// <returns>Shopping cart total;Null if shopping cart total couldn't be calculated now</returns>
public virtual decimal? GetShoppingCartTotal(IList<ShoppingCartItem> cart,
out decimal discountAmount, out Discount appliedDiscount,
out List<AppliedGiftCard> appliedGiftCards,
out int redeemedRewardPoints, out decimal redeemedRewardPointsAmount,
bool ignoreRewardPonts = false, bool usePaymentMethodAdditionalFee = true)
{
redeemedRewardPoints = 0;
redeemedRewardPointsAmount = decimal.Zero;
var customer = cart.GetCustomer();
string paymentMethodSystemName = "";
if (customer != null)
{
paymentMethodSystemName = customer.GetAttribute<string>(
SystemCustomerAttributeNames.SelectedPaymentMethod,
_genericAttributeService,
_storeContext.CurrentStore.Id);
}
//subtotal without tax
decimal subtotalBase = decimal.Zero;
decimal orderSubTotalDiscountAmount = decimal.Zero;
Discount orderSubTotalAppliedDiscount = null;
decimal subTotalWithoutDiscountBase = decimal.Zero;
decimal subTotalWithDiscountBase = decimal.Zero;
GetShoppingCartSubTotal(cart, false,
out orderSubTotalDiscountAmount, out orderSubTotalAppliedDiscount,
out subTotalWithoutDiscountBase, out subTotalWithDiscountBase);
//subtotal with discount
subtotalBase = subTotalWithDiscountBase;
//shipping without tax
decimal? shoppingCartShipping = GetShoppingCartShippingTotal(cart, false);
//payment method additional fee without tax
decimal paymentMethodAdditionalFeeWithoutTax = decimal.Zero;
if (usePaymentMethodAdditionalFee && !String.IsNullOrEmpty(paymentMethodSystemName))
{
decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(cart, paymentMethodSystemName);
paymentMethodAdditionalFeeWithoutTax = _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee,
false, customer);
}
//tax
decimal shoppingCartTax = GetTaxTotal(cart, usePaymentMethodAdditionalFee);
//order total
decimal resultTemp = decimal.Zero;
resultTemp += subtotalBase;
if (shoppingCartShipping.HasValue)
{
resultTemp += shoppingCartShipping.Value;
}
resultTemp += paymentMethodAdditionalFeeWithoutTax;
resultTemp += shoppingCartTax;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
resultTemp = Math.Round(resultTemp, 2);
#region Order total discount
discountAmount = GetOrderTotalDiscount(customer, resultTemp, out appliedDiscount);
//sub totals with discount
if (resultTemp < discountAmount)
discountAmount = resultTemp;
//reduce subtotal
resultTemp -= discountAmount;
if (resultTemp < decimal.Zero)
resultTemp = decimal.Zero;
if (_shoppingCartSettings.RoundPricesDuringCalculation)
resultTemp = Math.Round(resultTemp, 2);
#endregion
#region Applied gift cards
//.........这里部分代码省略.........
示例2: GetShoppingCartShippingTotal
/// <summary>
/// Gets shopping cart shipping total
/// </summary>
/// <param name="cart">Cart</param>
/// <param name="includingTax">A value indicating whether calculated price should include tax</param>
/// <param name="taxRate">Applied tax rate</param>
/// <param name="appliedDiscount">Applied discount</param>
/// <returns>Shipping total</returns>
public virtual decimal? GetShoppingCartShippingTotal(IList<ShoppingCartItem> cart, bool includingTax,
out decimal taxRate, out Discount appliedDiscount)
{
decimal? shippingTotal = null;
decimal? shippingTotalTaxed = null;
appliedDiscount = null;
taxRate = decimal.Zero;
var customer = cart.GetCustomer();
bool isFreeShipping = IsFreeShipping(cart);
if (isFreeShipping)
return decimal.Zero;
ShippingOption shippingOption = null;
if (customer != null)
shippingOption = customer.GetAttribute<ShippingOption>(SystemCustomerAttributeNames.SelectedShippingOption, _genericAttributeService, _storeContext.CurrentStore.Id);
if (shippingOption != null)
{
//use last shipping option (get from cache)
//adjust shipping rate
shippingTotal = AdjustShippingRate(shippingOption.Rate, cart, out appliedDiscount);
}
else
{
//use fixed rate (if possible)
Address shippingAddress = null;
if (customer != null)
shippingAddress = customer.ShippingAddress;
var shippingRateComputationMethods = _shippingService.LoadActiveShippingRateComputationMethods(_storeContext.CurrentStore.Id);
if (shippingRateComputationMethods == null || shippingRateComputationMethods.Count == 0)
throw new NopException("Shipping rate computation method could not be loaded");
if (shippingRateComputationMethods.Count == 1)
{
var shippingRateComputationMethod = shippingRateComputationMethods[0];
var shippingOptionRequests = _shippingService.CreateShippingOptionRequests(cart, shippingAddress);
decimal? fixedRate = null;
foreach (var shippingOptionRequest in shippingOptionRequests)
{
//calculate fixed rates for each request-package
var fixedRateTmp = shippingRateComputationMethod.GetFixedRate(shippingOptionRequest);
if (fixedRateTmp.HasValue)
{
if (!fixedRate.HasValue)
fixedRate = decimal.Zero;
fixedRate += fixedRateTmp.Value;
}
}
if (fixedRate.HasValue)
{
//adjust shipping rate
shippingTotal = AdjustShippingRate(fixedRate.Value, cart, out appliedDiscount);
}
}
}
if (shippingTotal.HasValue)
{
if (shippingTotal.Value < decimal.Zero)
shippingTotal = decimal.Zero;
//round
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotal = Math.Round(shippingTotal.Value, 2);
shippingTotalTaxed = _taxService.GetShippingPrice(shippingTotal.Value,
includingTax,
customer,
out taxRate);
//round
if (_shoppingCartSettings.RoundPricesDuringCalculation)
shippingTotalTaxed = Math.Round(shippingTotalTaxed.Value, 2);
}
return shippingTotalTaxed;
}
示例3: Can_save_and_load_discount
public void Can_save_and_load_discount()
{
var discount = new Discount
{
DiscountType = DiscountType.AssignedToCategories,
Name = "Discount 1",
UsePercentage = true,
DiscountPercentage = 1.1M,
DiscountAmount = 2.1M,
MaximumDiscountAmount = 3.1M,
StartDateUtc = new DateTime(2010, 01, 01),
EndDateUtc = new DateTime(2010, 01, 02),
RequiresCouponCode = true,
CouponCode = "SecretCode",
DiscountLimitation = DiscountLimitationType.Unlimited,
LimitationTimes = 3,
MaximumDiscountedQuantity = 4,
};
var fromDb = SaveAndLoadEntity(discount);
fromDb.ShouldNotBeNull();
fromDb.DiscountType.ShouldEqual(DiscountType.AssignedToCategories);
fromDb.Name.ShouldEqual("Discount 1");
fromDb.UsePercentage.ShouldEqual(true);
fromDb.DiscountPercentage.ShouldEqual(1.1M);
fromDb.DiscountAmount.ShouldEqual(2.1M);
fromDb.MaximumDiscountAmount.ShouldEqual(3.1M);
fromDb.StartDateUtc.ShouldEqual(new DateTime(2010, 01, 01));
fromDb.EndDateUtc.ShouldEqual(new DateTime(2010, 01, 02));
fromDb.RequiresCouponCode.ShouldEqual(true);
fromDb.CouponCode.ShouldEqual("SecretCode");
fromDb.DiscountLimitation.ShouldEqual(DiscountLimitationType.Unlimited);
fromDb.LimitationTimes.ShouldEqual(3);
fromDb.MaximumDiscountedQuantity.ShouldEqual(4);
}
示例4: CheckDiscountLimitations
/// <summary>
/// Checks discount limitation for customer
/// </summary>
/// <param name="discount">Discount</param>
/// <param name="customer">Customer</param>
/// <returns>Value indicating whether discount can be used</returns>
protected virtual bool CheckDiscountLimitations(Discount discount, Customer customer)
{
if (discount == null)
throw new ArgumentNullException("discount");
switch (discount.DiscountLimitation)
{
case DiscountLimitationType.Unlimited:
{
return true;
}
case DiscountLimitationType.NTimesOnly:
{
var totalDuh = GetAllDiscountUsageHistory(discount.Id, null, 0, 1).TotalCount;
return totalDuh < discount.LimitationTimes;
}
case DiscountLimitationType.NTimesPerCustomer:
{
if (customer != null && !customer.IsGuest())
{
//registered customer
var totalDuh = GetAllDiscountUsageHistory(discount.Id, customer.Id, 0, 1).TotalCount;
return totalDuh < discount.LimitationTimes;
}
else
{
//guest
return true;
}
}
default:
break;
}
return false;
}
示例5: Can_save_and_load_discount_with_discountRequirements
public void Can_save_and_load_discount_with_discountRequirements()
{
var discount = new Discount
{
Name = "Discount 1",
DiscountType = DiscountType.AssignedToCategories,
UsePercentage = true,
DiscountPercentage = 1,
DiscountAmount = 2,
StartDateUtc = new DateTime(2010, 01, 01),
EndDateUtc = new DateTime(2010, 01, 02),
RequiresCouponCode = true,
CouponCode = "SecretCode",
DiscountLimitation = DiscountLimitationType.Unlimited,
LimitationTimes = 3
};
discount.DiscountRequirements.Add
(
new DiscountRequirement()
{
DiscountRequirementRuleSystemName = "BillingCountryIs"
}
);
var fromDb = SaveAndLoadEntity(discount);
fromDb.ShouldNotBeNull();
fromDb.Name.ShouldEqual("Discount 1");
fromDb.DiscountRequirements.ShouldNotBeNull();
(fromDb.DiscountRequirements.Count == 1).ShouldBeTrue();
fromDb.DiscountRequirements.First().DiscountRequirementRuleSystemName.ShouldEqual("BillingCountryIs");
}
示例6: Can_validate_discount_dateRange
public void Can_validate_discount_dateRange()
{
var discount = new Discount
{
DiscountType = DiscountType.AssignedToSkus,
Name = "Discount 2",
UsePercentage = false,
DiscountPercentage = 0,
DiscountAmount = 5,
StartDateUtc = DateTime.UtcNow.AddDays(-1),
EndDateUtc = DateTime.UtcNow.AddDays(1),
RequiresCouponCode = false,
DiscountLimitation = DiscountLimitationType.Unlimited,
};
var customer = new Customer
{
CustomerGuid = Guid.NewGuid(),
AdminComment = "",
Active = true,
Deleted = false,
CreatedOnUtc = new DateTime(2010, 01, 01),
LastActivityDateUtc = new DateTime(2010, 01, 02)
};
var result1 = _discountService.IsDiscountValid(discount, customer);
result1.ShouldEqual(true);
discount.StartDateUtc = DateTime.UtcNow.AddDays(1);
var result2 = _discountService.IsDiscountValid(discount, customer);
result2.ShouldEqual(false);
}
示例7: PrepareDiscountModel
protected virtual void PrepareDiscountModel(DiscountModel model, Discount discount)
{
if (model == null)
throw new ArgumentNullException("model");
model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
model.AvailableDiscountRequirementRules.Add(new SelectListItem() { Text = _localizationService.GetResource("Admin.Promotions.Discounts.Requirements.DiscountRequirementType.Select"), Value = "" });
var discountRules = _discountService.LoadAllDiscountRequirementRules();
foreach (var discountRule in discountRules)
model.AvailableDiscountRequirementRules.Add(new SelectListItem() { Text = discountRule.PluginDescriptor.FriendlyName, Value = discountRule.PluginDescriptor.SystemName });
if (discount != null)
{
//applied to categories
foreach (var category in discount.AppliedToCategories)
{
if (category != null && !category.Deleted)
{
model.AppliedToCategoryModels.Add(new DiscountModel.AppliedToCategoryModel()
{
CategoryId = category.Id,
Name = category.Name
});
}
}
//applied to product variants
foreach (var product in discount.AppliedToProducts)
{
if (product != null && !product.Deleted)
{
var appliedToProductModel = new DiscountModel.AppliedToProductModel()
{
ProductId = product.Id,
ProductName = product.Name
};
model.AppliedToProductModels.Add(appliedToProductModel);
}
}
//requirements
foreach (var dr in discount.DiscountRequirements.OrderBy(dr=>dr.Id))
{
var drr = _discountService.LoadDiscountRequirementRuleBySystemName(dr.DiscountRequirementRuleSystemName);
if (drr != null)
{
model.DiscountRequirementMetaInfos.Add(new DiscountModel.DiscountRequirementMetaInfo()
{
DiscountRequirementId = dr.Id,
RuleName = drr.PluginDescriptor.FriendlyName,
ConfigurationUrl = GetRequirementUrlInternal(drr, discount, dr.Id)
});
}
}
}
}
示例8: GetRequirementUrlInternal
protected virtual string GetRequirementUrlInternal(IDiscountRequirementRule discountRequirementRule, Discount discount, int? discountRequirementId)
{
if (discountRequirementRule == null)
throw new ArgumentNullException("discountRequirementRule");
if (discount == null)
throw new ArgumentNullException("discount");
string url = string.Format("{0}{1}", _webHelper.GetStoreLocation(), discountRequirementRule.GetConfigurationUrl(discount.Id, discountRequirementId));
return url;
}
示例9: DeleteDiscount
/// <summary>
/// Delete discount
/// </summary>
/// <param name="discount">Discount</param>
public virtual void DeleteDiscount(Discount discount)
{
if (discount == null)
throw new ArgumentNullException("discount");
_discountRepository.Delete(discount);
_cacheManager.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
//event notification
_eventPublisher.EntityDeleted(discount);
}
示例10: Can_calculate_discount_amount_fixed
public void Can_calculate_discount_amount_fixed()
{
var discount = new Discount()
{
UsePercentage = false,
DiscountAmount = 10
};
discount.GetDiscountAmount(100).ShouldEqual(10);
discount.DiscountAmount = 20;
discount.GetDiscountAmount(200).ShouldEqual(20);
}
示例11: Can_calculate_discount_amount_percentage
public void Can_calculate_discount_amount_percentage()
{
var discount = new Discount()
{
UsePercentage = true,
DiscountPercentage= 30
};
discount.GetDiscountAmount(100).ShouldEqual(30);
discount.DiscountPercentage = 60;
discount.GetDiscountAmount(200).ShouldEqual(120);
}
示例12: ContainsDiscount
public static bool ContainsDiscount(this IList<Discount> discounts,
Discount discount)
{
if (discounts == null)
throw new ArgumentNullException("discounts");
if (discount == null)
throw new ArgumentNullException("discount");
foreach (var dis1 in discounts)
if (discount.Id == dis1.Id)
return true;
return false;
}
示例13: SetUp
public new void SetUp()
{
_discountRepo = MockRepository.GenerateMock<IRepository<Discount>>();
var discount1 = new Discount
{
Id = 1,
DiscountType = DiscountType.AssignedToCategories,
Name = "Discount 1",
UsePercentage = true,
DiscountPercentage = 10,
DiscountAmount =0,
DiscountLimitation = DiscountLimitationType.Unlimited,
LimitationTimes = 0,
};
var discount2 = new Discount
{
Id = 2,
DiscountType = DiscountType.AssignedToSkus,
Name = "Discount 2",
UsePercentage = false,
DiscountPercentage = 0,
DiscountAmount = 5,
RequiresCouponCode = true,
CouponCode = "SecretCode",
DiscountLimitation = DiscountLimitationType.NTimesPerCustomer,
LimitationTimes = 3,
};
_discountRepo.Expect(x => x.Table).Return(new List<Discount> { discount1, discount2 }.AsQueryable());
_eventPublisher = MockRepository.GenerateMock<IEventPublisher>();
_eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything));
_storeContext = MockRepository.GenerateMock<IStoreContext>();
var cacheManager = new NopNullCache();
_discountRequirementRepo = MockRepository.GenerateMock<IRepository<DiscountRequirement>>();
_discountUsageHistoryRepo = MockRepository.GenerateMock<IRepository<DiscountUsageHistory>>();
var pluginFinder = new PluginFinder();
_genericAttributeService = MockRepository.GenerateMock<IGenericAttributeService>();
_localizationService = MockRepository.GenerateMock<ILocalizationService>();
_discountService = new DiscountService(cacheManager, _discountRepo, _discountRequirementRepo,
_discountUsageHistoryRepo, _storeContext, _genericAttributeService,
_localizationService, pluginFinder, _eventPublisher);
}
示例14: Maximum_discount_amount_is_used
public void Maximum_discount_amount_is_used()
{
var discount = new Discount
{
UsePercentage = true,
DiscountPercentage = 30,
MaximumDiscountAmount = 3.4M
};
discount.GetDiscountAmount(100).ShouldEqual(3.4M);
discount.DiscountPercentage = 60;
discount.GetDiscountAmount(200).ShouldEqual(3.4M);
discount.GetDiscountAmount(100).ShouldEqual(3.4M);
discount.DiscountPercentage = 1;
discount.GetDiscountAmount(200).ShouldEqual(2);
}
示例15: Can_save_and_load_discount_with_appliedCategories
public void Can_save_and_load_discount_with_appliedCategories()
{
var discount = new Discount
{
Name = "Discount 1",
DiscountType = DiscountType.AssignedToCategories,
UsePercentage = true,
DiscountPercentage = 1,
DiscountAmount = 2,
StartDateUtc = new DateTime(2010, 01, 01),
EndDateUtc = new DateTime(2010, 01, 02),
RequiresCouponCode = true,
CouponCode = "SecretCode",
DiscountLimitation = DiscountLimitationType.Unlimited,
LimitationTimes = 3
};
discount.AppliedToCategories.Add(GetTestCategory());
var fromDb = SaveAndLoadEntity(discount);
fromDb.ShouldNotBeNull();
fromDb.AppliedToCategories.ShouldNotBeNull();
(fromDb.AppliedToCategories.Count == 1).ShouldBeTrue();
fromDb.AppliedToCategories.First().Name.ShouldEqual("Books");
}