protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                var checkoutAttribute = this.CheckoutAttributeService.GetCheckoutAttributeById(this.CheckoutAttributeId);
                if (checkoutAttribute != null)
                {
                    var cav = new CheckoutAttributeValue()
                    {
                        CheckoutAttributeId = checkoutAttribute.CheckoutAttributeId,
                        Name = txtNewName.Text,
                        PriceAdjustment = txtNewPriceAdjustment.Value,
                        WeightAdjustment = txtNewWeightAdjustment.Value,
                        IsPreSelected = cbNewIsPreSelected.Checked,
                        DisplayOrder = txtNewDisplayOrder.Value
                    };
                    this.CheckoutAttributeService.InsertCheckoutAttributeValue(cav);

                    SaveLocalizableContent(cav);

                    string url = string.Format("CheckoutAttributeDetails.aspx?CheckoutAttributeID={0}&TabID={1}", checkoutAttribute.CheckoutAttributeId, "pnlValues");
                    Response.Redirect(url);
                }
            }
            catch (Exception exc)
            {
                processAjaxError(exc);
            }
        }
        private static CheckoutAttributeValue DBMapping(DBCheckoutAttributeValue dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            var item = new CheckoutAttributeValue();

            item.CheckoutAttributeValueId = dbItem.CheckoutAttributeValueId;
            item.CheckoutAttributeId      = dbItem.CheckoutAttributeId;
            item.Name             = dbItem.Name;
            item.PriceAdjustment  = dbItem.PriceAdjustment;
            item.WeightAdjustment = dbItem.WeightAdjustment;
            item.IsPreSelected    = dbItem.IsPreSelected;
            item.DisplayOrder     = dbItem.DisplayOrder;

            return(item);
        }
        /// <summary>
        /// Inserts a checkout attribute value
        /// </summary>
        /// <param name="checkoutAttributeValue">Checkout attribute value</param>
        public void InsertCheckoutAttributeValue(CheckoutAttributeValue checkoutAttributeValue)
        {
            if (checkoutAttributeValue == null)
            {
                throw new ArgumentNullException("checkoutAttributeValue");
            }

            checkoutAttributeValue.Name = CommonHelper.EnsureNotNull(checkoutAttributeValue.Name);
            checkoutAttributeValue.Name = CommonHelper.EnsureMaximumLength(checkoutAttributeValue.Name, 100);



            _context.CheckoutAttributeValues.AddObject(checkoutAttributeValue);
            _context.SaveChanges();

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(CHECKOUTATTRIBUTES_PATTERN_KEY);
                _cacheManager.RemoveByPattern(CHECKOUTATTRIBUTEVALUES_PATTERN_KEY);
            }
        }
        protected void SaveLocalizableContentGrid(CheckoutAttributeValue cav)
        {
            if (cav == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (GridViewRow row in gvValues.Rows)
            {
                Repeater rptrLanguageDivs2 = row.FindControl("rptrLanguageDivs2") as Repeater;
                if (rptrLanguageDivs2 != null)
                {
                    HiddenField hfCheckoutAttributeValueId = row.FindControl("hfCheckoutAttributeValueId") as HiddenField;
                    int cavId = int.Parse(hfCheckoutAttributeValueId.Value);
                    if (cavId == cav.CheckoutAttributeValueId)
                    {
                        foreach (RepeaterItem item in rptrLanguageDivs2.Items)
                        {
                            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                            {
                                var txtLocalizedName = (TextBox)item.FindControl("txtLocalizedName");
                                var lblLanguageId = (Label)item.FindControl("lblLanguageId");

                                int languageId = int.Parse(lblLanguageId.Text);
                                string name = txtLocalizedName.Text;

                                bool allFieldsAreEmpty = string.IsNullOrEmpty(name);

                                var content = CheckoutAttributeManager.GetCheckoutAttributeValueLocalizedByCheckoutAttributeValueIdAndLanguageId(cav.CheckoutAttributeValueId, languageId);
                                if (content == null)
                                {
                                    if (!allFieldsAreEmpty && languageId > 0)
                                    {
                                        //only insert if one of the fields are filled out (avoid too many empty records in db...)
                                        content = CheckoutAttributeManager.InsertCheckoutAttributeValueLocalized(cav.CheckoutAttributeValueId,
                                            languageId, name);
                                    }
                                }
                                else
                                {
                                    if (languageId > 0)
                                    {
                                        content = CheckoutAttributeManager.UpdateCheckoutAttributeValueLocalized(content.CheckoutAttributeValueLocalizedId,
                                            content.CheckoutAttributeValueId, languageId, name);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets checkout attribute value price
        /// </summary>
        /// <param name="cav">Checkout attribute value</param>
        /// <param name="includingTax">A value indicating whether calculated price should include tax</param>
        /// <param name="customer">Customer</param>
        /// <param name="taxRate">Tax rate</param>
        /// <param name="error">Error</param>
        /// <returns>Price</returns>
        public static decimal GetCheckoutAttributePrice(CheckoutAttributeValue cav,
            bool includingTax, Customer customer, out decimal taxRate, ref string error)
        {
            if (cav == null)
                throw new ArgumentNullException("cav");

            taxRate = decimal.Zero;

            decimal price = cav.PriceAdjustment;
            if (cav.CheckoutAttribute.IsTaxExempt)
            {
                return price;
            }

            bool priceIncludesTax = TaxManager.PricesIncludeTax;
            int taxClassId = cav.CheckoutAttribute.TaxCategoryId;
            return GetPrice(null, taxClassId, price, includingTax, customer,
                priceIncludesTax, out taxRate, ref error);
        }
        protected void SaveLocalizableContent(CheckoutAttributeValue cav)
        {
            if (cav == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (RepeaterItem item in rptrLanguageDivs.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var txtNewLocalizedName = (TextBox)item.FindControl("txtNewLocalizedName");
                    var lblLanguageId = (Label)item.FindControl("lblLanguageId");

                    int languageId = int.Parse(lblLanguageId.Text);
                    string name = txtNewLocalizedName.Text;

                    bool allFieldsAreEmpty = string.IsNullOrEmpty(name);

                    var content = this.CheckoutAttributeService.GetCheckoutAttributeValueLocalizedByCheckoutAttributeValueIdAndLanguageId(cav.CheckoutAttributeValueId, languageId);
                    if (content == null)
                    {
                        if (!allFieldsAreEmpty && languageId > 0)
                        {
                            //only insert if one of the fields are filled out (avoid too many empty records in db...)
                            content = new CheckoutAttributeValueLocalized()
                            {
                                CheckoutAttributeValueId = cav.CheckoutAttributeValueId,
                                LanguageId = languageId,
                                Name = name
                            };
                            this.CheckoutAttributeService.InsertCheckoutAttributeValueLocalized(content);
                        }
                    }
                    else
                    {
                        if (languageId > 0)
                        {
                            content.LanguageId = languageId;
                            content.Name = name;
                            this.CheckoutAttributeService.UpdateCheckoutAttributeValueLocalized(content);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Gets checkout attribute value price
 /// </summary>
 /// <param name="cav">Checkout attribute value</param>
 /// <param name="includingTax">A value indicating whether calculated price should include tax</param>
 /// <param name="customer">Customer</param>
 /// <param name="error">Error</param>
 /// <returns>Price</returns>
 public static decimal GetCheckoutAttributePrice(CheckoutAttributeValue cav,
     bool includingTax, Customer customer, ref string error)
 {
     decimal taxRate = decimal.Zero;
     return GetCheckoutAttributePrice(cav, includingTax, customer,
         out taxRate, ref error);
 }
Esempio n. 8
0
 /// <summary>
 /// Gets checkout attribute value price
 /// </summary>
 /// <param name="cav">Checkout attribute value</param>
 /// <param name="includingTax">A value indicating whether calculated price should include tax</param>
 /// <param name="customer">Customer</param>
 /// <returns>Price</returns>
 public static decimal GetCheckoutAttributePrice(CheckoutAttributeValue cav, 
     bool includingTax, Customer customer)
 {
     string error = string.Empty;
     return GetCheckoutAttributePrice(cav,
         includingTax, customer, ref error);
 }
Esempio n. 9
0
 /// <summary>
 /// Gets checkout attribute value price
 /// </summary>
 /// <param name="cav">Checkout attribute value</param>
 /// <param name="customer">Customer</param>
 /// <param name="error">Error</param>
 /// <returns>Price</returns>
 public static decimal GetCheckoutAttributePrice(CheckoutAttributeValue cav, 
     Customer customer, ref string error)
 {
     bool includingTax = false;
     switch (NopContext.Current.TaxDisplayType)
     {
         case TaxDisplayTypeEnum.ExcludingTax:
             includingTax = false;
             break;
         case TaxDisplayTypeEnum.IncludingTax:
             includingTax = true;
             break;
     }
     return GetCheckoutAttributePrice(cav,
         includingTax, customer, ref error);
 }
Esempio n. 10
0
 /// <summary>
 /// Gets checkout attribute value price
 /// </summary>
 /// <param name="cav">Checkout attribute value</param>
 /// <returns>Price</returns>
 public static decimal GetCheckoutAttributePrice(CheckoutAttributeValue cav)
 {
     var customer = NopContext.Current.User;
     return GetCheckoutAttributePrice(cav, customer);
 }
Esempio n. 11
0
 /// <summary>
 /// Gets checkout attribute value price
 /// </summary>
 /// <param name="cav">Checkout attribute value</param>
 /// <param name="customer">Customer</param>
 /// <returns>Price</returns>
 public decimal GetCheckoutAttributePrice(CheckoutAttributeValue cav, 
     Customer customer)
 {
     string error = string.Empty;
     return GetCheckoutAttributePrice(cav, customer, ref error);
 }