Remove Add to Cart button on category pages

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
You should be able to achieve this simply by commenting out the code in productbox1.ascx  (and 2) - no c# changes needed

        
<!--<asp:Literal runat="server" ID="lShortDescription"></asp:Literal> -->
and
<!--   <asp:Button runat="server" ID="btnAddToCart" OnCommand="btnAddToCart_Click" Text="<% $NopResources:Products.AddToCart %>"
                ValidationGroup="ProductDetails" CommandArgument='<%# Eval("ProductId") %>' CssClass="productgridaddtocartbutton" /> -->
13 years ago
Hi,

Thanks for your feedback. When I comment the lines out as suggest it fails over with the below error. When I look in the .cs files after the comment out lines it show's error's on every line were there is a reference to the btnAddToCart.

It seemed straight forward to me but can't get ride of the add to cart button??

Cheers

[NullReferenceException: Object reference not set to an instance of an object.]
   NopSolutions.NopCommerce.Web.Modules.ProductBox1Control.BindData() in ProductBox1.ascx.cs:88
   NopSolutions.NopCommerce.Web.Modules.ProductBox1Control.DataBind() in ProductBox1.ascx.cs:53
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +125
   System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +459
   System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +54
   System.Web.UI.WebControls.BaseDataList.DataBind() +55
   NopSolutions.NopCommerce.Web.Templates.Categories.ProductsInGrid.BindData() in ProductsInGrid.ascx.cs:159
   NopSolutions.NopCommerce.Web.Templates.Categories.ProductsInGrid.Page_Load(Object sender, EventArgs e) in ProductsInGrid.ascx.cs:47
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
13 years ago
sorry - i tried it before i posted and it worked for me :(

try to comment it out with  <%   %>   instead of  <!-- -->

no point in me trying it this time   !!

alternatively, try surrounding the offending code in a div like so


<div style="visibility: hidden;" >

    your code


</div>
13 years ago
Hi,

Thanks again but the non of the comments seem to work. It seems really strange?
13 years ago
Hello all:  I also wanted to remove the Add To Cart button from the /Category page that lists all of the products for that Category.  I do not want to remove the button from the /Product Details page.  I am running 1.60.  My products have attributes.  I tried the code you suggested and it did not work for me.  Most surprising is that when adding the Visible="false" in the .ascx page - there was no effect.  The Add To Cart button is still visible.  I tested by doing the same for the Details button.  It worked, the button went away.  I tried many combination of adding your code and leaving it out.  It finally occurred to me that the action of both the Details and Add To Cart buttons by default with no code change will take you to the /Product Details page (not the cart page) when you have an assigned attribute.  No code change is necessary.  The pesky Add To Cart button is still there though. Any ideas?  It would be a great setting to add to the Category configuration.  Can the bool Direct add to cart allowed  be utilized to enable/disable the Add To Cart button on the Category / Product List page only?    Another thought though is that the user experience may be that they don't want to read details they just want to add to the cart, maybe it is the Details button that needs to be removed.
13 years ago
>> Most surprising is that when adding the Visible="false" in the .ascx page - there was no effect.
Setting the Visible property to false won't have any effect if you don't also modify the code behind files (files ending in ascx.cs) and recompile the solution. The code behind will set the visibility to true (overriding your change) if the product's first product variant has their "Disable buy button" property set to false (unchecked).
To recompile the solution, you will need the source version of NopCommerce (1.60) and either Visual Studio 2008 or Visual Web Developer 2008 Express Edition.


>> I tested by doing the same for the Details button.  It worked, the button went away.
It worked because the visibility of the Details button is never changed in the code behind so your change persists.


>> It finally occurred to me that the action of both the Details and Add To Cart buttons by default with no code change will take you to the /Product Details page (not the cart page) when you have an assigned attribute.
You are correct; if a product variant has attributes, it can't be added directly to the cart so you are taken to the product details page. The purpose of the change (see the first post in this topic) was to not display the "Add to Cart" button if the product couldn't be directly added to the cart (because attributes need to be selected).


>>Another thought though is that the user experience may be that they don't want to read details they just want to add to the cart, maybe it is the Details button that needs to be removed.
If a product has only one product variant and the product variant has no attributes to select, then it can be added directly to the cart because there is no further input needed from the customer in determining the product they want.

.
13 years ago
Thank you for your detailed response, I do hope to resolve this. All of this thread concerns Products that have Attributes and my objective is to remove the Add To Cart button only on the /Category Product List page.  My comments are preceded by **.

>> Most surprising is that when adding the Visible="false" in the .ascx page - there was no effect.
Setting the Visible property to false won't have any effect if you don't also modify the code behind files (files ending in ascx.cs) and recompile the solution.

**I did so according to the earlier post for 1.60 code changes.  

**I edited the file Modules\ProductBox2.ascx.cs and commented out line 84 and added the code that was in the post.  I did the same for ProductBox1.ascx.cs.  

**I am using Visual Studio 2010 Express and 4.0.  After making the code changes to the code behind files as well as the .ascx pages I built the NopCommerceStore website and ran it and there was no change to the Add To Cart button behavior.  I did this several times.  In version 1.50 I did see that the Add to Cart button was not displayed after using similar code from an earlier post for 1.50.

The code behind will set the visibility to true (overriding your change) if the product's first product variant has their "Disable buy button" property set to false (unchecked).

** I do not want to disable the buy button, as that will remove it entirely from all pages.  Please advise, it sounds like the code solution in the post is overridden (visible set to true) unless the Disable buy button is checked.  Since the Disable buy button setting checkbox is at the Product level, the result is that the product cannot be purchased.  

To recompile the solution, you will need the source version of NopCommerce (1.60) and either Visual Studio 2008 or Visual Web Developer 2008 Express Edition.

** As 1.60 is 4.0 are you sure I could be using my VS 2008?

>> I tested by doing the same for the Details button.  It worked, the button went away.
It worked because the visibility of the Details button is never changed in the code behind so your change persists.

** Yes I understand that.

>> It finally occurred to me that the action of both the Details and Add To Cart buttons by default with no code change will take you to the /Product Details page (not the cart page) when you have an assigned attribute.
You are correct; if a product variant has attributes, it can't be added directly to the cart so you are taken to the product details page. The purpose of the change (see the first post in this topic) was to not display the "Add to Cart" button if the product couldn't be directly added to the cart (because attributes need to be selected).

** Yes!  That is also my objective.  The code solution for 1.60 on June 09, 2010 did not prevent the button from displaying.

>>Another thought though is that the user experience may be that they don't want to read details they just want to add to the cart, maybe it is the Details button that needs to be removed.
If a product has only one product variant and the product variant has no attributes to select, then it can be added directly to the cart because there is no further input needed from the customer in determining the product they want.

** Yes, my thought is that the customer's thinking might be that their objective is to Add To Cart.  They are not particularly interested in reading the Details.  So if the Add To Cart is displayed and they will be taken directly to the Details anyway, perhaps the Details button should be in a Visible = "false" state.

** This is an excellent product, the best open source .Net solution available.  Really nice work.
13 years ago
Tara wrote:
Thank you for your detailed response, I do hope to resolve this. All of this thread concerns Products that have Attributes and my objective is to remove the Add To Cart button only on the /Category Product List page.  My comments are preceded by **.

>> Most surprising is that when adding the Visible="false" in the .ascx page - there was no effect.
Setting the Visible property to false won't have any effect if you don't also modify the code behind files (files ending in ascx.cs) and recompile the solution.

**I did so according to the earlier post for 1.60 code changes.  

**I edited the file Modules\ProductBox2.ascx.cs and commented out line 84 and added the code that was in the post.  I did the same for ProductBox1.ascx.cs.  

**I am using Visual Studio 2010 Express and 4.0.  After making the code changes to the code behind files as well as the .ascx pages I built the NopCommerceStore website and ran it and there was no change to the Add To Cart button behavior.  I did this several times.  In version 1.50 I did see that the Add to Cart button was not displayed after using similar code from an earlier post for 1.50.


After building, are you running the website on a web server or through the development server? If on a web server, ensure you are copying the new files (NopCommerceStore.dll) to the web server to see the changes. If you are using the built in development web server, and the changes aren't showing up, then the NopCommerceStore project may not be getting recompiled. Have you checked the Modified Date for the NopCommerceStore.dll (in /bin) after making a change and compiling the solution? Have you set NopCommerceStore as the 'StartUp Project'? Have you tried to build it from Solution Explorer (right-click on the NopCommerceStore project in Solution Explorer and select Build)?

To see if the project is getting built, make another change (temporarily -remove before publishing your site) to the code behind and add some static text. For Modules\ProductBox2.ascx.cs (line 76)
change from:
lShortDescription.Text = product.ShortDescription;

to:
lShortDescription.Text = product.ShortDescription + "TEST";


This change will append the text "TEST" to categories using the category template "ProductsInLines1". Build the solution and see if the change is present for categories using the "ProductsInLines1" template.


Tara wrote:

The code behind will set the visibility to true (overriding your change) if the product's first product variant has their "Disable buy button" property set to false (unchecked).

** I do not want to disable the buy button, as that will remove it entirely from all pages.  Please advise, it sounds like the code solution in the post is overridden (visible set to true) unless the Disable buy button is checked.  Since the Disable buy button setting checkbox is at the Product level, the result is that the product cannot be purchased.  

To recompile the solution, you will need the source version of NopCommerce (1.60) and either Visual Studio 2008 or Visual Web Developer 2008 Express Edition.

** As 1.60 is 4.0 are you sure I could be using my VS 2008?

Version 1.60 only requires .Net 3.5 SP1; version 1.70 requires .Net 4.0. If you have opened your version 1.60 with VS2010, it probably has been converted for VS2010 and VS2008 probably won't be able to open the solution intended for a newer version of VS.

.
13 years ago
I'll check out your suggestions later.  Thank you.  Yikes, I mis-spoke on my version. I am running 1.70. and my only other previous installation was 1.60.
13 years ago
Getting back to this project and found the easiest way to hide either the Add To Cart or Details button on the Product Page.  This is of course if you have attributes and both buttons take you to the Details page anyway.  This should work for any version, stylesheet or product template.  I am using the Product List so my changes reflect that.  The solution is to split the css block that manages the width of the buttons and set the Display to none on the button that you want to hide.

Original code block:
.productgridaddtocartbutton, .productlistaddtocartbutton
{
    width:100px;
}

Changes:
.productgridaddtocartbutton      /* i am not using this template so keep it */
{
    width:100px;
}

.productlistaddtocartbutton   /* i am using this template  */
{

    display: none;                       /* i don't want to display this button as it is redundant */
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.