示例#1
0
        private void BindUsageHistory()
        {
            Discount discount = DiscountManager.GetDiscountById(this.DiscountId);

            if (discount != null)
            {
                gvDiscountUsageHistory.DataSource = DiscountManager.GetAllDiscountUsageHistoryEntries(discount.DiscountId, null, null);
                gvDiscountUsageHistory.DataBind();
            }
        }
示例#2
0
        private void BindData()
        {
            Discount discount = DiscountManager.GetDiscountById(this.DiscountId);

            if (discount != null)
            {
                CommonHelper.SelectListItem(this.ddlDiscountType, discount.DiscountTypeId);
                CommonHelper.SelectListItem(this.ddlDiscountRequirement, discount.DiscountRequirementId);
                this.txtRequirementSpentAmount.Value   = discount.RequirementSpentAmount;
                this.txtRestrictedProductVariants.Text = GenerateListOfRestrictedProductVariants(ProductManager.GetProductVariantsRestrictedByDiscountId(discount.DiscountId));
                CommonHelper.SelectListItem(this.ddlRequirementBillingCountryIs, discount.RequirementBillingCountryIs);
                CommonHelper.SelectListItem(this.ddlRequirementShippingCountryIs, discount.RequirementShippingCountryIs);
                CommonHelper.SelectListItem(this.ddlDiscountLimitation, discount.DiscountLimitationId);
                this.txtLimitationTimes.Value         = discount.LimitationTimes;
                this.txtName.Text                     = discount.Name;
                this.cbUsePercentage.Checked          = discount.UsePercentage;
                this.txtDiscountPercentage.Value      = discount.DiscountPercentage;
                this.txtDiscountAmount.Value          = discount.DiscountAmount;
                this.ctrlStartDatePicker.SelectedDate = discount.StartDate;
                this.ctrlEndDatePicker.SelectedDate   = discount.EndDate;
                this.cbRequiresCouponCode.Checked     = discount.RequiresCouponCode;
                this.txtCouponCode.Text               = discount.CouponCode;

                var        customerRoles    = discount.CustomerRoles;
                List <int> _customerRoleIds = new List <int>();
                foreach (CustomerRole customerRole in customerRoles)
                {
                    _customerRoleIds.Add(customerRole.CustomerRoleId);
                }
                CustomerRoleMappingControl.SelectedCustomerRoleIds = _customerRoleIds;
                CustomerRoleMappingControl.BindData();
            }
            else
            {
                List <int> _customerRoleIds = new List <int>();
                CustomerRoleMappingControl.SelectedCustomerRoleIds = _customerRoleIds;
                CustomerRoleMappingControl.BindData();

                this.pnlUsageHistory.Visible = false;
            }
        }
示例#3
0
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                Discount discount = DiscountManager.GetDiscountById(this.DiscountId);
                if (discount != null)
                {
                    DiscountManager.MarkDiscountAsDeleted(discount.DiscountId);
                    CustomerActivityManager.InsertActivity(
                        "DeleteDiscount",
                        GetLocaleResourceString("ActivityLog.DeleteDiscount"),
                        discount.Name);
                }

                Response.Redirect("Discounts.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }
示例#4
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);
        }
        /// <summary>
        /// Gets shopping cart shipping total
        /// </summary>
        /// <param name="cart">Cart</param>
        /// <param name="customer">Customer</param>
        /// <param name="includingTax">A value indicating whether calculated price should include tax</param>
        /// <param name="appliedDiscount">Applied discount</param>
        /// <param name="error">Error</param>
        /// <returns>Shipping total</returns>
        public static decimal?GetShoppingCartShippingTotal(ShoppingCart cart,
                                                           Customer customer, bool includingTax, out Discount appliedDiscount, ref string error)
        {
            decimal?shippingTotalWithoutDiscount   = null;
            decimal?shippingTotalWithDiscount      = null;
            decimal?shippingTotalWithDiscountTaxed = null;

            appliedDiscount = null;

            bool isFreeShipping = IsFreeShipping(cart, customer);

            if (isFreeShipping)
            {
                return(decimal.Zero);
            }

            ShippingOption lastShippingOption = null;

            if (customer != null)
            {
                lastShippingOption = customer.LastShippingOption;
            }

            if (lastShippingOption != null)
            {
                //use last shipping option (get from cache)
                //we have already discounted cache value
                shippingTotalWithDiscount = lastShippingOption.Rate;
                appliedDiscount           = DiscountManager.GetDiscountById(lastShippingOption.AppliedDiscountId);
            }
            else
            {
                //use fixed rate (if possible)
                Address shippingAddress = null;
                if (customer != null)
                {
                    shippingAddress = customer.ShippingAddress;
                }
                var ShipmentPackage = CreateShipmentPackage(cart, customer, shippingAddress);
                var shippingRateComputationMethods = ShippingRateComputationMethodManager.GetAllShippingRateComputationMethods(false);
                if (shippingRateComputationMethods.Count == 0)
                {
                    throw new NopException("Shipping rate computation method could not be loaded");
                }

                if (shippingRateComputationMethods.Count == 1)
                {
                    var shippingRateComputationMethod  = shippingRateComputationMethods[0];
                    var iShippingRateComputationMethod = Activator.CreateInstance(Type.GetType(shippingRateComputationMethod.ClassName)) as IShippingRateComputationMethod;

                    decimal?fixedRate = iShippingRateComputationMethod.GetFixedRate(ShipmentPackage);
                    if (fixedRate.HasValue)
                    {
                        decimal additionalShippingCharge = GetShoppingCartAdditionalShippingCharge(cart, customer);
                        shippingTotalWithoutDiscount = fixedRate.Value + additionalShippingCharge;
                        shippingTotalWithoutDiscount = Math.Round(shippingTotalWithoutDiscount.Value, 2);
                        decimal shippingTotalDiscount = GetShippingDiscount(customer, shippingTotalWithoutDiscount.Value, out appliedDiscount);
                        shippingTotalWithDiscount = shippingTotalWithoutDiscount.Value - shippingTotalDiscount;
                        if (shippingTotalWithDiscount.Value < decimal.Zero)
                        {
                            shippingTotalWithDiscount = decimal.Zero;
                        }
                    }
                }
            }

            if (!shippingTotalWithDiscount.HasValue)
            {
                error = "Shipping total could not be calculated";
            }
            else
            {
                shippingTotalWithDiscountTaxed = TaxManager.GetShippingPrice(shippingTotalWithDiscount.Value,
                                                                             includingTax,
                                                                             customer,
                                                                             ref error);

                shippingTotalWithDiscountTaxed = Math.Round(shippingTotalWithDiscountTaxed.Value, 2);
            }

            return(shippingTotalWithDiscountTaxed);
        }