Example #1
0
        public void SaveInfo(int catId)
        {
            Category category = CategoryManager.GetCategoryById(catId);

            if (category != null)
            {
                List <int> selectedDiscountIds = this.DiscountMappingControl.SelectedDiscountIds;
                var        existingDiscounts   = DiscountManager.GetDiscountsByCategoryId(category.CategoryId);

                var allDiscounts = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToCategories);
                foreach (Discount discount in allDiscounts)
                {
                    if (selectedDiscountIds.Contains(discount.DiscountId))
                    {
                        if (existingDiscounts.Find(d => d.DiscountId == discount.DiscountId) == null)
                        {
                            DiscountManager.AddDiscountToCategory(category.CategoryId, discount.DiscountId);
                        }
                    }
                    else
                    {
                        if (existingDiscounts.Find(d => d.DiscountId == discount.DiscountId) != null)
                        {
                            DiscountManager.RemoveDiscountFromCategory(category.CategoryId, discount.DiscountId);
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Gets allowed discounts
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <returns>Discounts</returns>
        protected static List <Discount> GetAllowedDiscounts(ProductVariant productVariant, Customer customer)
        {
            var allowedDiscounts = new List <Discount>();

            string customerCouponCode = string.Empty;

            if (customer != null)
            {
                customerCouponCode = customer.LastAppliedCouponCode;
            }

            foreach (var _discount in productVariant.AllDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                    !allowedDiscounts.ContainsDiscount(_discount.Name))
                {
                    //discount requirements
                    if (_discount.CheckDiscountRequirements(customer) &&
                        _discount.CheckDiscountLimitations(customer))
                    {
                        allowedDiscounts.Add(_discount);
                    }
                }
            }

            var productCategories = CategoryManager.GetProductCategoriesByProductId(productVariant.ProductId);

            foreach (var _productCategory in productCategories)
            {
                var _categoryDiscounts = DiscountManager.GetDiscountsByCategoryId(_productCategory.CategoryId);
                foreach (var _discount in _categoryDiscounts)
                {
                    if (_discount.IsActive(customerCouponCode) &&
                        _discount.DiscountType == DiscountTypeEnum.AssignedToCategories &&
                        !allowedDiscounts.ContainsDiscount(_discount.Name))
                    {
                        //discount requirements
                        if (_discount.CheckDiscountRequirements(customer) &&
                            _discount.CheckDiscountLimitations(customer))
                        {
                            allowedDiscounts.Add(_discount);
                        }
                    }
                }
            }
            return(allowedDiscounts);
        }
        public void SaveInfo(int catId)
        {
            Category category = CategoryManager.GetCategoryById(catId);

            if (category != null)
            {
                foreach (Discount discount in DiscountManager.GetDiscountsByCategoryId(category.CategoryId))
                {
                    DiscountManager.RemoveDiscountFromCategory(category.CategoryId, discount.DiscountId);
                }
                foreach (int discountId in DiscountMappingControl.SelectedDiscountIds)
                {
                    DiscountManager.AddDiscountToCategory(category.CategoryId, discountId);
                }
            }
        }