Пример #1
0
        protected void ApplyDiscountCouponCode()
        {
            string couponCode = this.txtDiscountCouponCode.Text.Trim();

            if (String.IsNullOrEmpty(couponCode))
            {
                return;
            }

            var  discounts       = DiscountManager.GetAllDiscounts(null);
            var  discount        = discounts.FindByCouponCode(couponCode);
            bool isDiscountValid = discount != null;

            if (isDiscountValid)
            {
                pnlDiscountWarnings.Visible = false;
                lblDiscountWarning.Visible  = false;

                CustomerManager.ApplyDiscountCouponCode(couponCode);
                this.BindData();
            }
            else
            {
                pnlDiscountWarnings.Visible = true;
                lblDiscountWarning.Visible  = true;
                lblDiscountWarning.Text     = GetLocaleResourceString("ShoppingCart.DiscountCouponCode.WrongDiscount");
            }
        }
Пример #2
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);
                        }
                    }
                }
            }
        }
Пример #3
0
        void BindGrid()
        {
            DiscountCollection discountCollection = DiscountManager.GetAllDiscounts(null);

            gvDiscounts.DataSource = discountCollection;
            gvDiscounts.DataBind();
        }
Пример #4
0
        public void SaveInfo(int pvId)
        {
            ProductVariant productVariant = ProductManager.GetProductVariantById(pvId);

            if (productVariant != null)
            {
                List <int> selectedDiscountIds = this.DiscountMappingControl.SelectedDiscountIds;
                var        existingDiscounts   = DiscountManager.GetDiscountsByProductVariantId(productVariant.ProductVariantId);

                var allDiscounts = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToSKUs);
                foreach (Discount discount in allDiscounts)
                {
                    if (selectedDiscountIds.Contains(discount.DiscountId))
                    {
                        if (existingDiscounts.Find(d => d.DiscountId == discount.DiscountId) == null)
                        {
                            DiscountManager.AddDiscountToProductVariant(productVariant.ProductVariantId, discount.DiscountId);
                        }
                    }
                    else
                    {
                        if (existingDiscounts.Find(d => d.DiscountId == discount.DiscountId) != null)
                        {
                            DiscountManager.RemoveDiscountFromProductVariant(productVariant.ProductVariantId, discount.DiscountId);
                        }
                    }
                }
            }
        }
Пример #5
0
        void BindGrid()
        {
            var discounts = DiscountManager.GetAllDiscounts(null);

            gvDiscounts.DataSource = discounts;
            gvDiscounts.DataBind();
        }
Пример #6
0
        public void BindData(DiscountTypeEnum?DiscountType)
        {
            var discounts = DiscountManager.GetAllDiscounts(DiscountType);

            foreach (Discount discount in discounts)
            {
                ListItem item = new ListItem(discount.Name, discount.DiscountId.ToString());
                if (this.selectedDiscountIds.Contains(discount.DiscountId))
                {
                    item.Selected = true;
                }
                this.cblDiscounts.Items.Add(item);
            }
            this.cblDiscounts.DataBind();
        }
Пример #7
0
        /// <summary>
        /// Gets a shipping discount
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="shippingTotal">Shipping total</param>
        /// <param name="appliedDiscount">Applied discount</param>
        /// <returns>Shipping discount</returns>
        public static decimal GetShippingDiscount(Customer customer,
                                                  decimal shippingTotal, out Discount appliedDiscount)
        {
            decimal shippingDiscountAmount = decimal.Zero;

            string customerCouponCode = string.Empty;

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

            var allDiscounts     = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToShipping);
            var allowedDiscounts = new DiscountCollection();

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

            appliedDiscount = DiscountManager.GetPreferredDiscount(allowedDiscounts, shippingTotal);
            if (appliedDiscount != null)
            {
                shippingDiscountAmount = appliedDiscount.GetDiscountAmount(shippingTotal);
            }

            if (shippingDiscountAmount < decimal.Zero)
            {
                shippingDiscountAmount = decimal.Zero;
            }

            shippingDiscountAmount = Math.Round(shippingDiscountAmount, 2);

            return(shippingDiscountAmount);
        }
        /// <summary>
        /// Gets an order discount
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="orderSubTotal">Order subtotal</param>
        /// <returns>Order discount</returns>
        public static decimal GetOrderDiscount(Customer customer, decimal orderSubTotal)
        {
            decimal SubTotalDiscount = decimal.Zero;
            int     customerID       = 0;

            if (customer != null)
            {
                customerID = customer.CustomerID;
            }

            string customerCouponCode = string.Empty;

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

            DiscountCollection allDiscounts     = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToWholeOrder);
            DiscountCollection allowedDiscounts = new DiscountCollection();

            foreach (Discount _discount in allDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToWholeOrder &&
                    !allowedDiscounts.ContainsDiscount(_discount.Name))
                {
                    switch (_discount.DiscountRequirement)
                    {
                    case DiscountRequirementEnum.None:
                    {
                        allowedDiscounts.Add(_discount);
                    }
                    break;

                    case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                    {
                        if (_discount.CheckCustomerRoleRequirement(customerID))
                        {
                            allowedDiscounts.Add(_discount);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
            }

            Discount preferredDiscount = DiscountManager.GetPreferredDiscount(allowedDiscounts, orderSubTotal);

            if (preferredDiscount != null)
            {
                SubTotalDiscount = preferredDiscount.GetDiscountAmount(orderSubTotal);
            }

            if (SubTotalDiscount < decimal.Zero)
            {
                SubTotalDiscount = decimal.Zero;
            }

            SubTotalDiscount = Math.Round(SubTotalDiscount, 2);

            return(SubTotalDiscount);
        }
Пример #9
0
        public IEnumerable <Discount> GetAllDiscounts()
        {
            DiscountManager dscManager = new DiscountManager(_context);

            return(dscManager.GetAllDiscounts());
        }