check products category before compare

  • Posts: 120
  • Thank you received: 2
11 years 4 months ago #154816

I have a problem. I have two categories and subcategories thereof for example book category with it's subcategories and car category with it's subcategories. now my products in subcategories and when we add product in to wishlist for example one product from book subcategories add in wishlist and another product add from car subcategories in to wishlist.
now a user when compare and select products from wishlist select a book product and select a car product when redirect to compare page i want echo a message The product you have selected is not a set from a category. and return page.
now how can do it? which method i can do it and check products category before compare ?
I want compare only between car subcategories or book subcategories.
thank you

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

  • Posts: 2143
  • Thank you received: 747
11 years 4 months ago #154896

I'm just a user as well, and sure the official supporters here could say more about this, but I guess what you want would cause major programming.

However, since I have a similar 'problem', meaning it not making sense comparing products from mixed categories, but loving the 'compare' option where it makes sense, I chose a different but working solution:

In product listing views showing a mix of products from different categories, and only in these, hide the 'compare' part with CSS and "display:none;". Applying it to the proper id's and classes, it's simple, effective, and doesn't even require editing a view if you're not comfortable with PHP.

Good luck!


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

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

  • Posts: 13201
  • Thank you received: 2322
11 years 4 months ago #154840

Hi,

You can edit the view "product / compare" via the menu Display > Views and use this kind of code:

<?php
$display = true;
$cat = 0;
foreach($this->elements as $element) {
	if($cat == 0)
		$cat = $element->product_category_id;
	if($element->product_category_id != $cat)
		$display = false;
}
if(!$display){
	$app =& JFactory::getApplication();
	$app->enqueueMessage(JText::_('NOT_THE_SAME_CATEGORY'));
	?>
	<script type="text/javascript">history.back();</script>
	<?php
}
?>
That will redirect the customer to the previous page with a system message.
You can add a translation for the string:

NOT_THE_SAME_CATEGORY

Thanks to the translation overrides:
hikashop.com/support/faq.html#tran

The following user(s) said Thank You: kaya

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

  • Posts: 120
  • Thank you received: 2
11 years 4 months ago #154912

thank you dear Xavier
I have tow parent category and all my categories and products in two parent category now I want check parent category before compare.
The code that you gave me don't check parent category. now how can do it?

when use this code $cat = $element->category_id check category but i want check parent category. I have tow parent category and many categories in my tow parent category.

thank you very much.

Last edit: 11 years 4 months ago by kaya.

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

  • Posts: 13201
  • Thank you received: 2322
11 years 4 months ago #155114

Hi,

You will have to use the category class in order to get the parent category of the current one.

<?php
$display = true;
$cat = 0;
$categoryClass = hikashop_get('class.catgory');
foreach($this->elements as $element) {
	$parCat = $categoryClass->getParents($element->product_category_id);
	if($cat == 0)
		$cat = $parCat[0];
	if($parCat[0] != $cat)
		$display = false;
}
if(!$display){
	$app =& JFactory::getApplication();
	$app->enqueueMessage(JText::_('NOT_THE_SAME_CATEGORY'));
	?>
	<script type="text/javascript">history.back();</script>
	<?php
}
?>

ps: I haven't tested that code. It need probably to be adapted.

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

Time to create page: 0.083 seconds
Powered by Kunena Forum