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.
14 anni tempo fa
Regarding Category pages:

If there are no product variables, the "Add to cart" button adds directly to the cart, but if there are product variables like different sizes, etc, the button leads to the product page.

To eliminate customer confusion, I'd like to remove the "Add to cart" button from the listings on the category pages (leaving the "Details" button only) but I still need the "Add to cart" button on the individual product pages.  

Any suggestions?


Thanks in advance!!
14 anni tempo fa
The following changes will hide the "Add to cart" button only if the item can't be added to the cart without selecting attributes (it checks other things as well, stock status, availability date, disabled buy button, etc. ) for the ProductsInLines1 and ProductsInGrid category templates (ProductsInLines2 doesn't use buttons). To hide the "Add to cart" at all times, skip to below.
                
1. For Category Template "ProductsInLines1"

Edit File: Modules\ProductBox2.ascx.cs

comment out line 102:
//btnAddToCart.Visible = (!productVariant.DisableBuyButton);

add the following code:
int productVariantID = 0;
if (ProductManager.DirectAddToCartAllowed(product.ProductID, out productVariantID) == false)
{
    btnAddToCart.Visible = false;
}
else
{
    btnAddToCart.Visible = (!productVariant.DisableBuyButton);
}

2. For Category Templates "ProductsInLines1" and "ProductsInGrid"

Edit File: Modules\ProductBox1.ascx.cs (and make the same change at line 106)


---------

If you want to remove the "Add to cart" button entirely, just comment out lines 102 (ProductBox2.ascx.cs) and 106 (ProductBox1.ascx.cs) and set the visibility of the button in the control files (ProductBox1.ascx & ProductBox2.ascx).
<asp:Button runat="server" ID="btnAddToCart" OnCommand="btnAddToCart_Click" Text="<% $NopResources:Products.AddToCart %>"
ValidationGroup="ProductDetails" CommandArgument='<%# Eval("ProductID") %>' SkinID="ProductListAddToCartButton" Visible="false" />


You will need to recompile the solution.

.
14 anni tempo fa
Thank you!!  I made the changes, recompiled, and am putting everything back on the site.  Thanks again for your response.
14 anni tempo fa
One more question.  If I already have the site installed before making the changes and recompiling, do I need to delete all the files already on the site, upload, then reinstall?  Or can I simply delete the files and upload the newly compiled ones?
14 anni tempo fa
You don't need to replace all the files on the server, only files that have changed. When uploading new files, you should backup or rename the existing files on the server you are replacing before replacing them in case you need to revert back. You can delete the renamed files when you determine your changes are working as intended.

For an example on what to upload, regarding the changes I advised you to make:

If you only edited the code behind files ProductBox2.ascx.cs and/or ProductBox1.ascx.cs, you only need to upload NopCommerceStore.dll (from the \bin directory). You don't need .cs files on the server.

If you also edited the control files ProductBox2.ascx and ProductBox1.ascx, you will need to upload NopCommerceStore.dll (to \bin) and ProductBox2.ascx and ProductBox1.ascx (to \Modules).

.
14 anni tempo fa
Got it.  Thank you again for all of your help.
13 anni tempo fa
I managed to succesfully use this code for v1.5  (as well as v1.4 which it was written for) , however I'm having trouble achieving the same results in

v1.6

can anyone offer a solution ? - the qusetion is the same as that originally posted by     inspiredsky
13 anni tempo fa
haydie wrote:
I managed to succesfully use this code for v1.5  (as well as v1.4 which it was written for) , however I'm having trouble achieving the same results in

v1.6

can anyone offer a solution ? - the qusetion is the same as that originally posted by     inspiredsky


To use the code in 1.60, the line number to comment out/replace has changed and a parameter name has changed in the code to add. This change still only hides the "Add to cart" button if a product variant has attribute options that need to be selected.

1. For Category Template "ProductsInLines1"

Edit File: Modules\ProductBox2.ascx.cs

comment out line 84:
//btnAddToCart.Visible = (!productVariant.DisableBuyButton);

add the following code (changes underlined):

int productVariantId = 0;
if (ProductManager.DirectAddToCartAllowed(product.ProductId, out productVariantId) == false)
{
    btnAddToCart.Visible = false;
}
else
{
    btnAddToCart.Visible = (!productVariant.DisableBuyButton);
}

2. For Category Templates "ProductsInLines1" and "ProductsInGrid"

Edit File: Modules\ProductBox1.ascx.cs (and make the same change at line 88)

You will need to recompile the solution.

.
13 anni tempo fa
mb, thank you for your help one more time.

I knew where to put it and I first thought that the red squiggle which I was getting under

ProductID   was  because of capitalisation but it was still there when I changed  it to

productId  ( the same format as it is in the 'AddToCart_Click' event )

didn't realise I should have kept the capital 'P'   !

many thanks again  :) ,

Hayden
13 anni tempo fa
Hi,

I'm wanting to do away with the add to cart button and short description completely on this page. If I comment the the short description line in the .cs code e.g. //lShortDescription.Text = product.ShortDescription; and set visible="false" the description disappears as expected but if I do this to the add to cart button nothing happens.

Can anyone explain how I hide/get ride of the add to cart button and in the previous versions please.

Cheers

Vass
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.