Compare product bug in 1.4

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 years ago
Simple to recreate,

compare from the demo data:

Toshiba Satellite A305-S6908 15.4-Inch Laptop

and

ASUS Eee PC 900HA 8.9-Inch Netbook Black

When items are different, they are not compared but shown separate.
14 years ago
Thanks. It'll be fixed
14 years ago
Can you give a code to fix it?
Whether this link http://www.nopdownloads.com/downloads/nopCommerce_1.40.rar has a fix?
Thank you.
14 years ago
This release doesn't have the fix.

Fixed CreateCompareTable function (Modules\CopareProducts.ascx.cx) below:


protected void CreateCompareTable()
        {
            this.tblCompareProducts.Rows.Clear();
            this.tblCompareProducts.Width = "100%";
            ProductCollection compareProducts = ProductManager.GetCompareProducts();
            if (compareProducts.Count > 0)
            {
                HtmlTableRow headerRow = new HtmlTableRow();
                this.AddCell(headerRow, " ");
                HtmlTableRow productNameRow = new HtmlTableRow();
                this.AddCell(productNameRow, " ");
                HtmlTableRow priceRow = new HtmlTableRow();
                HtmlTableCell cell = new HtmlTableCell();
                cell.InnerText = GetLocaleResourceString("Products.CompareProductsPrice");
                cell.Align = "center";
                priceRow.Cells.Add(cell);

                List<int> specificationAttributeIDs = new List<int>();
                foreach (Product product in compareProducts)
                {
                    ProductSpecificationAttributeCollection productSpecificationAttributes = SpecificationAttributeManager.GetProductSpecificationAttributesByProductID(product.ProductID, null, true);
                    foreach (ProductSpecificationAttribute attribute in productSpecificationAttributes)
                        if (!specificationAttributeIDs.Contains(attribute.SpecificationAttribute.SpecificationAttributeID))
                            specificationAttributeIDs.Add(attribute.SpecificationAttribute.SpecificationAttributeID);
                }

                foreach (Product product in compareProducts)
                {
                    HtmlTableCell headerCell = new HtmlTableCell();
                    HtmlGenericControl headerCellDiv = new HtmlGenericControl("div");
                    Button 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 = "removeButton";
                    btnRemoveFromList.ID = "btnRemoveFromList" + product.ProductID.ToString();
                    headerCellDiv.Controls.Add(btnRemoveFromList);

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

                    HtmlImage productImage = new HtmlImage();
                    productImage.Border = 0;
                    //productImage.Align = "center";
                    productImage.Alt = "Product image";
                    ProductPictureCollection productPictures = product.ProductPictures;
                    if (productPictures.Count > 0)
                        productImage.Src = PictureManager.GetPictureUrl(productPictures[0].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);
                    HtmlTableCell productNameCell = new HtmlTableCell();
                    HyperLink productLink = new HyperLink();
                    productLink.Text = Server.HtmlEncode(product.Name);
                    productLink.NavigateUrl = SEOHelper.GetProductURL(product);
                    productLink.Attributes.Add("class", "link");
                    productNameCell.Align = "center";
                    productNameCell.Controls.Add(productLink);
                    productNameRow.Cells.Add(productNameCell);
                    HtmlTableCell priceCell = new HtmlTableCell();
                    priceCell.Align = "center";
                    ProductVariantCollection productVariantCollection = product.ProductVariants;
                    if (productVariantCollection.Count > 0)
                    {
                        ProductVariant productVariant = productVariantCollection[0];




                        decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                        decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                        priceCell.InnerText = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                    }
                    priceRow.Cells.Add(priceCell);
                }
                productNameRow.Attributes.Add("class", "productName");
                priceRow.Attributes.Add("class", "productPrice");
                this.tblCompareProducts.Rows.Add(headerRow);
                this.tblCompareProducts.Rows.Add(productNameRow);
                this.tblCompareProducts.Rows.Add(priceRow);

                foreach (int specificationAttributeID in specificationAttributeIDs)
                {
                    SpecificationAttribute specificationAttribute = SpecificationAttributeManager.GetSpecificationAttributeByID(specificationAttributeID);
                    HtmlTableRow productRow = new HtmlTableRow();
                    this.AddCell(productRow, Server.HtmlEncode(specificationAttribute.Name)).Align = "left";

                    foreach (Product product2 in compareProducts)
                    {
                        HtmlTableCell productCell = new HtmlTableCell();





                        {
                            ProductSpecificationAttributeCollection productSpecificationAttributes2 = SpecificationAttributeManager.GetProductSpecificationAttributesByProductID(product2.ProductID, null, true);
                            foreach (ProductSpecificationAttribute psa2 in productSpecificationAttributes2)
                            {
                                if (specificationAttribute.SpecificationAttributeID == psa2.SpecificationAttribute.SpecificationAttributeID)
                                {
                                    productCell.InnerHtml = (!String.IsNullOrEmpty(psa2.SpecificationAttributeOption.Name)) ? Server.HtmlEncode(psa2.SpecificationAttributeOption.Name) : "&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++)
                {
                    HtmlTableRow 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;
            }
        }
14 years ago
Thank you.
14 years ago
Hello.
I replaced the code into Modules/CompareProducts.ascx.cs but i get the same result.
can you help me?
Thanks
Paulo Lima
14 years ago
docpor
Don't forget to recompile the solution
14 years ago
It's working.
Thanks
Paulo
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.