public void OrderCalculator_TestBugWithGiftcardDiscounts_13878()
        {
            //InitBasicStubs();
            var app = CreateHccAppInMemory();

            // Prepare products
            var catA = new Category {
                Name = "Category A"
            };
            var catB = new Category {
                Name = "Category B"
            };
            var prod1 = new Product {
                ProductName = "Gift Card", SitePrice = 100, IsGiftCard = true
            };
            var prod2 = new Product {
                ProductName = "Product 2", SitePrice = 50
            };

            app.CatalogServices.Categories.Create(catA);
            app.CatalogServices.Categories.Create(catB);
            app.CatalogServices.Products.Create(prod1);
            app.CatalogServices.Products.Create(prod2);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod1.Bvin, catA.Bvin);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod2.Bvin, catB.Bvin);

            // Prepare promotion
            var orderTotalDiscount = new Promotion {
                Mode = PromotionType.OfferForOrder, Name = "-50%", IsEnabled = true
            };

            orderTotalDiscount.AddQualification(new AnyOrder());
            orderTotalDiscount.AddAction(new OrderTotalAdjustment(AmountTypes.Percent, -50));
            orderTotalDiscount.AddAction(new OrderTotalAdjustment(AmountTypes.MonetaryAmount, -100));
            app.MarketingServices.Promotions.Create(orderTotalDiscount);

            var o = new Order {
                StoreId = app.CurrentStore.Id
            };
            var li1 = prod1.ConvertToLineItem(app, 1);
            var li2 = prod2.ConvertToLineItem(app, 1);

            o.Items.Add(li1);
            o.Items.Add(li2);

            app.CalculateOrder(o);

            Assert.AreEqual(100m, li1.LineTotal);
            Assert.AreEqual(50m, li2.LineTotal);

            Assert.AreEqual(-25m, o.OrderDiscountDetails[0].Amount);
            Assert.AreEqual(-100m, o.OrderDiscountDetails[1].Amount);

            Assert.AreEqual(150m, o.TotalOrderBeforeDiscounts);
            Assert.AreEqual(100m, o.TotalOrderAfterDiscounts);
            Assert.AreEqual(100m, o.TotalGrand);
        }
Ejemplo n.º 2
0
        public void Promotion_CanPutAProductOnSale()
        {
            //InitBasicStubs();
            var app = CreateHccAppInMemory();

            var p = new Promotion();

            p.IsEnabled           = true;
            p.Name                = "Product Sale Test";
            p.CustomerDescription = "A Customer Discount";
            p.StartDateUtc        = DateTime.UtcNow.AddDays(-1);
            p.EndDateUtc          = DateTime.UtcNow.AddDays(1);
            p.StoreId             = 1;
            p.Id = 1;

            var prod = new Product();

            prod.Bvin      = "553690e2-6372-431f-97c0-83e11a05f298";
            prod.SitePrice = 59.99m;
            app.CatalogServices.Products.Create(prod);

            Assert.IsTrue(p.AddQualification(new ProductBvin(prod.Bvin)), "Add Qualification Failed");
            Assert.IsTrue(p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -20m)), "Add Action Failed");


            var userPrice = new UserSpecificPrice(prod, null, app.CurrentStore.Settings);


            var actual = p.ApplyToProduct(app.CurrentRequestContext, prod, userPrice, null);

            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");
        }
Ejemplo n.º 3
0
        public void Promotion_ActionsToXmlTest()
        {
            var target = new Promotion();
            var a1     = new ProductPriceAdjustment(AmountTypes.MonetaryAmount, 1.23m);

            target.AddAction(a1);

            var expected = "<Actions>" + Environment.NewLine;

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

            expected += "</Actions>";

            string actual;

            actual = target.ActionsToXml();
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
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");
        }
Ejemplo n.º 5
0
        public void Promotion_CanPutAProductOnSalePricedByApp()
        {
            //InitBasicStubs();
            var app = CreateHccAppInMemory();

            // Create a Promotion to Test
            var 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.UtcNow.AddDays(-1);
            p.EndDateUtc          = DateTime.UtcNow.AddDays(1);
            p.StoreId             = 1;
            p.Id = 0;
            p.AddQualification(new ProductBvin("b991f9de-2bf2-4472-a913-bfaa08e230cf"));
            p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -10m));
            app.MarketingServices.Promotions.Create(p);

            // Create a test Product
            var prod = new Product();

            prod.Bvin      = "b991f9de-2bf2-4472-a913-bfaa08e230cf";
            prod.SitePrice = 59.99m;
            prod.StoreId   = 1;

            var actualPrice = app.PriceProduct(prod, null, null, app.CurrentlyActiveSales);

            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");
        }
Ejemplo n.º 6
0
        public void Promotion_TestLineItemFreeShipping()
        {
            var app = CreateHccAppInMemory();

            // Prepare products
            var catA = new Category {
                Name = "Category A"
            };
            var catB = new Category {
                Name = "Category B"
            };
            var prod1 = new Product {
                ProductName = "Product 1", SitePrice = 100
            };
            var prod2 = new Product {
                ProductName = "Product 2", SitePrice = 50
            };

            app.CatalogServices.Categories.Create(catA);
            app.CatalogServices.Categories.Create(catB);
            app.CatalogServices.Products.Create(prod1);
            app.CatalogServices.Products.Create(prod2);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod1.Bvin, catA.Bvin);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod2.Bvin, catB.Bvin);

            // Prepare promotion
            var promFreeShipping = new Promotion
            {
                Mode      = PromotionType.OfferForLineItems,
                Name      = "FREE SHIPPING",
                IsEnabled = true
            };

            promFreeShipping.AddQualification(new LineItemCategory(catA.Bvin));
            promFreeShipping.AddAction(new LineItemFreeShipping());
            app.MarketingServices.Promotions.Create(promFreeShipping);

            var o = new Order {
                StoreId = app.CurrentStore.Id
            };
            var li1 = prod1.ConvertToLineItem(app, 1);
            var li2 = prod2.ConvertToLineItem(app, 1);

            o.Items.Add(li1);
            o.Items.Add(li2);

            app.CalculateOrder(o);

            Assert.IsTrue(li1.IsMarkedForFreeShipping);
            Assert.IsFalse(li2.IsMarkedForFreeShipping);
        }
        protected void btnNewAction_Click(object sender, ImageClickEventArgs e)
        {
            Promotion p = GetCurrentPromotion();

            if (p == null)
            {
                return;
            }

            string newid           = this.lstNewAction.SelectedValue;
            PromotionActionBase pa = PromotionActionBase.Factory(newid);

            p.AddAction(pa);

            MTApp.MarketingServices.Promotions.Update(p);
            LoadItem();
        }
Ejemplo n.º 8
0
        public void Promotion_TestLineItemIsProduct()
        {
            var app = CreateHccAppInMemory();

            // Prepare products
            var prod1 = new Product {
                ProductName = "Product 1", SitePrice = 100
            };
            var prod2 = new Product {
                ProductName = "Product 2", SitePrice = 50
            };

            app.CatalogServices.Products.Create(prod1);
            app.CatalogServices.Products.Create(prod2);

            // Prepare promotion
            var prom = new Promotion
            {
                Mode      = PromotionType.OfferForLineItems,
                Name      = "SPECIAL PRODUCTS",
                IsEnabled = true
            };
            var qIsProduct = new LineItemIsProduct();

            qIsProduct.AddProductIds(new List <string> {
                prod1.Bvin
            });
            prom.AddQualification(qIsProduct);
            prom.AddAction(new LineItemFreeShipping());

            var o = new Order {
                StoreId = app.CurrentStore.Id
            };
            var li1 = prod1.ConvertToLineItem(app, 1);
            var li2 = prod2.ConvertToLineItem(app, 1);

            o.Items.Add(li1);
            o.Items.Add(li2);


            prom.ApplyToOrder(app.CurrentRequestContext, o);

            Assert.IsTrue(li1.IsMarkedForFreeShipping);
            Assert.IsFalse(li2.IsMarkedForFreeShipping);
        }
Ejemplo n.º 9
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.º 10
0
        public void Promotion_CanSaveQualificationsAndActionsInRepository()
        {
            var app = CreateHccAppInMemory();

            var p = new Promotion {
                Mode = PromotionType.Sale, Name = "FindMe"
            };

            p.AddQualification(new ProductBvin(new List <string> {
                "ABC123"
            }));
            p.AddQualification(new ProductType("TYPE0"));
            p.AddAction(new ProductPriceAdjustment(AmountTypes.Percent, 50));
            var r = new PromotionRepository(new HccRequestContext());


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

            var 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 (var i = 0; i < p.Qualifications.Count; i++)
            {
                Assert.AreEqual(p.Qualifications[0].Id, target.Qualifications[0].Id,
                                "Id of index " + i + " didn't match");
                Assert.AreEqual(p.Qualifications[0].GetType(), target.Qualifications[0].GetType(),
                                "Type of index " + i + " didn't match");
            }

            Assert.AreEqual(p.Actions.Count, target.Actions.Count, "Action count didn't match");
            for (var i = 0; i < p.Actions.Count; i++)
            {
                Assert.AreEqual(p.Actions[0].Id, target.Actions[0].Id, "Id of action index " + i + " didn't match");
                Assert.AreEqual(p.Actions[0].GetType(), target.Actions[0].GetType(),
                                "Type of action index " + i + " didn't match");
            }
        }
Ejemplo n.º 11
0
        public void Promotion_ActionsFromXmlTest()
        {
            var expected = new Promotion();
            var a1       = new ProductPriceAdjustment(AmountTypes.MonetaryAmount, 1.23m);

            expected.AddAction(a1);

            var xml = "<Actions>" + Environment.NewLine;

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

            var 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 (var 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);
                Assert.AreEqual(expected.Actions[i].Settings.Count, actual.Actions[i].Settings.Count,
                                "Settings Count didn't match for action index " + i);
                Assert.AreEqual(expected.Actions[i].TypeId, actual.Actions[i].TypeId,
                                "TypeId didn't match for action index " + i);
            }
        }
Ejemplo n.º 12
0
        public void Promotion_CanSkipPromotionIfNoProduct()
        {
            var app = CreateHccAppInMemory();

            var p = new Promotion();

            p.IsEnabled    = true;
            p.Name         = "Product Sale Test";
            p.StartDateUtc = DateTime.UtcNow.AddDays(-1);
            p.EndDateUtc   = DateTime.UtcNow.AddDays(1);
            p.StoreId      = 1;
            p.Id           = 1;
            Assert.IsTrue(p.AddQualification(new ProductBvin("b991f9de-2bf2-4472-a913-bfaa08e230cf")),
                          "Add Qualification Failed");
            Assert.IsTrue(p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -20m)), "Add Action Failed");

            var actual = p.ApplyToProduct(app.CurrentRequestContext, null, null, null);

            Assert.IsFalse(actual, "Promotion should not have applied");
        }
Ejemplo n.º 13
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");
        }
Ejemplo n.º 14
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.º 15
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");
        }
Ejemplo n.º 16
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");
            }
        }
Ejemplo n.º 17
0
        public void Promotion_TestSumOfProductsWithinCategories()
        {
            var app = CreateHccAppInMemory();

            // Prepare products
            var prod1 = new Product {
                ProductName = "Product 1", SitePrice = 100
            };
            var prod2 = new Product {
                ProductName = "Product 2", SitePrice = 50
            };
            var prod3 = new Product {
                ProductName = "Product 3", SitePrice = 30
            };

            app.CatalogServices.Products.Create(prod1);
            app.CatalogServices.Products.Create(prod2);
            app.CatalogServices.Products.Create(prod3);

            var catA = new Category {
                Name = "CatA"
            };
            var catB = new Category {
                Name = "CatB"
            };

            app.CatalogServices.Categories.Create(catA);
            app.CatalogServices.Categories.Create(catB);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod1.Bvin, catA.Bvin);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod2.Bvin, catA.Bvin);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod3.Bvin, catB.Bvin);

            // Prepare promotion
            var prom = new Promotion {
                Mode = PromotionType.OfferForOrder, Name = "SPECIAL PRODUCTS", IsEnabled = true
            };
            var qIsProduct = new SumOrCountOfProducts();

            qIsProduct.AddCategoryId(catA.Bvin);
            qIsProduct.SumAmount = 149;
            prom.AddQualification(qIsProduct);
            prom.AddAction(new OrderTotalAdjustment(AmountTypes.MonetaryAmount, -10));

            var o = new Order {
                StoreId = app.CurrentStore.Id
            };
            var li1 = prod1.ConvertToLineItem(app, 1);
            var li2 = prod2.ConvertToLineItem(app, 1);
            var li3 = prod3.ConvertToLineItem(app, 1);

            o.Items.Add(li1);
            o.Items.Add(li2);
            o.Items.Add(li3);

            app.CalculateOrder(o);

            Assert.AreEqual(180m, o.TotalGrand);

            prom.ApplyToOrder(app.CurrentRequestContext, o);

            Assert.AreEqual(170m, o.TotalGrand);
        }
Ejemplo n.º 18
0
        public void Promotion_MigrateOldPromotions()
        {
#pragma warning disable 0612, 0618
            var app = CreateHccAppInMemory();

            // Add Sale promo
            var sale = new Promotion {
                Mode = PromotionType.Sale, Name = "SALE"
            };
            sale.AddAction(new ProductPriceAdjustment());
            app.MarketingServices.Promotions.Create(sale);

            // Add Empty Offer
            var offer = new Promotion {
                Mode = PromotionType.Offer, Name = "OFFER"
            };
            app.MarketingServices.Promotions.Create(offer);

            // Add Candidate to split
            var offer2s = new Promotion {
                Mode = PromotionType.Offer, Name = "Should Be Splitted"
            };
            // 2 qualifications
            offer2s.AddQualification(new AnyOrder());
            offer2s.AddQualification(new AnyProduct());
            // 5 actions
            offer2s.AddAction(new LineItemAdjustment());
            offer2s.AddAction(new LineItemFreeShipping());
            offer2s.AddAction(new OrderShippingAdjustment());
            offer2s.AddAction(new OrderTotalAdjustment());
            offer2s.AddAction(new OrderTotalAdjustment());
            app.MarketingServices.Promotions.Create(offer2s);

            var total = 0;
            app.MarketingServices.Promotions.FindAllWithFilter(PromotionType.Offer, "", true, 1, int.MaxValue, ref total);
            Assert.AreEqual(2, total);

            app.MarketingServices.MigrateOldPromotions();

            var proms = app.MarketingServices.Promotions.FindAllPaged(1, int.MaxValue);
            Assert.AreEqual(0, proms.Where(p => p.Mode == PromotionType.Offer).Count(),
                            "All 'Offer' promotions should be migrated to other modes");
            Assert.AreEqual(5, proms.Where(p => p.Mode != PromotionType.Offer).Count());
            Assert.AreEqual(1, proms.Where(p => p.Mode == PromotionType.Sale).Count());

            Assert.AreEqual(1, proms.Where(p => p.Mode == PromotionType.OfferForLineItems).Count());
            Assert.AreEqual(1, proms.Where(p => p.Mode == PromotionType.OfferForShipping).Count());
            Assert.AreEqual(2, proms.Where(p => p.Mode == PromotionType.OfferForOrder).Count());

            var pLi = proms.FirstOrDefault(p => p.Mode == PromotionType.OfferForLineItems);
            var pSh = proms.FirstOrDefault(p => p.Mode == PromotionType.OfferForShipping);
            var pO  = proms.FirstOrDefault(p => p.Mode == PromotionType.OfferForOrder && p.Name == "Should Be Splitted");

            Assert.AreEqual(2, pLi.Actions.Count);
            Assert.AreEqual(2, pLi.Qualifications.Count);
            Assert.AreEqual(1, pSh.Actions.Count);
            Assert.AreEqual(2, pSh.Qualifications.Count);
            Assert.AreEqual(2, pO.Actions.Count);
            Assert.AreEqual(2, pO.Qualifications.Count);

            Assert.AreEqual(typeof(OrderTotalAdjustment), pO.Actions[0].GetType());
            Assert.AreEqual(typeof(OrderTotalAdjustment), pO.Actions[1].GetType());
            Assert.AreEqual(typeof(AnyOrder), pO.Qualifications[0].GetType());
            Assert.AreEqual(typeof(AnyProduct), pO.Qualifications[1].GetType());
#pragma warning restore 0612, 0618
        }
Ejemplo n.º 19
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");
        }
        public void OrderCalculator_TestBugWithFreeShipping_12738()
        {
            //InitBasicStubs();
            var app = CreateHccAppInMemory();

            // Create taxes
            var tax1 = new TaxSchedule {
                Name = "Tax1"
            };
            var tax2 = new TaxSchedule {
                Name = "Tax2"
            };

            app.OrderServices.TaxSchedules.Create(tax1);
            app.OrderServices.TaxSchedules.Create(tax2);
            var taxrate1 = new Tax
            {
                Rate             = 10,
                ShippingRate     = 5,
                CountryIsoAlpha3 = "USA",
                ApplyToShipping  = true,
                TaxScheduleId    = tax1.Id
            };
            var taxrate2 = new Tax
            {
                Rate             = 10,
                ShippingRate     = 10,
                CountryIsoAlpha3 = "USA",
                ApplyToShipping  = true,
                TaxScheduleId    = tax2.Id
            };

            app.OrderServices.Taxes.Create(taxrate1);
            app.OrderServices.Taxes.Create(taxrate2);

            // Prepare products
            var catA = new Category {
                Name = "Category A"
            };
            var catB = new Category {
                Name = "Category B"
            };
            var prod1 = new Product {
                ProductName = "Product 1", SitePrice = 100, TaxSchedule = tax1.Id
            };
            var prod2 = new Product {
                ProductName = "Product 2", SitePrice = 50, TaxSchedule = tax2.Id
            };

            app.CatalogServices.Categories.Create(catA);
            app.CatalogServices.Categories.Create(catB);
            app.CatalogServices.Products.Create(prod1);
            app.CatalogServices.Products.Create(prod2);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod1.Bvin, catA.Bvin);
            app.CatalogServices.CategoriesXProducts.AddProductToCategory(prod2.Bvin, catB.Bvin);

            // Prepare promotion
            var promFreeShipping = new Promotion
            {
                Mode      = PromotionType.OfferForLineItems,
                Name      = "FREE SHIPPING",
                IsEnabled = true
            };

            promFreeShipping.AddQualification(new LineItemCategory(catA.Bvin));
            promFreeShipping.AddAction(new LineItemFreeShipping());
            app.MarketingServices.Promotions.Create(promFreeShipping);

            var o = new Order {
                StoreId = app.CurrentStore.Id
            };
            var li1 = prod1.ConvertToLineItem(app, 1);
            var li2 = prod2.ConvertToLineItem(app, 1);

            o.Items.Add(li1);
            o.Items.Add(li2);

            // Create Shipping Method
            var sm = new ShippingMethod();

            var flatRatePerOrder = new FlatRatePerOrder();

            flatRatePerOrder.Settings.Amount = 2m;

            sm.Bvin = Guid.NewGuid().ToString();
            sm.ShippingProviderId = flatRatePerOrder.Id;
            sm.Settings           = flatRatePerOrder.Settings;
            sm.Adjustment         = 0m;
            sm.Name   = "Flat Rate Per Item";
            sm.ZoneId = -100; // US All Zone
            app.OrderServices.ShippingMethods.Create(sm);
            app.OrderServices.EnsureDefaultZones(app.CurrentStore.Id);

            o.ShippingAddress.City        = "Richmond";
            o.ShippingAddress.CountryBvin = Country.UnitedStatesCountryBvin;
            o.ShippingAddress.Line1       = "124 Anywhere St.";
            o.ShippingAddress.PostalCode  = "23233";
            o.ShippingAddress.RegionBvin  = "VA";
            o.ShippingMethodId            = sm.Bvin;
            o.ShippingProviderId          = sm.ShippingProviderId;

            app.CalculateOrder(o);

            Assert.IsTrue(li1.IsMarkedForFreeShipping);
            Assert.IsFalse(li2.IsMarkedForFreeShipping);
            Assert.AreEqual(1.33m, li1.ShippingPortion);
            Assert.AreEqual(0.67m, li2.ShippingPortion);
            Assert.AreEqual(10m, li1.TaxPortion);
            Assert.AreEqual(5m, li2.TaxPortion);

            Assert.AreEqual(2m, o.TotalShippingBeforeDiscounts);
            Assert.AreEqual(2m, o.TotalShippingAfterDiscounts);

            Assert.AreEqual(15m, o.ItemsTax);
            Assert.AreEqual(0.14m, o.ShippingTax);
            Assert.AreEqual(15.14m, o.TotalTax);
        }