"Add To Cart" button in Compare List

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Hi,

I have been trying plenty way to add "Add to Cart" button for each products in the compare list page, but I could not figure it out.
Could somebody please help me?

-Thanks,

Joel.
13 years ago
I finally found how to implement my requirement. Here is what I did just in case some people have the same requirement:

I based the changes on HomeProductsPages. I used productBox2 to do the display.


1) We need to make the compare to have the 3 products persistent.

-> Change CompareProducts.ascx.cs  with:

      protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               BindData();
           }
       }

       private void BindData()
       {
           var products = this.ProductService.GetAllProductsDisplayedOnHomePage();
           if (products.Count > 0)
           {
               dlCatalog.DataSource = products;
               dlCatalog.DataBind();
           }
           else
           {
               this.Visible = false;
           }
       }



2) Change CompareProducts.ascx with:
<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.CompareProductsControl"
    CodeBehind="CompareProducts.ascx.cs" %>
<%@ Register TagPrefix="nopCommerce" TagName="ProductBox1" Src="~/Modules/ProductBox2.ascx" %>
<div class="compare-products">
    <div class="page-title">
       <h1><%=GetLocaleResourceString("Products.CompareProducts")%></h1>
    </div>
    <div class="clear">
    </div>
    <div class="body">
        <table cellpadding="0" cellspacing="0" border="0" id="tblCompareProducts" runat="server"
           class="compare-products-table">
        </table>

          <div class="clear">
    </div>
    <div class="product-grid">
       <asp:DataList ID="dlCatalog" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
           RepeatLayout="Table" ItemStyle-CssClass="item-box">
           <ItemTemplate>
               <nopCommerce:ProductBox1 ID="ctrlProductBox" Product='<%# Container.DataItem %>'
                   runat="server" />

           </ItemTemplate>
       </asp:DataList>
    </div>
</div>

3) Change in productBox2.ascx.cs:
added:
               var productSpecificationAttributes = this.SpecificationAttributeService.GetProductSpecificationAttributesByProductId(product.ProductId, null, true);
               if (productSpecificationAttributes.Count > 0)
               {
                   this.Visible = true;
                   rptrProductSpecification.DataSource = productSpecificationAttributes;
                   rptrProductSpecification.DataBind();
               }


4) Change in productBox2.ascx

…..
  <div class="description">
       <asp:Literal runat="server" ID="lShortDescription"></asp:Literal>
    </div>
<div class="productspec-box">
    <table width="100%">
       <tbody>
           <asp:Repeater ID="rptrProductSpecification" runat="server">
               <ItemTemplate>
                   <tr>
                       <td width="30%" style="padding: 2px">
                           <b><%#Server.HtmlEncode(((SpecificationAttribute)Eval("SpecificationAttribute")).LocalizedName)%></b>
                       </td>
                       <td width="70%" style="padding: 2px">
                           <%#Server.HtmlEncode(((SpecificationAttributeOption)Eval("SpecificationAttributeOption")).LocalizedName)%>
                       </td>
                   </tr>
               </ItemTemplate>
           </asp:Repeater>
       </tbody>
    </table>
</div>
    <div class="clear">
    </div>

    <div class="add-info">
       <div class="prices">
           <nopCommerce:ProductPrice2 ID="ctrlProductPrice" runat="server" ProductID='<%#Eval("ProductId") %>'/>

…...


-> Build Solution
-> FTP bin/NopCommerceStore.dll



5) Change the menu options
https://www.nopcommerce.com/boards/t/5283/how-to-change-menu-options.aspx

Disabled “New Products”
Add in HeaderMenu.ascx:

<li><a href="<%=Page.ResolveUrl("~/compareproducts.aspx")%>">
           <%=GetLocaleResourceString("Products.CompareProducts")%></a> </li>


6) Change resource in admin
Products.CompareProductsList -> Compare Produtcs (Information box)
Products.AddToCompareList -> Compare (button)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.