Exemplo n.º 1
0
        /// <summary>
        /// Gets allowed discounts
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <returns>Discounts</returns>
        protected static DiscountCollection GetAllowedDiscounts(ProductVariant productVariant, Customer customer)
        {
            var allowedDiscounts = new DiscountCollection();

            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 category = _productCategory.Category;
                if (category != null)
                {
                    foreach (var _discount in category.Discounts)
                    {
                        if (_discount.IsActive(customerCouponCode) &&
                            _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                            !allowedDiscounts.ContainsDiscount(_discount.Name))
                        {
                            //discount requirements
                            if (_discount.CheckDiscountRequirements(customer) &&
                                _discount.CheckDiscountLimitations(customer))
                            {
                                allowedDiscounts.Add(_discount);
                            }
                        }
                    }
                }
            }
            return(allowedDiscounts);
        }
Exemplo n.º 2
0
        private static DiscountCollection DBMapping(DBDiscountCollection dbCollection)
        {
            if (dbCollection == null)
                return null;

            DiscountCollection collection = new DiscountCollection();
            foreach (DBDiscount dbItem in dbCollection)
            {
                Discount item = DBMapping(dbItem);
                collection.Add(item);
            }

            return collection;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets allowed discounts
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <returns>Discounts</returns>
        protected static DiscountCollection GetAllowedDiscounts(ProductVariant productVariant, Customer customer)
        {
            int customerID = 0;
            if (customer != null)
                customerID = customer.CustomerID;

            DiscountCollection allowedDiscounts = new DiscountCollection();

            //CustomerRoleCollection customerRoles = CustomerManager.GetCustomerRolesByCustomerID(customerID);
            //foreach (CustomerRole _customerRole in customerRoles)
            //    foreach (Discount _discount in _customerRole.Discounts)
            //        if (_discount.IsActive && _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs && !allowedDiscounts.ContainsDiscount(_discount.Name))
            //            allowedDiscounts.Add(_discount);

            string customerCouponCode = string.Empty;
            if (customer != null)
                customerCouponCode = customer.LastAppliedCouponCode;

            foreach (Discount _discount in productVariant.AllDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                    !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;
                    }
                }
            }

            ProductCategoryCollection productCategories = CategoryManager.GetProductCategoriesByProductID(productVariant.ProductID);
            foreach (ProductCategory _productCategory in productCategories)
            {
                Category category = _productCategory.Category;
                if (category != null)
                {
                    foreach (Discount _discount in category.Discounts)
                    {
                        if (_discount.IsActive(customerCouponCode) &&
                            _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                            !allowedDiscounts.ContainsDiscount(_discount.Name))
                        {
                            switch (_discount.DiscountRequirement)
                            {
                                case DiscountRequirementEnum.None:
                                    {
                                        allowedDiscounts.Add(_discount);
                                    }
                                    break;
                                case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                                    {
                                        allowedDiscounts.Add(_discount);
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
            return allowedDiscounts;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets allowed discounts
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <returns>Discounts</returns>
        protected static DiscountCollection GetAllowedDiscounts(ProductVariant productVariant, Customer customer)
        {
            int customerID = 0;

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

            DiscountCollection allowedDiscounts = new DiscountCollection();

            //CustomerRoleCollection customerRoles = CustomerManager.GetCustomerRolesByCustomerID(customerID);
            //foreach (CustomerRole _customerRole in customerRoles)
            //    foreach (Discount _discount in _customerRole.Discounts)
            //        if (_discount.IsActive && _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs && !allowedDiscounts.ContainsDiscount(_discount.Name))
            //            allowedDiscounts.Add(_discount);

            string customerCouponCode = string.Empty;

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

            foreach (Discount _discount in productVariant.AllDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                    !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;
                    }
                }
            }

            ProductCategoryCollection productCategories = CategoryManager.GetProductCategoriesByProductID(productVariant.ProductID);

            foreach (ProductCategory _productCategory in productCategories)
            {
                Category category = _productCategory.Category;
                if (category != null)
                {
                    foreach (Discount _discount in category.Discounts)
                    {
                        if (_discount.IsActive(customerCouponCode) &&
                            _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                            !allowedDiscounts.ContainsDiscount(_discount.Name))
                        {
                            switch (_discount.DiscountRequirement)
                            {
                            case DiscountRequirementEnum.None:
                            {
                                allowedDiscounts.Add(_discount);
                            }
                            break;

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

                            default:
                                break;
                            }
                        }
                    }
                }
            }
            return(allowedDiscounts);
        }