예제 #1
0
        /// <summary>
        /// Updates the discount
        /// </summary>
        /// <param name="discountId">Discount identifier</param>
        /// <param name="discountType">The discount type</param>
        /// <param name="discountRequirement">The discount requirement</param>
        /// <param name="discountLimitation">The discount limitation</param>
        /// <param name="name">The name</param>
        /// <param name="usePercentage">A value indicating whether to use percentage</param>
        /// <param name="discountPercentage">The discount percentage</param>
        /// <param name="discountAmount">The discount amount</param>
        /// <param name="startDate">The discount start date and time</param>
        /// <param name="endDate">The discount end date and time</param>
        /// <param name="requiresCouponCode">The value indicating whether discount requires coupon code</param>
        /// <param name="couponCode">The coupon code</param>
        /// <param name="deleted">A value indicating whether the entity has been deleted</param>
        /// <returns>Discount</returns>
        public static Discount UpdateDiscount(int discountId, DiscountTypeEnum discountType,
                                              DiscountRequirementEnum discountRequirement, DiscountLimitationEnum discountLimitation,
                                              string name, bool usePercentage, decimal discountPercentage, decimal discountAmount,
                                              DateTime startDate, DateTime endDate, bool requiresCouponCode,
                                              string couponCode, bool deleted)
        {
            if (startDate.CompareTo(endDate) >= 0)
            {
                throw new NopException("Start date should be less then expiration date");
            }

            if (requiresCouponCode && String.IsNullOrEmpty(couponCode))
            {
                throw new NopException("Discount requires coupon code. Coupon code could not be empty.");
            }

            var dbItem = DBProviderManager <DBDiscountProvider> .Provider.UpdateDiscount(discountId, (int)discountType,
                                                                                         (int)discountRequirement, (int)discountLimitation, name,
                                                                                         usePercentage, discountPercentage, discountAmount, startDate, endDate,
                                                                                         requiresCouponCode, couponCode, deleted);

            var discount = DBMapping(dbItem);

            if (DiscountManager.CacheEnabled)
            {
                NopCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
            return(discount);
        }
예제 #2
0
 public Campaign(string description, double amount, int quantity, DiscountTypeEnum discountType)
 {
     Description  = description;
     Amount       = amount;
     Quantity     = quantity;
     DiscountType = discountType;
 }
예제 #3
0
    /// <summary>
    /// Based on type of displayed discount <see cref="DiscountApplicationEnum"/> sets correct discount type <see cref="DiscountTypeEnum"/> for status filter in UniGrid.
    /// </summary>
    private void SetDiscountStatusFilterType()
    {
        DiscountTypeEnum discountStatusFilterType = DiscountTypeEnum.Discount;

        switch (DiscountType)
        {
        case DiscountApplicationEnum.Products:
            discountStatusFilterType = DiscountTypeEnum.CatalogDiscount;
            break;

        case DiscountApplicationEnum.Order:
            discountStatusFilterType = DiscountTypeEnum.OrderDiscount;
            break;

        case DiscountApplicationEnum.Shipping:
            discountStatusFilterType = DiscountTypeEnum.ShippingDiscount;
            break;
        }

        // In UniGrid, find column Status, its filter and its parameter for discount type
        var discountFilterTypeParam = ugDiscounts?.GridColumns?
                                      .Columns.SingleOrDefault(c => string.Equals(c.Name, "Status", StringComparison.OrdinalIgnoreCase))?
                                      .Filter?.CustomFilterParameters?.Parameters.SingleOrDefault(p => string.Equals(p.Name, "discounttype", StringComparison.OrdinalIgnoreCase));

        // If this parameter has been found, set its value
        if (discountFilterTypeParam != null)
        {
            discountFilterTypeParam.Value = discountStatusFilterType.ToStringRepresentation();
        }
    }
예제 #4
0
        /// <summary>
        /// Updates the discount
        /// </summary>
        /// <param name="discountId">Discount identifier</param>
        /// <param name="discountType">The discount type</param>
        /// <param name="discountRequirement">The discount requirement</param>
        /// <param name="requirementSpentAmount">The discount requirement - applies if customer has spent/purchased x.xx amount</param>
        /// <param name="requirementBillingCountryIs">The discount requirement - customer's billing country is... (used when requirement is set to "Billing country is")</param>
        /// <param name="requirementShippingCountryIs">The discount requirement - customer's shipping country is... (used when requirement is set to "Shipping country is")</param>
        /// <param name="discountLimitation">The discount limitation</param>
        /// <param name="limitationTimes">The discount limitation times (used when Limitation is set to "N Times Only" or "N Times Per Customer")</param>
        /// <param name="name">The name</param>
        /// <param name="usePercentage">A value indicating whether to use percentage</param>
        /// <param name="discountPercentage">The discount percentage</param>
        /// <param name="discountAmount">The discount amount</param>
        /// <param name="startDate">The discount start date and time</param>
        /// <param name="endDate">The discount end date and time</param>
        /// <param name="requiresCouponCode">The value indicating whether discount requires coupon code</param>
        /// <param name="couponCode">The coupon code</param>
        /// <param name="deleted">A value indicating whether the entity has been deleted</param>
        /// <returns>Discount</returns>
        public static Discount UpdateDiscount(int discountId, DiscountTypeEnum discountType,
                                              DiscountRequirementEnum discountRequirement, decimal requirementSpentAmount,
                                              int requirementBillingCountryIs, int requirementShippingCountryIs,
                                              DiscountLimitationEnum discountLimitation, int limitationTimes,
                                              string name, bool usePercentage,
                                              decimal discountPercentage, decimal discountAmount,
                                              DateTime startDate, DateTime endDate, bool requiresCouponCode,
                                              string couponCode, bool deleted)
        {
            if (startDate.CompareTo(endDate) >= 0)
            {
                throw new NopException("Start date should be less then expiration date");
            }

            if (requiresCouponCode && String.IsNullOrEmpty(couponCode))
            {
                throw new NopException("Discount requires coupon code. Coupon code could not be empty.");
            }

            name       = CommonHelper.EnsureMaximumLength(name, 100);
            couponCode = CommonHelper.EnsureMaximumLength(couponCode, 100);

            var discount = GetDiscountById(discountId);

            if (discount == null)
            {
                return(null);
            }

            var context = ObjectContextHelper.CurrentObjectContext;

            if (!context.IsAttached(discount))
            {
                context.Discounts.Attach(discount);
            }

            discount.DiscountTypeId               = (int)discountType;
            discount.DiscountRequirementId        = (int)discountRequirement;
            discount.RequirementSpentAmount       = requirementSpentAmount;
            discount.RequirementBillingCountryIs  = requirementBillingCountryIs;
            discount.RequirementShippingCountryIs = requirementShippingCountryIs;
            discount.DiscountLimitationId         = (int)discountLimitation;
            discount.LimitationTimes              = limitationTimes;
            discount.Name               = name;
            discount.UsePercentage      = usePercentage;
            discount.DiscountPercentage = discountPercentage;
            discount.DiscountAmount     = discountAmount;
            discount.StartDate          = startDate;
            discount.EndDate            = endDate;
            discount.RequiresCouponCode = requiresCouponCode;
            discount.CouponCode         = couponCode;
            discount.Deleted            = deleted;
            context.SaveChanges();

            if (DiscountManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
            return(discount);
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Coupon" /> class.
 /// </summary>
 /// <param name="Code">Code.</param>
 /// <param name="Company">Company.</param>
 /// <param name="CurrentUsage">CurrentUsage.</param>
 /// <param name="DiscountAmount">DiscountAmount (required).</param>
 /// <param name="DiscountType">DiscountType (required).</param>
 /// <param name="ExpireDate">ExpireDate.</param>
 /// <param name="Id">Id.</param>
 /// <param name="MaxLimit">MaxLimit (required).</param>
 public Coupon(string Code = default(string), Company Company = default(Company), int?CurrentUsage = default(int?), decimal?DiscountAmount = default(decimal?), DiscountTypeEnum DiscountType = default(DiscountTypeEnum), DateTime?ExpireDate = default(DateTime?), long?Id = default(long?), int?MaxLimit = default(int?))
 {
     // to ensure "DiscountAmount" is required (not null)
     if (DiscountAmount == null)
     {
         throw new InvalidDataException("DiscountAmount is a required property for Coupon and cannot be null");
     }
     else
     {
         this.DiscountAmount = DiscountAmount;
     }
     // to ensure "DiscountType" is required (not null)
     if (DiscountType == null)
     {
         throw new InvalidDataException("DiscountType is a required property for Coupon and cannot be null");
     }
     else
     {
         this.DiscountType = DiscountType;
     }
     // to ensure "MaxLimit" is required (not null)
     if (MaxLimit == null)
     {
         throw new InvalidDataException("MaxLimit is a required property for Coupon and cannot be null");
     }
     else
     {
         this.MaxLimit = MaxLimit;
     }
     this.Code         = Code;
     this.Company      = Company;
     this.CurrentUsage = CurrentUsage;
     this.ExpireDate   = ExpireDate;
     this.Id           = Id;
 }
예제 #6
0
파일: Discount.cs 프로젝트: maorRoz/Sadna
 public Discount(string _discountCode, DiscountTypeEnum _discountType, DateTime _startDate, DateTime _EndDate, int _discountAmount, bool _presenteges)
 {
     discountCode   = _discountCode;
     discountType   = _discountType;
     startDate      = _startDate;
     EndDate        = _EndDate;
     DiscountAmount = _discountAmount;
     Percentages    = _presenteges;
 }
예제 #7
0
파일: Discount.cs 프로젝트: maorRoz/Sadna
 public Discount(DiscountTypeEnum _discountType, DateTime _startDate, DateTime _EndDate, double _discountAmount, bool _presenteges)
 {
     discountCode   = GetDiscountCode();
     discountType   = _discountType;
     startDate      = _startDate;
     EndDate        = _EndDate;
     DiscountAmount = _discountAmount;
     Percentages    = _presenteges;
 }
예제 #8
0
        public Coupon(string description, double minAmount, double discountAmount, DiscountTypeEnum discountType)
        {
            Description    = description;
            MinAmount      = minAmount;
            DiscountAmount = discountAmount;
            DiscountType   = discountType;

            ValidationHelper.Validate(this);
        }
예제 #9
0
 /// <summary>
 /// Coupon implementation based on min value of Cart
 /// </summary>
 /// <param name="discountFactor">Comparing value to apply coupon</param>
 /// <param name="discountValue">Appyling value of discount</param>
 /// <param name="discountType">Apply type of discount</param>
 public CartMinValueCoupon(double discountValue, double discountFactor, DiscountTypeEnum discountType)
 {
     _discountValue = discountValue;
     _ruleFactor    = discountFactor;
     _discountType  = discountType;
     if (!IsValid())
     {
         throw new System.Exception("Coupon is not valid");
     }
 }
예제 #10
0
        /// <summary>
        /// Get discount type name
        /// </summary>
        /// <param name="dt">Discount type</param>
        /// <returns>Discount type name</returns>
        public static string GetDiscountTypeName(this DiscountTypeEnum dt)
        {
            string name = IoC.Resolve <ILocalizationManager>().GetLocaleResourceString(
                string.Format("DiscountType.{0}", (int)dt),
                NopContext.Current.WorkingLanguage.LanguageId,
                true,
                CommonHelper.ConvertEnum(dt.ToString()));

            return(name);
        }
예제 #11
0
        public static string PrintEnum(DiscountTypeEnum type)
        {
            switch (type)
            {
            case DiscountTypeEnum.Hidden: return("HIDDEN");

            case DiscountTypeEnum.Visible: return("VISIBLE");

            default: throw new StoreException(MarketError.LogicError, "Enum value not exists");
            }
        }
 /// <summary>
 /// Campaign based on count of product in a category
 /// </summary>
 /// <param name="category">Category to apply discount</param>
 /// <param name="discountValue">Appyling value of discount</param>
 /// <param name="discountFactor">Comparing value to apply coupon</param>
 /// <param name="discountType">Apply type of discount</param>
 public CategoryProductCountCampaign(Category category, double discountValue, double discountFactor, DiscountTypeEnum discountType)
 {
     _category      = category;
     _discountValue = discountValue;
     _ruleFactor    = discountFactor;
     _discountType  = discountType;
     if (!IsValid())
     {
         throw new Exception("Campaign is not valid");
     }
 }
예제 #13
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();
 }
예제 #14
0
        /// <summary>
        /// Converts a DiscountTypeEnum value to a corresponding string value
        /// </summary>
        /// <param name="enumValue">The DiscountTypeEnum value to convert</param>
        /// <returns>The representative string value</returns>
        public static string ToValue(DiscountTypeEnum enumValue)
        {
            switch (enumValue)
            {
            //only valid enum elements can be used
            //this is necessary to avoid errors
            case DiscountTypeEnum.LOYALTY_DISCOUNT:
            case DiscountTypeEnum.OTHER:
                return(stringValues[(int)enumValue]);

            //an invalid enum value was requested
            default:
                return(null);
            }
        }
예제 #15
0
        public static IBasketDiscountStrategy GetDiscount(DiscountTypeEnum discountType)
        {
            switch (discountType)
            {
            case DiscountTypeEnum.NoDiscount:
                return(new NoBasketDiscount());

            case DiscountTypeEnum.MoneyOff:
                return(new BasketDiscountMoneyOff());

            case DiscountTypeEnum.PercentageOff:
                return(new BasketDiscountPercentageOff());

            default:
                return(new NoBasketDiscount());
            }
        }
예제 #16
0
        /// <summary>
        /// Updates the discount
        /// </summary>
        /// <param name="DiscountID">Discount identifier</param>
        /// <param name="DiscountType">The discount type</param>
        /// <param name="DiscountRequirement">The discount requirement</param>
        /// <param name="Name">The name</param>
        /// <param name="UsePercentage">A value indicating whether to use percentage</param>
        /// <param name="DiscountPercentage">The discount percentage</param>
        /// <param name="DiscountAmount">The discount amount</param>
        /// <param name="StartDate">The discount start date and time</param>
        /// <param name="EndDate">The discount end date and time</param>
        /// <param name="RequiresCouponCode">The value indicating whether discount requires coupon code</param>
        /// <param name="CouponCode">The coupon code</param>
        /// <param name="Deleted">A value indicating whether the entity has been deleted</param>
        /// <returns>Discount</returns>
        public static Discount UpdateDiscount(int DiscountID, DiscountTypeEnum DiscountType,
                                              DiscountRequirementEnum DiscountRequirement, string Name, bool UsePercentage,
                                              decimal DiscountPercentage, decimal DiscountAmount, DateTime StartDate,
                                              DateTime EndDate, bool RequiresCouponCode, string CouponCode, bool Deleted)
        {
            if (StartDate.CompareTo(EndDate) >= 0)
            {
                throw new NopException("Start date should be less then expiration date");
            }

            //if ((DiscountType == DiscountTypeEnum.AssignedToWholeOrder) && !RequiresCouponCode)
            //{
            //    throw new NopException("Discounts assigned to whole order should require coupon code");
            //}

            //if ((DiscountType == DiscountTypeEnum.AssignedToWholeOrder)
            //    && RequiresCouponCode
            //    && String.IsNullOrEmpty(CouponCode))
            //{
            //    throw new NopException("Discounts assigned to whole order should require coupon code. Coupon code could not be empty.");
            //}

            if (RequiresCouponCode && String.IsNullOrEmpty(CouponCode))
            {
                throw new NopException("Discount requires coupon code. Coupon code could not be empty.");
            }

            DBDiscount dbItem = DBProviderManager <DBDiscountProvider> .Provider.UpdateDiscount(DiscountID, (int)DiscountType,
                                                                                                (int)DiscountRequirement, Name, UsePercentage, DiscountPercentage,
                                                                                                DiscountAmount, StartDate, EndDate,
                                                                                                RequiresCouponCode, CouponCode, Deleted);

            Discount discount = DBMapping(dbItem);

            if (DiscountManager.CacheEnabled)
            {
                NopCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
            return(discount);
        }
예제 #17
0
        /// <summary>
        /// Updates the discount
        /// </summary>
        /// <param name="discountId">Discount identifier</param>
        /// <param name="discountType">The discount type</param>
        /// <param name="discountRequirement">The discount requirement</param>
        /// <param name="requirementSpentAmount">The discount requirement - applies if customer has spent/purchased x.xx amount</param>
        /// <param name="requirementBillingCountryIs">The discount requirement - customer's billing country is... (used when requirement is set to "Billing country is")</param>
        /// <param name="requirementShippingCountryIs">The discount requirement - customer's shipping country is... (used when requirement is set to "Shipping country is")</param>
        /// <param name="discountLimitation">The discount limitation</param>
        /// <param name="limitationTimes">The discount limitation times (used when Limitation is set to "N Times Only" or "N Times Per Customer")</param>
        /// <param name="name">The name</param>
        /// <param name="usePercentage">A value indicating whether to use percentage</param>
        /// <param name="discountPercentage">The discount percentage</param>
        /// <param name="discountAmount">The discount amount</param>
        /// <param name="startDate">The discount start date and time</param>
        /// <param name="endDate">The discount end date and time</param>
        /// <param name="requiresCouponCode">The value indicating whether discount requires coupon code</param>
        /// <param name="couponCode">The coupon code</param>
        /// <param name="deleted">A value indicating whether the entity has been deleted</param>
        /// <returns>Discount</returns>
        public static Discount UpdateDiscount(int discountId, DiscountTypeEnum discountType,
            DiscountRequirementEnum discountRequirement, decimal requirementSpentAmount,
            int requirementBillingCountryIs, int requirementShippingCountryIs,
            DiscountLimitationEnum discountLimitation, int limitationTimes, 
            string name, bool usePercentage,
            decimal discountPercentage, decimal discountAmount,
            DateTime startDate, DateTime endDate, bool requiresCouponCode, 
            string couponCode, bool deleted)
        {
            if (startDate.CompareTo(endDate) >= 0)
                throw new NopException("Start date should be less then expiration date");

            if (requiresCouponCode && String.IsNullOrEmpty(couponCode))
            {
                throw new NopException("Discount requires coupon code. Coupon code could not be empty.");
            }

            name = CommonHelper.EnsureMaximumLength(name, 100);
            couponCode = CommonHelper.EnsureMaximumLength(couponCode, 100);

            var discount = GetDiscountById(discountId);
            if (discount == null)
                return null;

            var context = ObjectContextHelper.CurrentObjectContext;
            if (!context.IsAttached(discount))
                context.Discounts.Attach(discount);

            discount.DiscountTypeId = (int)discountType;
            discount.DiscountRequirementId = (int)discountRequirement;
            discount.RequirementSpentAmount = requirementSpentAmount;
            discount.RequirementBillingCountryIs = requirementBillingCountryIs;
            discount.RequirementShippingCountryIs = requirementShippingCountryIs;
            discount.DiscountLimitationId = (int)discountLimitation;
            discount.LimitationTimes = limitationTimes;
            discount.Name = name;
            discount.UsePercentage = usePercentage;
            discount.DiscountPercentage = discountPercentage;
            discount.DiscountAmount = discountAmount;
            discount.StartDate = startDate;
            discount.EndDate = endDate;
            discount.RequiresCouponCode = requiresCouponCode;
            discount.CouponCode = couponCode;
            discount.Deleted = deleted;
            context.SaveChanges();

            if (DiscountManager.CacheEnabled)
            {
                NopRequestCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
            return discount;
        }
예제 #18
0
        /// <summary>
        /// Gets all discounts
        /// </summary>
        /// <param name="discountType">Discount type; null to load all discount</param>
        /// <returns>Discount collection</returns>
        public static List<Discount> GetAllDiscounts(DiscountTypeEnum? discountType)
        {
            bool showHidden = NopContext.Current.IsAdmin;
            string key = string.Format(DISCOUNTS_ALL_KEY, showHidden, discountType);
            object obj2 = NopRequestCache.Get(key);
            if (DiscountManager.CacheEnabled && (obj2 != null))
            {
                return (List<Discount>)obj2;
            }

            int? discountTypeId = null;
            if (discountType.HasValue)
                discountTypeId = (int)discountType.Value;

            var context = ObjectContextHelper.CurrentObjectContext;
            var query = (IQueryable<Discount>)context.Discounts;
            if (!showHidden)
                query = query.Where(d => d.StartDate <= DateTime.UtcNow && d.EndDate >= DateTime.UtcNow);
            if (discountTypeId.HasValue && discountTypeId.Value > 0)
                query = query.Where(d => d.DiscountTypeId == discountTypeId);
            query = query.Where(d => !d.Deleted);
            query = query.OrderByDescending(d => d.StartDate);

            var discounts = query.ToList();

            if (DiscountManager.CacheEnabled)
            {
                NopRequestCache.Add(key, discounts);
            }
            return discounts;
        }
예제 #19
0
 public Basket(DiscountTypeEnum discountType)
 {
     _basketDiscountStrategy = BasketDiscountFactory.GetDiscount(discountType);
 }
예제 #20
0
 public CreateRequest DiscountType(DiscountTypeEnum discountType)
 {
     m_params.Add("discount_type", discountType);
     return(this);
 }
예제 #21
0
        /// <summary>
        /// Gets all discounts
        /// </summary>
        /// <param name="DiscountType">Discount type; null to load all discount</param>
        /// <returns>Discount collection</returns>
        public static DiscountCollection GetAllDiscounts(DiscountTypeEnum? DiscountType)
        {
            bool showHidden = NopContext.Current.IsAdmin;
            string key = string.Format(DISCOUNTS_ALL_KEY, showHidden, DiscountType);
            object obj2 = NopCache.Get(key);
            if (DiscountManager.CacheEnabled && (obj2 != null))
            {
                return (DiscountCollection)obj2;
            }

            int? discountTypeID = null;
            if (DiscountType.HasValue)
                discountTypeID = (int)DiscountType.Value;

            DBDiscountCollection dbCollection = DBProviderManager<DBDiscountProvider>.Provider.GetAllDiscounts(showHidden, discountTypeID);
            DiscountCollection discounts = DBMapping(dbCollection);

            if (DiscountManager.CacheEnabled)
            {
                NopCache.Max(key, discounts);
            }
            return discounts;
        }
예제 #22
0
        public Discount SaveInfo()
        {
            //discou tn type
            DiscountTypeEnum discountType = (DiscountTypeEnum)int.Parse(this.ddlDiscountType.SelectedItem.Value);

            //requirements
            DiscountRequirementEnum discountRequirement = (DiscountRequirementEnum)int.Parse(this.ddlDiscountRequirement.SelectedItem.Value);

            int[] restrictedProductVariantIds = new int[0];
            if (discountRequirement == DiscountRequirementEnum.HadPurchasedAllOfTheseProductVariants || discountRequirement == DiscountRequirementEnum.HadPurchasedOneOfTheseProductVariants)
            {
                restrictedProductVariantIds = ParseListOfRestrictedProductVariants(txtRestrictedProductVariants.Text);
            }
            decimal requirementSpentAmount = txtRequirementSpentAmount.Value;

            int requirementBillingCountryIs  = int.Parse(this.ddlRequirementBillingCountryIs.SelectedItem.Value);
            int requirementShippingCountryIs = int.Parse(this.ddlRequirementShippingCountryIs.SelectedItem.Value);

            //limitation
            DiscountLimitationEnum discountLimitation = (DiscountLimitationEnum)int.Parse(this.ddlDiscountLimitation.SelectedItem.Value);
            int limitationTimes = txtLimitationTimes.Value;

            string  name               = txtName.Text.Trim();
            bool    usePercentage      = cbUsePercentage.Checked;
            decimal discountPercentage = txtDiscountPercentage.Value;
            decimal discountAmount     = txtDiscountAmount.Value;
            bool    requiresCouponCode = cbRequiresCouponCode.Checked;
            string  couponCode         = txtCouponCode.Text.Trim();

            //dates
            if (!ctrlStartDatePicker.SelectedDate.HasValue)
            {
                throw new NopException("Start date is not set");
            }
            DateTime discountStartDate = ctrlStartDatePicker.SelectedDate.Value;

            if (!ctrlEndDatePicker.SelectedDate.HasValue)
            {
                throw new NopException("End date is not set");
            }
            DateTime discountEndDate = ctrlEndDatePicker.SelectedDate.Value;

            discountStartDate = DateTime.SpecifyKind(discountStartDate, DateTimeKind.Utc);
            discountEndDate   = DateTime.SpecifyKind(discountEndDate, DateTimeKind.Utc);

            Discount discount = DiscountManager.GetDiscountById(this.DiscountId);

            if (discount != null)
            {
                discount = DiscountManager.UpdateDiscount(discount.DiscountId,
                                                          discountType,
                                                          discountRequirement,
                                                          requirementSpentAmount,
                                                          requirementBillingCountryIs,
                                                          requirementShippingCountryIs,
                                                          discountLimitation,
                                                          limitationTimes,
                                                          name,
                                                          usePercentage,
                                                          discountPercentage,
                                                          discountAmount,
                                                          discountStartDate,
                                                          discountEndDate,
                                                          requiresCouponCode,
                                                          couponCode,
                                                          discount.Deleted);

                //discount requirements
                foreach (CustomerRole customerRole in discount.CustomerRoles)
                {
                    CustomerManager.RemoveDiscountFromCustomerRole(customerRole.CustomerRoleId, discount.DiscountId);
                }
                foreach (int customerRoleId in CustomerRoleMappingControl.SelectedCustomerRoleIds)
                {
                    CustomerManager.AddDiscountToCustomerRole(customerRoleId, discount.DiscountId);
                }

                foreach (ProductVariant pv in ProductManager.GetProductVariantsRestrictedByDiscountId(discount.DiscountId))
                {
                    DiscountManager.RemoveDiscountRestriction(pv.ProductVariantId, discount.DiscountId);
                }
                foreach (int productVariantId in restrictedProductVariantIds)
                {
                    DiscountManager.AddDiscountRestriction(productVariantId, discount.DiscountId);
                }
            }
            else
            {
                discount = DiscountManager.InsertDiscount(discountType,
                                                          discountRequirement,
                                                          requirementSpentAmount,
                                                          requirementBillingCountryIs,
                                                          requirementShippingCountryIs,
                                                          discountLimitation,
                                                          limitationTimes,
                                                          name,
                                                          usePercentage,
                                                          discountPercentage,
                                                          discountAmount,
                                                          discountStartDate,
                                                          discountEndDate,
                                                          requiresCouponCode,
                                                          couponCode,
                                                          false);

                //discount requirements
                foreach (int customerRoleId in CustomerRoleMappingControl.SelectedCustomerRoleIds)
                {
                    CustomerManager.AddDiscountToCustomerRole(customerRoleId, discount.DiscountId);
                }

                foreach (int productVariantId in restrictedProductVariantIds)
                {
                    DiscountManager.AddDiscountRestriction(productVariantId, discount.DiscountId);
                }
            }

            return(discount);
        }
예제 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OnDemandPromotion" /> class.
 /// </summary>
 /// <param name="accessType">The type of access that the promotion grants.  Option descriptions:  * &#x60;default&#x60; - The promotion grants discounts on existing product offerings.  * &#x60;vip&#x60; - The promotion grants free access to On Demand content before it is released or to access types that aren&#39;t part of the existing product offerings.  (required).</param>
 /// <param name="discountType">The type of discount that the promotion provides.  Option descriptions:  * &#x60;dollars&#x60; - The promotion discounts a fixed amount from the full purchase price.  * &#x60;free&#x60; - The promotion discounts the full purchase price. When **access_type** is &#x60;vip&#x60;, **discount_type** is always &#x60;free&#x60;.  * &#x60;percent&#x60; - The promotion discounts a percentage of the full purchase price.  (required).</param>
 /// <param name="download">Whether the promotion grants download access to On Demand content. (required).</param>
 /// <param name="label">The prefix string for batch codes, or the null value for single codes. (required).</param>
 /// <param name="metadata">metadata (required).</param>
 /// <param name="percentOff">When **discount_type** is &#x60;percent&#x60;, the percentage amount that is deducted from the product price. (required).</param>
 /// <param name="productType">The type of product to which the promotion can be applied. Only the &#x60;buy&#x60; and &#x60;rent&#x60; options are available when **access_type** is &#x60;vip&#x60;.  Option descriptions:  * &#x60;any&#x60; - The promotion can be applied to any product.  * &#x60;buy&#x60; - The promotion can be applied to a buyable single video.  * &#x60;buy_episode&#x60; - The promotion can be applied to a buyable single episode.  * &#x60;rent&#x60; - The promotion can be applied to a rentable single video.  * &#x60;rent_episode&#x60; - The promotion can be applied to a rentable single episode.  * &#x60;subscribe&#x60; - The promotion can be applied to a subscription.  (required).</param>
 /// <param name="streamPeriod">The amount of time that the user has access to the On Demand content after redeeming a promo code.  Option descriptions:  * &#x60;1_week&#x60; - Access lasts for one week.  * &#x60;1_year&#x60; - Access lasts for one year.  * &#x60;24_hour&#x60; - Access lasts for 24 hours.  * &#x60;30_days&#x60; - Access lasts for 30 days.  * &#x60;3_month&#x60; - Access lasts for three months.  * &#x60;48_hour&#x60; - Access lasts for 48 hours.  * &#x60;6_month&#x60; - Access lasts for six months.  * &#x60;72_hour&#x60; - Access lasts for 72 hours.  (required).</param>
 /// <param name="total">When **type** is &#x60;single&#x60;, the total number of times that the promotion can be used. When **type** is &#x60;batch&#x60; or &#x60;batch_prefix&#x60;, the total number of promo codes that have been generated. (required).</param>
 /// <param name="type">The way in which the promotion generates promo codes.  Option descriptions:  * &#x60;batch&#x60; - The promotion provides a unique promo code for each user.  * &#x60;batch_prefix&#x60; - Like &#x60;batch&#x60;, except that all codes have a similar prefix string. This option is deprecated, yet it may still appear for some users.  * &#x60;single&#x60; - The promotion provides a single promo code for all users.  (required).</param>
 /// <param name="uri">The promotion&#39;s canonical relative URI. (required).</param>
 public OnDemandPromotion(AccessTypeEnum accessType = default(AccessTypeEnum), DiscountTypeEnum discountType = default(DiscountTypeEnum), bool download = default(bool), string label = default(string), OnDemandPromotionMetadata metadata = default(OnDemandPromotionMetadata), decimal percentOff = default(decimal), ProductTypeEnum productType = default(ProductTypeEnum), StreamPeriodEnum streamPeriod = default(StreamPeriodEnum), decimal total = default(decimal), TypeEnum type = default(TypeEnum), string uri = default(string))
 {
     this.AccessType   = accessType;
     this.DiscountType = discountType;
     this.Download     = download;
     // to ensure "label" is required (not null)
     this.Label = label ?? throw new ArgumentNullException("label is a required property for OnDemandPromotion and cannot be null");
     // to ensure "metadata" is required (not null)
     this.Metadata     = metadata ?? throw new ArgumentNullException("metadata is a required property for OnDemandPromotion and cannot be null");
     this.PercentOff   = percentOff;
     this.ProductType  = productType;
     this.StreamPeriod = streamPeriod;
     this.Total        = total;
     this.Type         = type;
     // to ensure "uri" is required (not null)
     this.Uri = uri ?? throw new ArgumentNullException("uri is a required property for OnDemandPromotion and cannot be null");
 }
예제 #24
0
        /// <summary>
        /// Updates the discount
        /// </summary>
        /// <param name="DiscountID">Discount identifier</param>
        /// <param name="DiscountType">The discount type</param>
        /// <param name="DiscountRequirement">The discount requirement</param>
        /// <param name="Name">The name</param>
        /// <param name="UsePercentage">A value indicating whether to use percentage</param>
        /// <param name="DiscountPercentage">The discount percentage</param>
        /// <param name="DiscountAmount">The discount amount</param>
        /// <param name="StartDate">The discount start date and time</param>
        /// <param name="EndDate">The discount end date and time</param>
        /// <param name="RequiresCouponCode">The value indicating whether discount requires coupon code</param>
        /// <param name="CouponCode">The coupon code</param>
        /// <param name="Deleted">A value indicating whether the entity has been deleted</param>
        /// <returns>Discount</returns>
        public static Discount UpdateDiscount(int DiscountID, DiscountTypeEnum DiscountType,
            DiscountRequirementEnum DiscountRequirement, string Name, bool UsePercentage,
            decimal DiscountPercentage, decimal DiscountAmount, DateTime StartDate,
            DateTime EndDate, bool RequiresCouponCode, string CouponCode, bool Deleted)
        {
            if (StartDate.CompareTo(EndDate) >= 0)
                throw new NopException("Start date should be less then expiration date");

            //if ((DiscountType == DiscountTypeEnum.AssignedToWholeOrder) && !RequiresCouponCode)
            //{
            //    throw new NopException("Discounts assigned to whole order should require coupon code");
            //}

            //if ((DiscountType == DiscountTypeEnum.AssignedToWholeOrder)
            //    && RequiresCouponCode
            //    && String.IsNullOrEmpty(CouponCode))
            //{
            //    throw new NopException("Discounts assigned to whole order should require coupon code. Coupon code could not be empty.");
            //}

            if (RequiresCouponCode && String.IsNullOrEmpty(CouponCode))
            {
                throw new NopException("Discount requires coupon code. Coupon code could not be empty.");
            }

            DBDiscount dbItem = DBProviderManager<DBDiscountProvider>.Provider.UpdateDiscount(DiscountID, (int)DiscountType,
                (int)DiscountRequirement, Name, UsePercentage, DiscountPercentage,
                DiscountAmount, StartDate, EndDate,
                RequiresCouponCode, CouponCode, Deleted);
            Discount discount = DBMapping(dbItem);

            if (DiscountManager.CacheEnabled)
            {
                NopCache.RemoveByPattern(DISCOUNTS_PATTERN_KEY);
            }
            return discount;
        }
예제 #25
0
        public Discount SaveInfo()
        {
            //discou tn type
            DiscountTypeEnum discountType = (DiscountTypeEnum)int.Parse(this.ddlDiscountType.SelectedItem.Value);

            //requirements
            DiscountRequirementEnum discountRequirement = (DiscountRequirementEnum)int.Parse(this.ddlDiscountRequirement.SelectedItem.Value);

            int[] restrictedProductVariantIds = new int[0];

            if (discountRequirement == DiscountRequirementEnum.HasAllOfTheseProductVariantsInTheCart ||
                discountRequirement == DiscountRequirementEnum.HasOneOfTheseProductVariantsInTheCart ||
                discountRequirement == DiscountRequirementEnum.HadPurchasedAllOfTheseProductVariants ||
                discountRequirement == DiscountRequirementEnum.HadPurchasedOneOfTheseProductVariants)
            {
                restrictedProductVariantIds = ParseListOfRestrictedProductVariants(txtRestrictedProductVariants.Text);
            }
            decimal requirementSpentAmount = txtRequirementSpentAmount.Value;

            int requirementBillingCountryIs  = int.Parse(this.ddlRequirementBillingCountryIs.SelectedItem.Value);
            int requirementShippingCountryIs = int.Parse(this.ddlRequirementShippingCountryIs.SelectedItem.Value);

            //limitation
            DiscountLimitationEnum discountLimitation = (DiscountLimitationEnum)int.Parse(this.ddlDiscountLimitation.SelectedItem.Value);
            int limitationTimes = txtLimitationTimes.Value;

            string  name               = txtName.Text.Trim();
            bool    usePercentage      = cbUsePercentage.Checked;
            decimal discountPercentage = txtDiscountPercentage.Value;
            decimal discountAmount     = txtDiscountAmount.Value;
            bool    requiresCouponCode = cbRequiresCouponCode.Checked;
            string  couponCode         = txtCouponCode.Text.Trim();

            //dates
            if (!ctrlStartDatePicker.SelectedDate.HasValue)
            {
                throw new NopException("Start date is not set");
            }
            DateTime discountStartDate = ctrlStartDatePicker.SelectedDate.Value;

            if (!ctrlEndDatePicker.SelectedDate.HasValue)
            {
                throw new NopException("End date is not set");
            }
            DateTime discountEndDate = ctrlEndDatePicker.SelectedDate.Value;

            discountStartDate = DateTime.SpecifyKind(discountStartDate, DateTimeKind.Utc);
            discountEndDate   = DateTime.SpecifyKind(discountEndDate, DateTimeKind.Utc);

            if (discountStartDate.CompareTo(discountEndDate) >= 0)
            {
                throw new NopException("Start date should be less then expiration date");
            }

            if (requiresCouponCode && String.IsNullOrEmpty(couponCode))
            {
                throw new NopException("Discount requires coupon code. Coupon code could not be empty.");
            }


            Discount discount = this.DiscountService.GetDiscountById(this.DiscountId);

            if (discount != null)
            {
                discount.DiscountTypeId               = (int)discountType;
                discount.DiscountRequirementId        = (int)discountRequirement;
                discount.RequirementSpentAmount       = requirementSpentAmount;
                discount.RequirementBillingCountryIs  = requirementBillingCountryIs;
                discount.RequirementShippingCountryIs = requirementShippingCountryIs;
                discount.DiscountLimitationId         = (int)discountLimitation;
                discount.LimitationTimes              = limitationTimes;
                discount.Name               = name;
                discount.UsePercentage      = usePercentage;
                discount.DiscountPercentage = discountPercentage;
                discount.DiscountAmount     = discountAmount;
                discount.StartDate          = discountStartDate;
                discount.EndDate            = discountEndDate;
                discount.RequiresCouponCode = requiresCouponCode;
                discount.CouponCode         = couponCode;
                this.DiscountService.UpdateDiscount(discount);

                //discount requirements
                foreach (CustomerRole customerRole in discount.CustomerRoles)
                {
                    this.CustomerService.RemoveDiscountFromCustomerRole(customerRole.CustomerRoleId, discount.DiscountId);
                }
                foreach (int customerRoleId in CustomerRoleMappingControl.SelectedCustomerRoleIds)
                {
                    this.CustomerService.AddDiscountToCustomerRole(customerRoleId, discount.DiscountId);
                }

                foreach (ProductVariant pv in this.ProductService.GetProductVariantsRestrictedByDiscountId(discount.DiscountId))
                {
                    this.DiscountService.RemoveDiscountRestriction(pv.ProductVariantId, discount.DiscountId);
                }
                foreach (int productVariantId in restrictedProductVariantIds)
                {
                    this.DiscountService.AddDiscountRestriction(productVariantId, discount.DiscountId);
                }
            }
            else
            {
                discount = new Discount()
                {
                    DiscountTypeId               = (int)discountType,
                    DiscountRequirementId        = (int)discountRequirement,
                    RequirementSpentAmount       = requirementSpentAmount,
                    RequirementBillingCountryIs  = requirementBillingCountryIs,
                    RequirementShippingCountryIs = requirementShippingCountryIs,
                    DiscountLimitationId         = (int)discountLimitation,
                    LimitationTimes              = limitationTimes,
                    Name               = name,
                    UsePercentage      = usePercentage,
                    DiscountPercentage = discountPercentage,
                    DiscountAmount     = discountAmount,
                    StartDate          = discountStartDate,
                    EndDate            = discountEndDate,
                    RequiresCouponCode = requiresCouponCode,
                    CouponCode         = couponCode
                };
                this.DiscountService.InsertDiscount(discount);

                //discount requirements
                foreach (int customerRoleId in CustomerRoleMappingControl.SelectedCustomerRoleIds)
                {
                    this.CustomerService.AddDiscountToCustomerRole(customerRoleId, discount.DiscountId);
                }

                foreach (int productVariantId in restrictedProductVariantIds)
                {
                    this.DiscountService.AddDiscountRestriction(productVariantId, discount.DiscountId);
                }
            }

            return(discount);
        }