public void LoadQualification(Promotion p, string id)
        {
            if (p == null) return;
            this.itemid.Value = id;
            this.promotionid.Value = p.Id.ToString();

            LoadCorrectEditor();
        }
 private IPromotionAction GetCurrentAction(Promotion p)
 {
     if (p == null) return null;
     string itemId = this.itemid.Value;
     long temp = 0;
     long.TryParse(itemId, out temp);
     IPromotionAction a = p.GetAction(temp);
     return a;
 }
 private IPromotionQualification GetCurrentQualification(Promotion p)
 {
     if (p == null) return null;
     string itemId = this.itemid.Value;
     long temp = 0;
     long.TryParse(itemId, out temp);
     IPromotionQualification q = p.GetQualification(temp);
     return q;
 }
Esempio n. 4
0
        public void CanCreateAPromotion()
        {
            Promotion p = new Promotion();
            PromotionRepository r = PromotionRepository.InstantiateForMemory(new RequestContext());

            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");
        }
Esempio n. 5
0
        public void CanFindPromotionInRepository()
        {
            Promotion p = new Promotion();
            p.Name = "FindMe";
            PromotionRepository r = PromotionRepository.InstantiateForMemory(new RequestContext());

            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");

            Promotion target = r.Find(p.Id);
            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual(p.Name, target.Name, "Name didn't match");
        }
Esempio n. 6
0
        public void ActionsFromXmlTest()
        {
            Promotion expected = new Promotion();
            ProductPriceAdjustment a1 = new ProductPriceAdjustment(AmountTypes.MonetaryAmount, 1.23m);
            expected.AddAction(a1);

            string xml = "<Actions>" + System.Environment.NewLine;
            xml += "  <Action>" + System.Environment.NewLine;
            xml += "    <Id>" + a1.Id.ToString() + "</Id>" + System.Environment.NewLine;
            xml += "    <TypeId>" + a1.TypeId + "</TypeId>" + System.Environment.NewLine;
            xml += "    <Settings>" + System.Environment.NewLine;
            xml += "      <Setting>" + System.Environment.NewLine;
            xml += "        <Key>AdjustmentType</Key>" + System.Environment.NewLine;
            xml += "        <Value>1</Value>" + System.Environment.NewLine;
            xml += "      </Setting>" + System.Environment.NewLine;
            xml += "      <Setting>" + System.Environment.NewLine;
            xml += "        <Key>Amount</Key>" + System.Environment.NewLine;
            xml += "        <Value>1.23</Value>" + System.Environment.NewLine;
            xml += "      </Setting>" + System.Environment.NewLine;
            xml += "    </Settings>" + System.Environment.NewLine;
            xml += "  </Action>" + System.Environment.NewLine;
            xml += "</Actions>";

            Promotion actual = new Promotion();
            actual.ActionsFromXml(xml);

            Assert.AreEqual(expected.Actions.Count, actual.Actions.Count, "Actions count did not match");
            Assert.AreEqual(a1.Amount, ((ProductPriceAdjustment)actual.Actions[0]).Amount, "Amount didn't come through");
            Assert.AreEqual(a1.AdjustmentType, ((ProductPriceAdjustment)actual.Actions[0]).AdjustmentType, "Adjustment Type didn't come through");
            for (int i = 0; i < expected.Actions.Count; i++)
            {
                Assert.AreEqual(expected.Actions[i].Id, actual.Actions[i].Id, "Id didn't match for action index " + i.ToString());
                Assert.AreEqual(expected.Actions[i].Settings.Count, actual.Actions[i].Settings.Count, "Settings Count didn't match for action index " + i.ToString());
                Assert.AreEqual(expected.Actions[i].TypeId, actual.Actions[i].TypeId, "TypeId didn't match for action index " + i.ToString());
            }
        }
Esempio n. 7
0
        public void CanGetExpiredStatus()
        {
            Promotion target = new Promotion();
            target.IsEnabled = true;
            target.StartDateUtc = new DateTime(2010, 09, 1, 0, 0, 0); // Sept 1st, 2010
            target.EndDateUtc = new DateTime(2010, 11, 1, 23, 59, 59); // Nov. 1, 2010

            DateTime currentUtcTime = new DateTime(2010, 11, 2, 0, 0, 0); // Nov. 2nd
            PromotionStatus expected = PromotionStatus.Expired;
            PromotionStatus actual;
            actual = target.GetStatus(currentUtcTime);
            Assert.AreEqual(expected, actual, "Nov 2nd should return Expired status");

            DateTime currentUtcTime2 = new DateTime(2011, 9, 1, 0, 0, 0); // Sept. 1th, 2011
            PromotionStatus expected2 = PromotionStatus.Expired;
            PromotionStatus actual2;
            actual2 = target.GetStatus(currentUtcTime2);
            Assert.AreEqual(expected2, actual2, "Sept 1st should return Expired status");
        }
Esempio n. 8
0
        public void QualificationsFromXmlTest()
        {
            Promotion expected = new Promotion();
            ProductBvin q1 = new ProductBvin("abc123");
            expected.AddQualification(q1);

            string xml = "<Qualifications>" + System.Environment.NewLine;
            xml += "  <Qualification>" + System.Environment.NewLine;
            xml += "    <Id>" + q1.Id.ToString() + "</Id>" + System.Environment.NewLine;
            xml += "    <TypeId>" + q1.TypeId + "</TypeId>" + System.Environment.NewLine;
            xml += "    <ProcessingCost>0</ProcessingCost>" + System.Environment.NewLine;
            xml += "    <Settings>" + System.Environment.NewLine;
            xml += "      <Setting>" + System.Environment.NewLine;
            xml += "        <Key>ProductIds</Key>" + System.Environment.NewLine;
            xml += "        <Value>abc123</Value>" + System.Environment.NewLine;
            xml += "      </Setting>" + System.Environment.NewLine;
            xml += "    </Settings>" + System.Environment.NewLine;
            xml += "  </Qualification>" + System.Environment.NewLine;
            xml += "</Qualifications>";

            Promotion actual = new Promotion();
            actual.QualificationsFromXml(xml);

            Assert.AreEqual(expected.Qualifications.Count, actual.Qualifications.Count, "Qualifications count did not match");
            Assert.AreEqual(q1.CurrentProductIds()[0], ((ProductBvin)actual.Qualifications[0]).CurrentProductIds()[0], "Product bvin didn't come through");
            for (int i = 0; i < expected.Qualifications.Count; i++)
            {
                Assert.AreEqual(expected.Qualifications[i].Id, actual.Qualifications[i].Id, "Id didn't match for qualification index " + i.ToString());
                Assert.AreEqual(expected.Qualifications[i].ProcessingCost, actual.Qualifications[i].ProcessingCost, "Processing Cost didn't match for qualification index " + i.ToString());
                Assert.AreEqual(expected.Qualifications[i].Settings.Count, actual.Qualifications[i].Settings.Count, "Settings Count didn't match for qualification index " + i.ToString());
                Assert.AreEqual(expected.Qualifications[i].TypeId, actual.Qualifications[i].TypeId, "TypeId didn't match for qualification index " + i.ToString());
            }
        }
Esempio n. 9
0
        public void QualificationsToXmlTest()
        {
            Promotion target = new Promotion();
            ProductBvin q1 = new ProductBvin("abc123");
            target.AddQualification(q1);

            string expected = "<Qualifications>" + System.Environment.NewLine;

            expected += "  <Qualification>" + System.Environment.NewLine;
            expected += "    <Id>" + q1.Id.ToString() + "</Id>" + System.Environment.NewLine;
            expected += "    <TypeId>" + q1.TypeId + "</TypeId>" + System.Environment.NewLine;
            expected += "    <ProcessingCost>0</ProcessingCost>" + System.Environment.NewLine;
            expected += "    <Settings>" + System.Environment.NewLine;
            expected += "      <Setting>" + System.Environment.NewLine;
            expected += "        <Key>ProductIds</Key>" + System.Environment.NewLine;
            expected += "        <Value>abc123</Value>" + System.Environment.NewLine;
            expected += "      </Setting>" + System.Environment.NewLine;
            expected += "    </Settings>" + System.Environment.NewLine;
            expected += "  </Qualification>" + System.Environment.NewLine;

            expected += "</Qualifications>";

            string actual;
            actual = target.QualificationsToXml();
            Assert.AreEqual(expected, actual);
        }
Esempio n. 10
0
        public void CanSkipPromotionIfNoProduct()
        {
            Promotion p = new Promotion();
            p.IsEnabled = true;
            p.Name = "Product Sale Test";
            p.StartDateUtc = DateTime.Now.AddDays(-1);
            p.EndDateUtc = DateTime.Now.AddDays(1);
            p.StoreId = 1;
            p.Id = 1;
            Assert.IsTrue(p.AddQualification(new ProductBvin("bvin1234")), "Add Qualification Failed");
            Assert.IsTrue(p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -20m)), "Add Action Failed");

            RequestContext c = new RequestContext();
            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            bool actual = p.ApplyToProduct(app, null, null, null, DateTime.UtcNow);

            Assert.IsFalse(actual, "Promotion should not have applied");
        }
Esempio n. 11
0
        public void CanUpdateNameOfPromotion()
        {
            Promotion p = new Promotion();
            p.Name = "Old";
            PromotionRepository r = PromotionRepository.InstantiateForMemory(new RequestContext());
            r.Create(p);

            string updatedName = "New";
            p.Name = updatedName;
            Assert.IsTrue(r.Update(p), "Update should be true");
            Promotion target = r.Find(p.Id);

            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual("New", target.Name, "Name didn't match");
        }
Esempio n. 12
0
        public void CanPutAProductOnSalePricedByApp()
        {
            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.Sale;
            p.IsEnabled = true;
            p.Name = "Product Sale Test";
            p.CustomerDescription = "$10.00 off Test Sale!";
            p.StartDateUtc = DateTime.Now.AddDays(-1);
            p.EndDateUtc = DateTime.Now.AddDays(1);
            p.StoreId = 1;
            p.Id = 0;
            p.AddQualification(new ProductBvin("bvin1234"));
            p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -10m));
            app.MarketingServices.Promotions.Create(p);

            // Create a test Product
            Catalog.Product prod = new Catalog.Product();
            prod.Bvin = "bvin1234";
            prod.SitePrice = 59.99m;
            prod.StoreId = 1;

            Catalog.UserSpecificPrice actualPrice = app.PriceProduct(prod, null, null);

            Assert.IsNotNull(actualPrice, "Price should not be null");
            Assert.AreEqual(49.99m, actualPrice.PriceWithAdjustments(), "Price should be $49.99");
            Assert.AreEqual(1, actualPrice.DiscountDetails.Count, "Discount Details count should be one");
            Assert.AreEqual(p.CustomerDescription, actualPrice.DiscountDetails[0].Description, "Description should match promotion");
        }
Esempio n. 13
0
        public void CanSaveQualificationsAndActionsInRepository()
        {
            Promotion p = new Promotion();
            p.Name = "FindMe";
            p.AddQualification(new ProductBvin("ABC123"));
            p.AddQualification(new ProductType("TYPE0"));
            p.AddAction(new ProductPriceAdjustment(AmountTypes.Percent, 50));
            PromotionRepository r = PromotionRepository.InstantiateForMemory(new RequestContext());

            Assert.IsTrue(r.Create(p), "Create should be true");
            Assert.IsNotNull(p);
            Assert.IsTrue(p.Id > 0, "Promotion was not assigned an Id number");

            Promotion target = r.Find(p.Id);
            Assert.IsNotNull(target, "Found should not be null");
            Assert.AreEqual(p.Id, target.Id, "Id didn't match");
            Assert.AreEqual(p.StoreId, target.StoreId, "Store ID Didn't Match");
            Assert.AreEqual(p.Name, target.Name, "Name didn't match");

            Assert.AreEqual(p.Qualifications.Count, target.Qualifications.Count, "Qualification count didn't match");
            for (int i = 0; i < p.Qualifications.Count; i++)
            {
                Assert.AreEqual(p.Qualifications[0].Id, target.Qualifications[0].Id, "Id of index " + i.ToString() + " didn't match");
                Assert.AreEqual(p.Qualifications[0].GetType(), target.Qualifications[0].GetType(), "Type of index " + i.ToString() + " didn't match");
            }

            Assert.AreEqual(p.Actions.Count, target.Actions.Count, "Action count didn't match");
            for (int i = 0; i < p.Actions.Count; i++)
            {
                Assert.AreEqual(p.Actions[0].Id, target.Actions[0].Id, "Id of action index " + i.ToString() + " didn't match");
                Assert.AreEqual(p.Actions[0].GetType(), target.Actions[0].GetType(), "Type of action index " + i.ToString() + " didn't match");
            }
        }
Esempio n. 14
0
        protected void btnNew_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            string newType = this.lstNewType.SelectedValue;
            int temp = -1;
            int.TryParse(newType, out temp);

            long newId = 0;

            if (temp >= 0)
            {
                PreDefinedPromotion promo = (PreDefinedPromotion)temp;
                Promotion predefined = MTApp.MarketingServices.GetPredefinedPromotion(promo);
                if (predefined == null) return;
                MTApp.MarketingServices.Promotions.Create(predefined);
                newId = predefined.Id;
            }
            else
            {
                if (temp == -1)
                {
                    Promotion sale = new Promotion();
                    sale.Mode = PromotionType.Sale;
                    sale.Name = "New Custom Sale";
                    MTApp.MarketingServices.Promotions.Create(sale);
                    newId = sale.Id;
                }
                else
                {
                    Promotion offer = new Promotion();
                    offer.Mode = PromotionType.Offer;
                    offer.Name = "New Custom Offer";
                    MTApp.MarketingServices.Promotions.Create(offer);
                    newId = offer.Id;
                }
            }

            string destinationLink = "Promotions_edit.aspx?id=" + newId + "&page=" + currentPage + "&showdisabled="
                             + (this.chkShowDisabled.Checked ? "1" : "0") +
                             "&keyword=" + System.Web.HttpUtility.UrlEncode(keyword);
            Response.Redirect(destinationLink);
        }
        private bool SaveEditor(Promotion p, IPromotionAction a)
        {
            switch (a.TypeId.ToString().ToUpper())
            {
                case PromotionActionBase.TypeIdProductPriceAdjustment:
                    decimal adjustmentTemp = ((ProductPriceAdjustment)a).Amount;
                    decimal parsedAdjustment = 0;
                    if (decimal.TryParse(this.AmountField.Text, out parsedAdjustment))
                    {
                        adjustmentTemp = parsedAdjustment;
                    }
                    ((ProductPriceAdjustment)a).Amount = adjustmentTemp;
                    if (this.lstAdjustmentType.SelectedValue == "1")
                    {
                        ((ProductPriceAdjustment)a).AdjustmentType = AmountTypes.Percent;
                    }
                    else
                    {
                        ((ProductPriceAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                    }
                    return MyPage.MTApp.MarketingServices.Promotions.Update(p);
                case PromotionActionBase.TypeIdOrderTotalAdjustment:
                    decimal adjustmentTemp2 = ((OrderTotalAdjustment)a).Amount;
                    decimal parsedAdjustment2 = 0;
                    if (decimal.TryParse(this.OrderTotalAmountField.Text, out parsedAdjustment2))
                    {
                        adjustmentTemp2 = parsedAdjustment2;
                    }
                    ((OrderTotalAdjustment)a).Amount = adjustmentTemp2;
                    if (this.lstOrderTotalAdjustmentType.SelectedValue == "1")
                    {
                        ((OrderTotalAdjustment)a).AdjustmentType = AmountTypes.Percent;
                    }
                    else
                    {
                        ((OrderTotalAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                    }
                    return MyPage.MTApp.MarketingServices.Promotions.Update(p);
                case PromotionActionBase.TypeIdOrderShippingAdjustment:
                    decimal adjustmentOrderShipping = ((OrderShippingAdjustment)a).Amount;
                    decimal parsedAdjustmentOrderShipping = 0;
                    if (decimal.TryParse(this.OrderShippingAdjustmentAmount.Text, out parsedAdjustmentOrderShipping))
                    {
                        adjustmentOrderShipping = parsedAdjustmentOrderShipping;
                    }
                    ((OrderShippingAdjustment)a).Amount = adjustmentOrderShipping;
                    if (this.lstOrderShippingAdjustmentType.SelectedValue == "1")
                    {
                        ((OrderShippingAdjustment)a).AdjustmentType = AmountTypes.Percent;
                    }
                    else
                    {
                        ((OrderShippingAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                    }
                    return MyPage.MTApp.MarketingServices.Promotions.Update(p);       
            }

            return false;
        }
Esempio n. 16
0
        public void ActionsToXmlTest()
        {
            Promotion target = new Promotion();
            ProductPriceAdjustment a1 = new ProductPriceAdjustment(AmountTypes.MonetaryAmount, 1.23m);
            target.AddAction(a1);

            string expected = "<Actions>" + System.Environment.NewLine;

            expected += "  <Action>" + System.Environment.NewLine;
            expected += "    <Id>" + a1.Id.ToString() + "</Id>" + System.Environment.NewLine;
            expected += "    <TypeId>" + a1.TypeId + "</TypeId>" + System.Environment.NewLine;
            expected += "    <Settings>" + System.Environment.NewLine;
            expected += "      <Setting>" + System.Environment.NewLine;
            expected += "        <Key>AdjustmentType</Key>" + System.Environment.NewLine;
            expected += "        <Value>1</Value>" + System.Environment.NewLine;
            expected += "      </Setting>" + System.Environment.NewLine;
            expected += "      <Setting>" + System.Environment.NewLine;
            expected += "        <Key>Amount</Key>" + System.Environment.NewLine;
            expected += "        <Value>1.23</Value>" + System.Environment.NewLine;
            expected += "      </Setting>" + System.Environment.NewLine;
            expected += "    </Settings>" + System.Environment.NewLine;
            expected += "  </Action>" + System.Environment.NewLine;

            expected += "</Actions>";

            string actual;
            actual = target.ActionsToXml();
            Assert.AreEqual(expected, actual);
        }
Esempio n. 17
0
        public void CanGetDisabledStatus()
        {
            Promotion target = new Promotion();
            target.IsEnabled = false;
            target.StartDateUtc = new DateTime(2010, 09, 1, 0, 0, 0); // Sept 1st, 2010
            target.EndDateUtc = new DateTime(2010, 11, 1, 23, 59, 59); // Nov. 1, 2010

            DateTime currentUtcTime = new DateTime(2010, 9, 15, 23, 59, 59); // Sept. 15th, 11:59:59 pm
            PromotionStatus expected = PromotionStatus.Disabled;
            PromotionStatus actual;
            actual = target.GetStatus(currentUtcTime);
            Assert.AreEqual(expected, actual, "Sept 15th should return disabled");

            DateTime currentUtcTime2 = new DateTime(2009, 9, 1, 0, 0, 0); // Sept. 1th, 2009
            PromotionStatus expected2 = PromotionStatus.Disabled;
            PromotionStatus actual2;
            actual2 = target.GetStatus(currentUtcTime2);
            Assert.AreEqual(expected2, actual2, "Sept 1st from one year ago should return disabled status");

            DateTime currentUtcTime3 = new DateTime(2012, 11, 1, 23, 59, 59); // Sept. 1th, 2012
            PromotionStatus expected3 = PromotionStatus.Disabled;
            PromotionStatus actual3;
            actual3 = target.GetStatus(currentUtcTime3);
            Assert.AreEqual(expected3, actual3, "Nov 1st from 2012 should return disabled status");
        }
Esempio n. 18
0
        public void CanGetActiveStatus()
        {
            Promotion target = new Promotion();
            target.IsEnabled = true;
            target.StartDateUtc = new DateTime(2010, 09, 1, 0, 0, 0); // Sept 1st, 2010
            target.EndDateUtc = new DateTime(2010, 11, 1, 23, 59, 59); // Nov. 1, 2010

            DateTime currentUtcTime = new DateTime(2010,9,15,23,59,59); // Sept. 15th, 11:59:59 pm
            PromotionStatus expected = PromotionStatus.Active;
            PromotionStatus actual;
            actual = target.GetStatus(currentUtcTime);
            Assert.AreEqual(expected, actual, "Sept 15th should return active status");

            DateTime currentUtcTime2 = new DateTime(2010, 9, 1, 0, 0, 0); // Sept. 1th, 2010
            PromotionStatus expected2 = PromotionStatus.Active;
            PromotionStatus actual2;
            actual2 = target.GetStatus(currentUtcTime2);
            Assert.AreEqual(expected2, actual2, "Sept 1st should return active status");

            DateTime currentUtcTime3 = new DateTime(2010, 11, 1, 23, 59, 59); // Sept. 1th, 2010
            PromotionStatus expected3 = PromotionStatus.Active;
            PromotionStatus actual3;
            actual3 = target.GetStatus(currentUtcTime3);
            Assert.AreEqual(expected3, actual3, "Nov 1st should return active status");
        }
Esempio n. 19
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");
        }
        private bool SaveEditor(Promotion p, IPromotionQualification q)
        {
            switch (q.TypeId.ToString().ToUpper())
            {
                case PromotionQualificationBase.TypeIdAnyProduct: // all saved at time of edit, no extra save here
                case PromotionQualificationBase.TypeIdProductBvin:
                case PromotionQualificationBase.TypeIdProductCategory:
                case PromotionQualificationBase.TypeIdProductType:
                case PromotionQualificationBase.TypeIdUserIs:
                case PromotionQualificationBase.TypeIdUserIsInGroup:
                case PromotionQualificationBase.TypeIdOrderHasCoupon:
                case PromotionQualificationBase.TypeIdAnyShippingMethod:
                case PromotionQualificationBase.TypeIdShippingMethodIs:
                case PromotionQualificationBase.TypeIdAnyOrder:
                    return true;
                case PromotionQualificationBase.TypeIdOrderSubTotalIs:
                    decimal ototal = ((OrderSubTotalIs)q).Amount;
                    decimal parsedototal = 0;
                    if (decimal.TryParse(this.OrderSubTotalIsField.Text, out parsedototal))
                    {
                        ototal = parsedototal;
                    }
                    ((OrderSubTotalIs)q).Amount = ototal;
                    return MyPage.MTApp.MarketingServices.Promotions.Update(p);
                case PromotionQualificationBase.TypeIdOrderHasProducts:
                    int qty1 = ((OrderHasProducts)q).Quantity;
                    int parsedqty1 = 1;
                    if (int.TryParse(this.OrderProductQuantityField.Text, out parsedqty1))
                    {
                        qty1 = parsedqty1;
                    }
                    QualificationSetMode setmode = ((OrderHasProducts)q).SetMode;
                    int parsedsetmode = 1;
                    if (int.TryParse(this.lstOrderProductSetMode.SelectedValue, out parsedsetmode))
                    {
                        setmode = (QualificationSetMode)parsedsetmode;
                    }
                    ((OrderHasProducts)q).Quantity = qty1;
                    ((OrderHasProducts)q).SetMode = setmode;
                    return MyPage.MTApp.MarketingServices.Promotions.Update(p);
            }

            return false;
        }
Esempio n. 21
0
        public Promotion GetPredefinedPromotion(PreDefinedPromotion type)
        {
            Promotion p = new Promotion();
            
            switch(type)
            {
                case PreDefinedPromotion.SaleCategories:
                    p.Name = "New Category Sale";
                    p.Mode = PromotionType.Sale;
                    p.AddQualification(new PromotionQualifications.ProductCategory());
                    p.AddAction(new PromotionActions.ProductPriceAdjustment());
                    break;
                case PreDefinedPromotion.SaleProducts:
                    p.Name = "New Product Sale";
                    p.Mode = PromotionType.Sale;
                    p.AddQualification(new PromotionQualifications.ProductBvin());
                    p.AddAction(new PromotionActions.ProductPriceAdjustment());
                    break;
                case PreDefinedPromotion.SaleProductType:
                    p.Name = "New Product Type Sale";
                    p.Mode = PromotionType.Sale;
                    p.AddQualification(new PromotionQualifications.ProductType());
                    p.AddAction(new PromotionActions.ProductPriceAdjustment());
                    break;
                case PreDefinedPromotion.SaleStorewide:
                    p.Name = "New Storewide Sale";
                    p.Mode = PromotionType.Sale;
                    p.AddQualification(new PromotionQualifications.AnyProduct());
                    p.AddAction(new PromotionActions.ProductPriceAdjustment());
                    break;
                case PreDefinedPromotion.SaleUser:
                    p.Name = "New Sale By User";
                    p.Mode = PromotionType.Sale;
                    p.AddQualification(new PromotionQualifications.UserIs());
                    p.AddAction(new PromotionActions.ProductPriceAdjustment());
                    break;
                case PreDefinedPromotion.SaleUserGroup:
                    p.Name = "New Sale By Price Group";
                    p.Mode = PromotionType.Sale;
                    p.AddQualification(new PromotionQualifications.UserIsInGroup());
                    p.AddAction(new PromotionActions.ProductPriceAdjustment());
                    break;
                case PreDefinedPromotion.OrderDiscountCoupon:
                    p.Name = "New Order Discount With Coupon";
                    p.Mode = PromotionType.Offer;
                    p.AddQualification(new PromotionQualifications.OrderHasCoupon());
                    p.AddAction(new PromotionActions.OrderTotalAdjustment());
                    break;
                case PreDefinedPromotion.OrderDiscountUser:
                    p.Name = "New Order Discount by User";
                    p.Mode = PromotionType.Offer;
                    p.AddQualification(new PromotionQualifications.UserIs());
                    p.AddAction(new PromotionActions.OrderTotalAdjustment());
                    break;
                case PreDefinedPromotion.OrderDiscountUserGroup:
                    p.Name = "New Order Discount by Price Group";
                    p.Mode = PromotionType.Offer;
                    p.AddQualification(new PromotionQualifications.UserIsInGroup());
                    p.AddAction(new PromotionActions.OrderTotalAdjustment());
                    break;
                case PreDefinedPromotion.OrderFreeShipping:
                    p.Name = "New Free Shipping Discount";
                    p.Mode = PromotionType.Offer;
                    p.AddQualification(new PromotionQualifications.AnyShippingMethod());
                    p.AddAction(new PromotionActions.OrderShippingAdjustment(AmountTypes.Percent, -100m));
                    break;
                case PreDefinedPromotion.OrderShippingDiscount:
                    p.Name = "New Free Shipping Discount";
                    p.Mode = PromotionType.Offer;
                    p.AddQualification(new PromotionQualifications.AnyShippingMethod());
                    p.AddAction(new PromotionActions.OrderShippingAdjustment(AmountTypes.Percent, 0m));
                    break;
            }

            return p;
        }
Esempio n. 22
0
        public void CanGetUpcomingStatus()
        {
            Promotion target = new Promotion();
            target.IsEnabled = true;
            target.StartDateUtc = new DateTime(2010, 09, 1, 0, 0, 0); // Sept 1st, 2010
            target.EndDateUtc = new DateTime(2010, 11, 1, 23, 59, 59); // Nov. 1, 2010

            DateTime currentUtcTime = new DateTime(2010, 08, 1, 0, 0, 0);
            PromotionStatus expected = PromotionStatus.Upcoming;
            PromotionStatus actual;
            actual = target.GetStatus(currentUtcTime);
            Assert.AreEqual(expected, actual, "Augst 1st should return upcoming status");

            DateTime currentUtcTime2 = new DateTime(2010, 8, 31, 23, 59, 59); // August 31st
            PromotionStatus expected2 = PromotionStatus.Upcoming;
            PromotionStatus actual2;
            actual2 = target.GetStatus(currentUtcTime2);
            Assert.AreEqual(expected2, actual2, "August 31th should return Upcoming status");
        }
Esempio n. 23
0
        private void RenderSingleItem(StringBuilder sb, Promotion p)
        {

            string destinationLink = "Promotions_edit.aspx?id=" + p.Id + "&page=" + currentPage + "&showdisabled=" 
                              + (this.chkShowDisabled.Checked ? "1":"0") +
                              "&keyword=" + System.Web.HttpUtility.UrlEncode(keyword);
            string deleteLink = destinationLink.Replace("_edit", "_delete");

            sb.Append("<tr><td><a href=\"" + destinationLink + "\">" + p.Name + "</a></td>");
            sb.Append("<td><a href=\"" + destinationLink + "\">");
            switch (p.GetStatus(DateTime.UtcNow))
            {
                case PromotionStatus.Active:
                    sb.Append("<span style=\"color:#060\">Active</span>");
                    break;
                case PromotionStatus.Disabled:
                    sb.Append("<span style=\"color:#999\">Disabled</span>");                    
                    break;
                case PromotionStatus.Expired:
                    sb.Append("<span style=\"color:#600\">Expired</span>");                    
                    break;
                case PromotionStatus.Unknown:
                    sb.Append("<span style=\"color:#999;\">Unknown</span>");                    
                    break;
                case PromotionStatus.Upcoming:
                    sb.Append("<span style=\"color:#d4d40e;\">Upcoming</span>");                    
                    break;
            }                    
            sb.Append("</a></td>");
            sb.Append("<td><a href=\"" + destinationLink + "\">" + (p.IsEnabled ? "<span style=\"color:#060\">Yes</span" : "<span style=\"color:#999\">No</span>") + "</a></td>");
            sb.Append("<td><a onclick=\"return window.confirm('Delete this item?');\" href=\"" + deleteLink + "\" class=\"btn\"><b>Delete</b></a></td>");
            sb.Append("<td><a href=\"" + destinationLink + "\" class=\"btn\"><b>Edit</b></a></td></tr>");
        }
Esempio n. 24
0
        public void CanPutAProductOnSale()
        {
            Promotion p = new Promotion();
            p.IsEnabled = true;
            p.Name = "Product Sale Test";
            p.CustomerDescription = "A Customer Discount";
            p.StartDateUtc = DateTime.Now.AddDays(-1);
            p.EndDateUtc = DateTime.Now.AddDays(1);
            p.StoreId = 1;
            p.Id = 1;
            Assert.IsTrue(p.AddQualification(new ProductBvin("bvin1234")), "Add Qualification Failed");
            Assert.IsTrue(p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -20m)), "Add Action Failed");

            Catalog.Product prod = new Catalog.Product();
            prod.Bvin = "bvin1234";
            prod.SitePrice = 59.99m;
            prod.StoreId = 1;

            Catalog.UserSpecificPrice userPrice = new Catalog.UserSpecificPrice(prod, null);

            RequestContext c = new RequestContext();
            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            bool actual = p.ApplyToProduct(app, prod, userPrice, null, DateTime.UtcNow);

            Assert.IsTrue(actual, "Promotion should have applied with return value of true");
            Assert.AreEqual(39.99m, userPrice.PriceWithAdjustments(), "Price should have been reduced by $20.00");
            Assert.AreEqual(p.CustomerDescription, userPrice.DiscountDetails[0].Description, "Description should match promotion");
        }