Esempio n. 1
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");
        }
Esempio n. 2
0
        private void CheckForPricesBelowZero(UserSpecificPrice price)
        {
            var final = price.PriceWithAdjustments();

            if (final < 0)
            {
                var tweak = -1 * final;
                price.AddAdjustment(tweak, "Price can not be below zero");
            }
        }
Esempio n. 3
0
        private void AdjustProductPriceForUser(UserSpecificPrice price, Product p, CustomerAccount currentUser)
        {
            if (currentUser == null)
            {
                return;
            }
            if (currentUser.Bvin == string.Empty)
            {
                return;
            }
            if (currentUser.PricingGroupId == string.Empty)
            {
                return;
            }
            if (p == null)
            {
                return;
            }
            if (price == null)
            {
                return;
            }

            var startingPrice = price.PriceWithAdjustments();

            var pricingGroup = ContactServices.PriceGroups.Find(currentUser.PricingGroupId);

            if (pricingGroup == null)
            {
                return;
            }

            var nonGroupPrice = price.BasePrice;

            var groupPrice = nonGroupPrice;

            //groupPrice = pricingGroup.GetAdjustedPriceForThisGroup(p.SitePrice, p.ListPrice, p.SiteCost);
            groupPrice = pricingGroup.GetAdjustedPriceForThisGroup(startingPrice, p.ListPrice, p.SiteCost);

            var amountOfDiscount = groupPrice - nonGroupPrice;

            price.AddAdjustment(amountOfDiscount, "Price Group");
        }