Remove Add to Cart from Specific Categories

  • Posts: 303
  • Thank you received: 18
  • Hikashop Business
8 years 9 months ago #207685

-- url of the page with the problem -- : new.mojooutdoors.com/index.php/vendor-pr...category_pathway-166
-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.3.1
-- Browser(s) name and version -- : Chrome latest

How do i remove the add to cart button and quantity field from a specific category. I have read through other user's posts in the Forum, but the solutions do not seem to work. I've tried setting up a content module to override the defaults, but it still does not remove the add to cart button and quantity field from the product detail page. Any help would be greatly appreciated.

Also, I had a quick question on Canonical URL's. If i set a canonical url, all variations (alternate urls that point to the same product) will become consolidated into the canonical? I'm using sh404SEF and there is an option for canonical urls in the alias manager. Just don't want a billion 404's pop up if i change a product to a new category.

Thanks for you time.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
8 years 9 months ago #207712

Hi,

To remove the add to cart button and quantity field on the product page for products in a specific category it will require view override.
The view to edit is "product / show_default" and you can replace the code:

		<div id="hikashop_product_quantity_main" class="hikashop_product_quantity_main">
			<?php
			//LAYOUT quantity
			$this->row = & $this->element;
			$this->ajax = 'if(hikashopCheckChangeForm(\'item\',\'hikashop_product_form\')){ return hikashopModifyQuantity(\'' . $this->row->product_id . '\',field,1' . $form . ',\'cart\'); } else { return false; }';
			$this->setLayout('quantity');
			echo $this->loadTemplate();
			?>
		</div>
By:
<?php if(!in_array($this->element->product_category_id,array('XX','YY'))){ ?>
		<div id="hikashop_product_quantity_main" class="hikashop_product_quantity_main">
			<?php
			//LAYOUT quantity
			$this->row = & $this->element;
			$this->ajax = 'if(hikashopCheckChangeForm(\'item\',\'hikashop_product_form\')){ return hikashopModifyQuantity(\'' . $this->row->product_id . '\',field,1' . $form . ',\'cart\'); } else { return false; }';
			$this->setLayout('quantity');
			echo $this->loadTemplate();
			?>
		</div>
<?php } ?>

And replace 'XX' and 'YY' by the desired category ids.

Please Log in or Create an account to join the conversation.

  • Posts: 303
  • Thank you received: 18
  • Hikashop Business
8 years 9 months ago #207805

I cannot find "hikashop_product_quantity_main" in the product/show_default view? Is this the correct view to edit that block of code?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
8 years 9 months ago #207820

Hi,

Yes it is ;)
You potentially have a view override on the show_default view. So please search for the code:

			$this->setLayout('quantity');
			echo $this->loadTemplate();
and add the given if condition around these lines, like that:
if(!in_array($this->element->product_category_id,array('XX','YY'))){
			$this->setLayout('quantity');
			echo $this->loadTemplate();
}

Please Log in or Create an account to join the conversation.

  • Posts: 303
  • Thank you received: 18
  • Hikashop Business
8 years 9 months ago #207896

I cannot even find 'quantity' in the show_default view. Is it possible it is being overwritten from somewhere else?

UPDATE: I found the first blcck of code you mentioned, in an older version of hikashop (2.1.3). However, it does not exist in this location for the latest version of hikashop. Did the location change?

Last edit: 8 years 9 months ago by mojooutdoors-holden.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
8 years 9 months ago #207937

Hi,

You potentially have an override on the view "product / show_default", please make a backup of this view and then remove it to use our default view. The quantity block must be present, else you should not have any add to cart button on the product detail page.

If it is not solving your issue, please give us a backend access via our contact form with the link to that topic in the message.
www.hikashop.com/support/contact-us.html

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 0
  • Hikashop Business
5 years 6 months ago #299277

Hi Xavier,

We need definitely an INVERS solution; No categories to show cart, except only one or two.
Can you support us with some code for that?
We run Hikashop professional now in catalogue mode only.
www.studio-general.hu

regards,
Janos

Please Log in or Create an account to join the conversation.

  • Posts: 303
  • Thank you received: 18
  • Hikashop Business
5 years 6 months ago #299308

You should be able to do the same thing except change the if statement:

if(in_array($this->element->product_category_id,array('XX','YY'))){
			$this->setLayout('quantity');
			echo $this->loadTemplate();
}

*Note that all i did was remove the exclamation point at the beginning of the if statement. Now it reads if the categories 'XX','YY' are in the array, display the add to cart. Might be in a different view file since you are using the catalog mode. Not much experience with that.

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 6 months ago #299311

Hi,

The code provided by @mojooutdoors-holden is indeed correct.
Note also that you'll want to turn off the "catalogue mode" after changing that code.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 0
  • Hikashop Business
5 years 5 months ago #299695

Hi,

The code is almost correct, except 'category_id' should be used, instead:

if(in_array($this->element->category_id,array('XX','YY'))){
			$this->setLayout('quantity');
			echo $this->loadTemplate();
}

And also, it does not work when product belongs to more than one category.

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 5 months ago #299698

Hi,

In that case, you want to make sure that the category you want to check on is the first one.
Or you want to change the check and look at $this->categories which contains the information of all the categories of the product.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 0
  • Hikashop Business
5 years 5 months ago #300290

It seems, the smaller category_id is used at the check, not the first given in the product's details.

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 5 months ago #300298

Hi,

Well, the best is to use $this->categories since you have in it all the categories of the product, that's the safest.

Please Log in or Create an account to join the conversation.

  • Posts: 31
  • Thank you received: 0
  • Hikashop Business
5 years 5 months ago #300332

Is there an array called 'categories'?

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 5 months ago #300333

Hi,

I don't understand your question. The variable $this->categories I'm talking about in my previous message is an array called "categories".

Please Log in or Create an account to join the conversation.

Time to create page: 0.103 seconds
Powered by Kunena Forum