Example #1
0
        public SpecificationAttribute SaveInfo()
        {
            SpecificationAttribute specificationAttribute = SpecificationAttributeManager.GetSpecificationAttributeById(this.SpecificationAttributeId, 0);

            if (specificationAttribute != null)
            {
                specificationAttribute = SpecificationAttributeManager.UpdateSpecificationAttribute(specificationAttribute.SpecificationAttributeId, txtName.Text, txtDisplayOrder.Value);
            }
            else
            {
                specificationAttribute = SpecificationAttributeManager.InsertSpecificationAttribute(txtName.Text, txtDisplayOrder.Value);
            }

            SaveLocalizableContent(specificationAttribute);

            return(specificationAttribute);
        }
        private void BindData()
        {
            var specificationAttribute = SpecificationAttributeManager.GetSpecificationAttributeById(this.SpecificationAttributeId);

            if (this.HasLocalizableContent)
            {
                var languages = this.GetLocalizableLanguagesSupported();
                rptrLanguageTabs.DataSource = languages;
                rptrLanguageTabs.DataBind();
                rptrLanguageDivs.DataSource = languages;
                rptrLanguageDivs.DataBind();
            }

            if (specificationAttribute != null)
            {
                this.txtName.Text          = specificationAttribute.Name;
                this.txtDisplayOrder.Value = specificationAttribute.DisplayOrder;
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                var specificationAttribute = SpecificationAttributeManager.GetSpecificationAttributeById(this.SpecificationAttributeId);
                if (specificationAttribute != null)
                {
                    var sao = SpecificationAttributeManager.InsertSpecificationAttributeOption(specificationAttribute.SpecificationAttributeId,
                                                                                               txtNewOptionName.Text, txtNewOptionDisplayOrder.Value);

                    SaveLocalizableContent(sao);

                    string url = string.Format("SpecificationAttributeDetails.aspx?SpecificationAttributeID={0}&TabID={1}", specificationAttribute.SpecificationAttributeId, "pnlOptions");
                    Response.Redirect(url);
                }
            }
            catch (Exception exc)
            {
                processAjaxError(exc);
            }
        }
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                SpecificationAttribute specificationAttribute = SpecificationAttributeManager.GetSpecificationAttributeById(this.SpecificationAttributeId);
                if (specificationAttribute != null)
                {
                    SpecificationAttributeManager.DeleteSpecificationAttribute(this.SpecificationAttributeId);

                    CustomerActivityManager.InsertActivity(
                        "DeleteSpecAttribute",
                        GetLocaleResourceString("ActivityLog.DeleteSpecAttribute"),
                        specificationAttribute.Name);
                }

                Response.Redirect("SpecificationAttributes.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }
        protected void gvProductSpecificationAttributes_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ProductSpecificationAttribute productSpecificationAttribute = (ProductSpecificationAttribute)e.Row.DataItem;

                Button btnUpdate = e.Row.FindControl("btnUpdate") as Button;
                if (btnUpdate != null)
                {
                    btnUpdate.CommandArgument = e.Row.RowIndex.ToString();
                }

                SpecificationAttributeOption sao      = SpecificationAttributeManager.GetSpecificationAttributeOptionById(productSpecificationAttribute.SpecificationAttributeOptionId);
                SpecificationAttribute       sa       = SpecificationAttributeManager.GetSpecificationAttributeById(sao.SpecificationAttributeId);
                Literal lblSpecificationAttributeName = e.Row.FindControl("lblSpecificationAttributeName") as Literal;
                lblSpecificationAttributeName.Text = sa.Name;

                DropDownList ddlSpecificationAttributeOption = e.Row.FindControl("ddlSpecificationAttributeOption") as DropDownList;
                ddlSpecificationAttributeOption.Items.Clear();
                SpecificationAttributeOptionCollection saoCol = SpecificationAttributeManager.GetSpecificationAttributeOptionsBySpecificationAttribute(sao.SpecificationAttributeId);
                foreach (SpecificationAttributeOption sao1 in saoCol)
                {
                    ListItem item = new ListItem(sao1.Name, sao1.SpecificationAttributeOptionId.ToString());
                    ddlSpecificationAttributeOption.Items.Add(item);
                    if (productSpecificationAttribute.SpecificationAttributeOptionId == sao1.SpecificationAttributeOptionId)
                    {
                        item.Selected = true;
                    }
                }

                CheckBox chkAllowFiltering = e.Row.FindControl("chkAllowFiltering") as CheckBox;
                chkAllowFiltering.Checked = productSpecificationAttribute.AllowFiltering;

                CheckBox chkShowOnProductPage = e.Row.FindControl("chkShowOnProductPage") as CheckBox;
                chkShowOnProductPage.Checked = productSpecificationAttribute.ShowOnProductPage;
            }
        }
        private void BindData()
        {
            var specificationAttribute = SpecificationAttributeManager.GetSpecificationAttributeById(this.SpecificationAttributeId);

            if (specificationAttribute != null)
            {
                pnlData.Visible    = true;
                pnlMessage.Visible = false;

                if (this.HasLocalizableContent)
                {
                    var languages = this.GetLocalizableLanguagesSupported();
                    rptrLanguageTabs.DataSource = languages;
                    rptrLanguageTabs.DataBind();
                    rptrLanguageDivs.DataSource = languages;
                    rptrLanguageDivs.DataBind();
                }

                var saoCol = SpecificationAttributeManager.GetSpecificationAttributeOptionsBySpecificationAttribute(SpecificationAttributeId);
                if (saoCol.Count > 0)
                {
                    grdSpecificationAttributeOptions.Visible    = true;
                    grdSpecificationAttributeOptions.DataSource = saoCol;
                    grdSpecificationAttributeOptions.DataBind();
                }
                else
                {
                    grdSpecificationAttributeOptions.Visible = false;
                }
            }
            else
            {
                pnlData.Visible    = false;
                pnlMessage.Visible = true;
                lblMessage.Text    = GetLocaleResourceString("Admin.SpecificationAttributeOptions.AvailableAfterSaving");
            }
        }
Example #7
0
        protected void GenerateCompareTable()
        {
            this.tblCompareProducts.Rows.Clear();
            this.tblCompareProducts.Width = "100%";
            var compareProducts = ProductManager.GetCompareProducts();

            if (compareProducts.Count > 0)
            {
                var headerRow = new HtmlTableRow();
                this.AddCell(headerRow, " ");
                var productNameRow = new HtmlTableRow();
                this.AddCell(productNameRow, " ");
                var priceRow = new HtmlTableRow();
                var cell     = new HtmlTableCell();
                cell.InnerText = GetLocaleResourceString("Products.CompareProductsPrice");
                cell.Align     = "center";
                priceRow.Cells.Add(cell);

                var specificationAttributeIds = new List <int>();
                foreach (var product in compareProducts)
                {
                    var productSpecificationAttributes = SpecificationAttributeManager.GetProductSpecificationAttributesByProductId(product.ProductId, null, true);
                    foreach (var attribute in productSpecificationAttributes)
                    {
                        if (!specificationAttributeIds.Contains(attribute.SpecificationAttribute.SpecificationAttributeId))
                        {
                            specificationAttributeIds.Add(attribute.SpecificationAttribute.SpecificationAttributeId);
                        }
                    }
                }

                foreach (var product in compareProducts)
                {
                    var headerCell        = new HtmlTableCell();
                    var headerCellDiv     = new HtmlGenericControl("div");
                    var btnRemoveFromList = new Button();
                    btnRemoveFromList.ToolTip          = GetLocaleResourceString("Products.CompareProductsRemoveFromList");
                    btnRemoveFromList.Text             = GetLocaleResourceString("Products.CompareProductsRemoveFromList");
                    btnRemoveFromList.CommandName      = "Remove";
                    btnRemoveFromList.Command         += new CommandEventHandler(this.btnRemoveFromList_Command);
                    btnRemoveFromList.CommandArgument  = product.ProductId.ToString();
                    btnRemoveFromList.CausesValidation = false;
                    btnRemoveFromList.CssClass         = "remove-button";
                    btnRemoveFromList.ID = "btnRemoveFromList" + product.ProductId.ToString();
                    headerCellDiv.Controls.Add(btnRemoveFromList);

                    var productImagePanel = new HtmlGenericControl("p");
                    productImagePanel.Attributes.Add("align", "center");

                    var productImage = new HtmlImage();
                    productImage.Border = 0;
                    //productImage.Align = "center";
                    productImage.Alt = "Product image";
                    var picture = product.DefaultPicture;
                    if (picture != null)
                    {
                        productImage.Src = PictureManager.GetPictureUrl(picture, SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125), true);
                    }
                    else
                    {
                        productImage.Src = PictureManager.GetDefaultPictureUrl(SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125));
                    }
                    productImagePanel.Controls.Add(productImage);
                    headerCellDiv.Controls.Add(productImagePanel);

                    headerCell.Controls.Add(headerCellDiv);
                    headerRow.Cells.Add(headerCell);
                    var productNameCell = new HtmlTableCell();
                    var productLink     = new HyperLink();
                    productLink.Text        = Server.HtmlEncode(product.LocalizedName);
                    productLink.NavigateUrl = SEOHelper.GetProductUrl(product);
                    productLink.Attributes.Add("class", "link");
                    productNameCell.Align = "center";
                    productNameCell.Controls.Add(productLink);
                    productNameRow.Cells.Add(productNameCell);
                    var priceCell = new HtmlTableCell();
                    priceCell.Align = "center";
                    var productVariantCollection = product.ProductVariants;
                    if (productVariantCollection.Count > 0)
                    {
                        var     productVariant = productVariantCollection[0];
                        decimal taxRate        = decimal.Zero;
                        decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false), out taxRate);
                        decimal finalPriceWithoutDiscount     = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                        priceCell.InnerText = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                    }
                    priceRow.Cells.Add(priceCell);
                }
                productNameRow.Attributes.Add("class", "product-name");
                priceRow.Attributes.Add("class", "productPrice");
                this.tblCompareProducts.Rows.Add(headerRow);
                this.tblCompareProducts.Rows.Add(productNameRow);
                if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                    (NopContext.Current.User != null &&
                     !NopContext.Current.User.IsGuest))
                {
                    this.tblCompareProducts.Rows.Add(priceRow);
                }

                foreach (int specificationAttributeId in specificationAttributeIds)
                {
                    var specificationAttribute = SpecificationAttributeManager.GetSpecificationAttributeById(specificationAttributeId);
                    var productRow             = new HtmlTableRow();
                    this.AddCell(productRow, Server.HtmlEncode(specificationAttribute.LocalizedName)).Align = "left";

                    foreach (var product2 in compareProducts)
                    {
                        var productCell = new HtmlTableCell();
                        {
                            var productSpecificationAttributes2 = SpecificationAttributeManager.GetProductSpecificationAttributesByProductId(product2.ProductId, null, true);
                            foreach (var psa2 in productSpecificationAttributes2)
                            {
                                if (specificationAttribute.SpecificationAttributeId == psa2.SpecificationAttribute.SpecificationAttributeId)
                                {
                                    productCell.InnerHtml = (!String.IsNullOrEmpty(psa2.SpecificationAttributeOption.LocalizedName)) ? Server.HtmlEncode(psa2.SpecificationAttributeOption.LocalizedName) : "&nbsp;";
                                }
                            }
                        }
                        productCell.Align  = "center";
                        productCell.VAlign = "top";
                        productRow.Cells.Add(productCell);
                    }
                    this.tblCompareProducts.Rows.Add(productRow);
                }

                string width = Math.Round((decimal)(90M / compareProducts.Count), 0).ToString() + "%";
                for (int i = 0; i < this.tblCompareProducts.Rows.Count; i++)
                {
                    var row = this.tblCompareProducts.Rows[i];
                    for (int j = 1; j < row.Cells.Count; j++)
                    {
                        if (j == (row.Cells.Count - 1))
                        {
                            row.Cells[j].Style.Add("width", width);
                            row.Cells[j].Style.Add("text-align", "center");
                        }
                        else
                        {
                            row.Cells[j].Style.Add("width", width);
                            row.Cells[j].Style.Add("text-align", "center");
                        }
                    }
                }
            }
            else
            {
                btnClearCompareProductsList.Visible = false;
                tblCompareProducts.Visible          = false;
            }
        }