示例#1
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);
        }
示例#2
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);
        }