Example #1
0
        public static bool HasQualifyingItemGiftProductPromotion(IRuleContext ruleContext)
        {
            bool isQualifyingItemGiftProductPromotion = false;
            PromotionController promotionController   = CreatePromotionController();

            foreach (PromotionsData.PromotionUsage promotionUsage in PromotionsData.DataContextProvider.Current.PromotionUsages.Where(pu => pu.CustomerId == ruleContext.CustomerId && pu.Complete == false))
            {
                PromotionsData.Promotion promotion = PromotionsData.DataContextProvider.Current.Promotions.FirstOrDefault(p => p.Id == promotionUsage.PromotionId);
                ruleContext.PromotionId = promotion.Id;

                if (promotionController.ValidatePromotion(promotion, ruleContext, AppLogic.CustomerLevelAllowsCoupons(ruleContext.CustomerLevel)).All(vr => vr.IsValid))
                {
                    foreach (PromotionDiscountBase pd in promotion.PromotionDiscounts.Where(p => p.GetType() == typeof(GiftProductPromotionDiscount)))
                    {
                        CategoryPromotionRule     categories    = new CategoryPromotionRule();
                        SectionPromotionRule      sections      = new SectionPromotionRule();
                        ManufacturerPromotionRule manufacturers = new ManufacturerPromotionRule();
                        ProductIdPromotionRule    productids    = new ProductIdPromotionRule();

                        if (promotion.PromotionRules.Where(pr => (pr.GetType() == typeof(CategoryPromotionRule)) || (pr.GetType() == typeof(SectionPromotionRule)) || (pr.GetType() == typeof(ManufacturerPromotionRule)) || (pr.GetType() == typeof(ProductIdPromotionRule))).Count() > 0)
                        {
                            isQualifyingItemGiftProductPromotion = true;
                        }
                    }
                }
            }

            return(isQualifyingItemGiftProductPromotion);
        }
Example #2
0
        public static IList <PromotionsData.Promotion> AutoAssignPromotions(int customerId, IRuleContext ruleContext)
        {
            IList <PromotionsData.Promotion> autoAssignPromotions = new List <PromotionsData.Promotion>();

            if (ruleContext.CartType != null && ruleContext.CartType != (Int32)CartTypeEnum.ShoppingCart)
            {
                return(autoAssignPromotions);
            }

            PromotionController promotionController = CreatePromotionController();

            if (!AppLogic.AppConfigExists("AspDotNetStorefront.Promotions.excludestates"))
            {
                AppLogic.AddAppConfig("AspDotNetStorefront.Promotions.excludestates", "states to be excluded from shipping promotions", String.Empty, "", true);
            }
            string excludeConfig = AppLogic.AppConfig("AspDotNetStorefront.Promotions.excludestates");

            if (excludeConfig.Length > 0)
            {
                ruleContext.ExcludeStates = excludeConfig.Split(',');
            }

            var promosToAssign = PromotionsData.DataContextProvider.Current.Promotions.Where(p => p.Active && p.AutoAssigned && !PromotionManager.GetRemovedAutoAssignPromotionIdList(customerId).Contains(p.Id));

            foreach (PromotionsData.Promotion promotion in promosToAssign)
            {
                ruleContext.PromotionId = promotion.Id;
                if (promotionController.ValidatePromotion(promotion, ruleContext, AppLogic.CustomerLevelAllowsCoupons(ruleContext.CustomerLevel)).All(vr => vr.IsValid))
                {
                    AssignPromotion(customerId, promotion.Id);
                    autoAssignPromotions.Add(promotion);
                }
            }

            return(autoAssignPromotions);
        }
Example #3
0
        public static List <DiscountableItem> GetDiscountableItems(IRuleContext ruleContext, int promoId)
        {
            List <DiscountableItem> discountableItems   = new List <DiscountableItem>();
            List <Int32>            nonDiscountableIds  = GetNonDiscountableShoppingCartIds(ruleContext);
            PromotionController     promotionController = CreatePromotionController();

            PromotionsData.Promotion promotion = PromotionsData.DataContextProvider.Current.Promotions.FirstOrDefault(p => p.Active && p.Id == promoId);
            ruleContext.PromotionId = promotion.Id;

            if (promotionController.ValidatePromotion(promotion, ruleContext, AppLogic.CustomerLevelAllowsCoupons(ruleContext.CustomerLevel)).All(vr => vr.IsValid))
            {
                foreach (PromotionDiscountBase pd in promotion.PromotionDiscounts.Where(p => p.GetType() == typeof(OrderItemPromotionDiscount) || p.GetType() == typeof(GiftProductPromotionDiscount) || p.GetType() == typeof(OrderPromotionDiscount)))
                {
                    CategoryPromotionRule     categoryIdRule     = new CategoryPromotionRule();
                    SectionPromotionRule      sectionIdRule      = new SectionPromotionRule();
                    ManufacturerPromotionRule manufacturerIdRule = new ManufacturerPromotionRule();
                    ProductIdPromotionRule    productIdRule      = new ProductIdPromotionRule();

                    if (promotion.PromotionRules.Where(pr => pr.GetType() == typeof(CategoryPromotionRule)).Count() > 0)
                    {
                        categoryIdRule = promotion.PromotionRules.Where(pr => pr.GetType() == typeof(CategoryPromotionRule)).First() as CategoryPromotionRule;
                    }

                    if (promotion.PromotionRules.Where(pr => pr.GetType() == typeof(SectionPromotionRule)).Count() > 0)
                    {
                        sectionIdRule = promotion.PromotionRules.Where(pr => pr.GetType() == typeof(SectionPromotionRule)).First() as SectionPromotionRule;
                    }

                    if (promotion.PromotionRules.Where(pr => pr.GetType() == typeof(ManufacturerPromotionRule)).Count() > 0)
                    {
                        manufacturerIdRule = promotion.PromotionRules.Where(pr => pr.GetType() == typeof(ManufacturerPromotionRule)).First() as ManufacturerPromotionRule;
                    }

                    if (promotion.PromotionRules.Where(pr => pr.GetType() == typeof(ProductIdPromotionRule)).Count() > 0)
                    {
                        productIdRule = promotion.PromotionRules.Where(pr => pr.GetType() == typeof(ProductIdPromotionRule)).First() as ProductIdPromotionRule;
                    }

                    foreach (ShoppingCartItem cartItem in ruleContext.ShoppingCartItems)
                    {
                        bool qualifies = true;
                        if (categoryIdRule.CategoryIds != null && categoryIdRule.CategoryIds.Count() > 0 && cartItem.CategoryIds != null && cartItem.CategoryIds.Intersect(categoryIdRule.CategoryIds).Count() == 0)
                        {
                            qualifies = false;
                        }

                        if (sectionIdRule.SectionIds != null && sectionIdRule.SectionIds.Count() > 0 && cartItem.SectionIds != null && cartItem.SectionIds.Intersect(sectionIdRule.SectionIds).Count() == 0)
                        {
                            qualifies = false;
                        }

                        if (manufacturerIdRule.ManufacturerIds != null && manufacturerIdRule.ManufacturerIds.Count() > 0 && cartItem.ManufacturerIds != null && cartItem.ManufacturerIds.Intersect(manufacturerIdRule.ManufacturerIds).Count() == 0)
                        {
                            qualifies = false;
                        }

                        if (productIdRule.ProductIds != null && !productIdRule.ProductIds.Contains(cartItem.ProductId))
                        {
                            qualifies = false;
                        }

                        if (nonDiscountableIds.Contains(cartItem.ShoppingCartRecordId))
                        {
                            qualifies = false;
                        }

                        if (qualifies)
                        {
                            if (pd.GetType() == typeof(OrderItemPromotionDiscount) || pd.GetType() == typeof(GiftProductPromotionDiscount))
                            {
                                DiscountableItem discountableItem = new DiscountableItem();
                                discountableItem.CartPrice            = cartItem.CartPrice;
                                discountableItem.ProductId            = cartItem.ProductId;
                                discountableItem.Quantity             = cartItem.Quantity;
                                discountableItem.ShoppingCartRecordId = cartItem.ShoppingCartRecordId;
                                discountableItem.Sku       = cartItem.Sku;
                                discountableItem.Subtotal  = cartItem.Subtotal;
                                discountableItem.VariantId = cartItem.VariantId;
                                discountableItems.Add(discountableItem);
                            }
                        }
                    }
                }
            }
            return(discountableItems);
        }