// 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();
        }
        protected void gvOrderCoupons_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Promotion      p = GetCurrentPromotion();
            OrderHasCoupon q = (OrderHasCoupon)GetCurrentQualification(p);

            if (q == null)
            {
                return;
            }
            string coupon = (string)e.Keys[0];

            q.RemoveCoupon(coupon);
            MyPage.MTApp.MarketingServices.Promotions.Update(p);
            LoadOrderHasCouponEditor(q);
        }
        protected void btnAddOrderCoupon_Click(object sender, ImageClickEventArgs e)
        {
            string code = this.OrderCouponField.Text.Trim();

            Promotion      p = GetCurrentPromotion();
            OrderHasCoupon q = (OrderHasCoupon)GetCurrentQualification(p);

            if (q == null)
            {
                return;
            }

            q.AddCoupon(code);
            MyPage.MTApp.MarketingServices.Promotions.Update(p);
            LoadOrderHasCouponEditor(q);
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 5
0
        public void Promotion_CanDiscountAnOrderByCoupon()
        {
            var app = CreateHccAppInMemory();

            // Create a Promotion to Test
            var p = new Promotion();

            p.Mode                = PromotionType.OfferForOrder;
            p.IsEnabled           = true;
            p.Name                = "Discount By Coupon Test";
            p.CustomerDescription = "$20.00 off Test Offer!";
            p.StartDateUtc        = DateTime.UtcNow.AddDays(-1);
            p.EndDateUtc          = DateTime.UtcNow.AddDays(1);
            p.StoreId             = 1;
            p.Id = 0;
            var 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
            var 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");
        }
Ejemplo n.º 6
0
        public void Promotion_CanDiscountShipping()
        {
            var app = CreateHccAppInMemory();

            // Create a Promotion to Test
            var p = new Promotion();

            p.Mode                = PromotionType.OfferForShipping;
            p.IsEnabled           = true;
            p.Name                = "10% Off Shipping Test";
            p.CustomerDescription = "10% Off Shipping Test!";
            p.StartDateUtc        = DateTime.UtcNow.AddDays(-1);
            p.EndDateUtc          = DateTime.UtcNow.AddDays(1);
            p.StoreId             = 1;
            p.Id = 0;
            var q = new OrderHasCoupon();

            q.AddCoupon("COUPON");
            p.AddQualification(q);
            p.AddAction(new OrderShippingAdjustment(AmountTypes.Percent, -10m));
            app.MarketingServices.Promotions.Create(p);

            // Create shipping method
            var method = new ShippingMethod();

            method.Adjustment         = 0m;
            method.AdjustmentType     = ShippingMethodAdjustmentType.Amount;
            method.Bvin               = string.Empty;
            method.Name               = "Test Name";
            method.ShippingProviderId = new FlatRatePerOrder().Id;
            method.Settings           = new FlatRatePerItemSettings {
                Amount = 100
            };
            method.ZoneId = -100;
            app.OrderServices.ShippingMethods.Create(method);
            app.OrderServices.EnsureDefaultZones(app.CurrentStore.Id);

            var prod1 = new Product {
                ProductName = "Sample Product", Sku = "ABC123", SitePrice = 50
            };

            app.CatalogServices.Products.Create(prod1);

            // Create a test Order
            var o = new Order {
                StoreId = app.CurrentStore.Id
            };

            o.ShippingMethodId   = method.Bvin;
            o.ShippingProviderId = method.ShippingProviderId;

            o.Items.Add(prod1.ConvertToLineItem(app, 1));
            app.CalculateOrderAndSave(o);

            Assert.AreEqual(100.00m, o.TotalShippingAfterDiscounts, "Shipping should be $100 before discounts");
            Assert.AreEqual(150.00m, o.TotalGrand, "Grand Total should be $150");

            o.AddCouponCode("COUPON");
            app.CalculateOrderAndSave(o);

            Assert.AreEqual(90.00m, o.TotalShippingAfterDiscounts, "Shipping After Discount should be $90.00");
            Assert.AreEqual(-10m, o.TotalShippingDiscounts, "Discount should be -10");
            Assert.AreEqual(100.00m, o.TotalShippingBeforeDiscounts, "Total Before Discounts Should be $100.00");
            Assert.AreEqual(140.00m, o.TotalGrand, "Grand Total should be $140");
        }