public void CanDiscountAnOrderByCoupon() { RequestContext c = new RequestContext(); MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c); app.CurrentStore = new Accounts.Store(); app.CurrentStore.Id = 1; // Create a Promotion to Test Promotion p = new Promotion(); p.Mode = PromotionType.Offer; p.IsEnabled = true; p.Name = "Discount By Coupon Test"; p.CustomerDescription = "$20.00 off Test Offer!"; p.StartDateUtc = DateTime.Now.AddDays(-1); p.EndDateUtc = DateTime.Now.AddDays(1); p.StoreId = 1; p.Id = 0; OrderHasCoupon q = new OrderHasCoupon(); q.AddCoupon("COUPON"); p.AddQualification(q); p.AddAction(new OrderTotalAdjustment(AmountTypes.MonetaryAmount, -20m)); app.MarketingServices.Promotions.Create(p); // Create a test Order Order o = new Order(); o.Items.Add(new LineItem() { BasePricePerItem = 59.99m, ProductName = "Sample Product", ProductSku = "ABC123" }); app.CalculateOrderAndSave(o); Assert.AreEqual(59.99m, o.TotalOrderAfterDiscounts, "Order total should be $59.99 before discounts"); o.AddCouponCode("COUPON"); app.CalculateOrderAndSave(o); Assert.AreEqual(39.99m, o.TotalOrderAfterDiscounts, "Order total after discounts should be $39.99"); Assert.AreEqual(-20m, o.TotalOrderDiscounts, "Discount should be -20"); Assert.AreEqual(59.99m, o.TotalOrderBeforeDiscounts, "Order total with coupon but before discount should be $59.99"); }
// Order has Coupon Editor private void LoadOrderHasCouponEditor(OrderHasCoupon q) { List<FriendlyBvinDisplay> displayData = new List<FriendlyBvinDisplay>(); foreach (string coupon in q.CurrentCoupons()) { FriendlyBvinDisplay item = new FriendlyBvinDisplay(); item.bvin = coupon; item.DisplayName = coupon; displayData.Add(item); } this.gvOrderCoupons.DataSource = displayData; this.gvOrderCoupons.DataBind(); }