本文整理汇总了C#中OrderInfo.SetCouponCode方法的典型用法代码示例。如果您正苦于以下问题:C# OrderInfo.SetCouponCode方法的具体用法?C# OrderInfo.SetCouponCode怎么用?C# OrderInfo.SetCouponCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderInfo
的用法示例。
在下文中一共展示了OrderInfo.SetCouponCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCoupon
public CouponCodeResult AddCoupon(OrderInfo order, string couponCode)
{
if (ChangeOrderToIncompleteAndReturnTrueIfNotAllowed(order))
return CouponCodeResult.NotPermitted;
if (string.IsNullOrEmpty(couponCode))
{
return CouponCodeResult.Failed;
}
if (order.CouponCodes.Contains(couponCode))
{
return CouponCodeResult.AlreadyUsed;
}
// todo: services
var orderDiscountService = IO.Container.Resolve<IOrderDiscountService>();
var discounts = IO.Container.Resolve<ICouponCodeService>().GetAllWithCouponcode(couponCode).Where(coupon => coupon.NumberAvailable > 0)
.Select(coupon => orderDiscountService.GetById(coupon.DiscountId, order.Localization ?? StoreHelper.CurrentLocalization)).Where(c => c != null).ToList();
var couponOrderDiscount = orderDiscountService.GetAll(order.Localization).FirstOrDefault(x => x.CouponCode == couponCode);
if (couponOrderDiscount != null) discounts.Add(couponOrderDiscount);
if (!discounts.Any())
{
return CouponCodeResult.NotFound;
}
var member = Membership.GetUser();
var oncePerCustomer = discounts.All(discount => discount.OncePerCustomer);
if (oncePerCustomer && member != null)
{
var ordersOfMember = OrderHelper.GetOrdersForCustomer(member.UserName);
foreach (var discount in discounts)
{
if (ordersOfMember.Any(x => x.CouponCodes != null && x.CouponCodes.Contains(couponCode) && (x.Discounts.Any(d => d.OriginalId == discount.Id)) || x.OrderLines.Any(l => l.ProductInfo.DiscountId == discount.Id)))
{
return CouponCodeResult.OncePerCustomer;
}
}
}
if (discounts.All(discount => discount.MinimumOrderAmount.WithVat.ValueInCents > 0) && order.GrandtotalInCents < discounts.Max(d => d.MinimumOrderAmount.WithVat.ValueInCents))
{
return CouponCodeResult.MinimumOrderAmount;
}
if (discounts.All(discount => discount.CounterEnabled && discount.Counter <= 0))
{
return CouponCodeResult.OutOfStock;
}
order.SetCouponCode(couponCode);
return CouponCodeResult.Success;
}