check products category before compare
12 years 4 months ago #154816
by kaya
check products category before compare was created by kaya
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
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.
12 years 4 months ago #154896
by lousyfool
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" )
Replied by lousyfool on topic check products category before compare
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!
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.
12 years 4 months ago #154840
by Xavier
Replied by Xavier on topic check products category before compare
Hi,
You can edit the view "product / compare" via the menu Display > Views and use this kind of code:
That will redirect the customer to the previous page with a system message.
You can add a translation for the string:
hikashop.com/support/faq.html#tran
You can edit the view "product / compare" via the menu Display > Views and use this kind of code:
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
}
?>
You can add a translation for the string:
Thanks to the translation overrides:NOT_THE_SAME_CATEGORY
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.
12 years 4 months ago - 12 years 4 months ago #154912
by kaya
Replied by kaya on topic check products category before compare
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.
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: 12 years 4 months ago by kaya.
Please Log in or Create an account to join the conversation.
12 years 4 months ago #155114
by Xavier
Replied by Xavier on topic check products category before compare
Hi,
You will have to use the category class in order to get the parent category of the current one.
ps: I haven't tested that code. It need probably to be adapted.
You will have to use the category class in order to get the parent category of the current one.
Code:
<?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.162 seconds