Display text depending on category

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #240633

Hi,

1. I have added some div classes inside show_default view file. Basically it is text in size tab...
Is there a way to hide it on some category products?
Example. Show it on products which are in category clothes but If product is in category shoes that div/text should be hidden.

2. Any ETA on hikashop 3 release?

Thank you

Last edit: 8 years 6 months ago by kyratn.

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

  • Posts: 13201
  • Thank you received: 2322
8 years 6 months ago #240669

Hi,

1. Yes you can add custom if condition like that in the view:

<?php
$productClass = hikashop_get('class.product');
$categories = $productClass->getCategories($this->element->product_id);
if(in_array('XX',$categories)){
	// Show content for all products in the 'XX' category
}

if(!in_array('YY',$categories)){
	// Show content for all products but the one in the 'YY' category
}

// XX and YY must be the category id
?>

2. We can't give a date for now, still under development.

The following user(s) said Thank You: kyratn

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #240678

Thank you Xavier

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #240760

Hi,

So code working great but I can't understand one thing.

I added code like this:

<?php
$productClass = hikashop_get('class.product');
$categories = $productClass->getCategories($this->element->product_id);
if(!in_array('158',$categories)){
 echo	'<div class="size_guide">
            <a href="ismatavimai" target="_blank"><img src="images/ismatavimai/sizeicon.png" data-placement="top" data-toggle="hk-tooltip" data-original-title="Išmatavimų paaiškinimai"></a>
          </div>';
}?>

ID 158 is the category of the accessories and code works fine. It is showing on all products except on products from this category.
Now, I have category shoes with ID 159 and when I use it, products still are visible.
So not sure why with one category it is working and not with other?

Thanks

Last edit: 8 years 6 months ago by kyratn.

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
8 years 6 months ago #240763

Hi,

As Xavier said, you would need a second if for that other category, like that:

if(!in_array('159',$categories)){
 echo	'<div class="size_guide">
            <a href="ismatavimai" target="_blank"><img src="images/ismatavimai/sizeicon.png" data-placement="top" data-toggle="hk-tooltip" data-original-title="Išmatavimų paaiškinimai"></a>
          </div>';
}

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #240805

Hi,

Still couldn't get it to work.
I spent 1 hour and tried all possible combinations.
I need to hide it on 2 categories. They ID's are 158 and 159
What I get is it will hide on one of them or will be shown on both.
Tried something like this:

<?php
$productClass = hikashop_get('class.product');
$categories = $productClass->getCategories($this->element->product_id);
if(!in_array('158',$categories)){
 echo	'<div class="size_guide">
            <a href="ismatavimai" target="_blank"><img src="images/ismatavimai/sizeicon.png" data-placement="top" data-toggle="hk-tooltip" data-original-title="Išmatavimų paaiškinimai"></a>
          </div>';
}if(!in_array('159',$categories)){
 echo	'<div class="size_guide">
            <a href="ismatavimai" target="_blank"><img src="images/ismatavimai/sizeicon.png" data-placement="top" data-toggle="hk-tooltip" data-original-title="Išmatavimų paaiškinimai"></a>
          </div>';

}?>

What I am doing wrong?
Looking into code I only see difference in exclamation mark.

Thank you

Last edit: 8 years 6 months ago by kyratn.

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
8 years 6 months ago #240808

Hi,

Ah ok, I didn't understand that it's what you wanted.
In that case, you want to do that:

if(!in_array('158',$categories) && !in_array('159',$categories)){
 echo	'<div class="size_guide">
            <a href="ismatavimai" target="_blank"><img src="images/ismatavimai/sizeicon.png" data-placement="top" data-toggle="hk-tooltip" data-original-title="Išmatavimų paaiškinimai"></a>
          </div>';
}

The following user(s) said Thank You: kyratn

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #240908

Hi,

Thank you for help Nicolas.
Unfortunately it doesn't work. It seems it works only with category accessories with ID 158, tried shoes with ID 159 and it doesn't work.
I also tried with other categories ID's and no success.
Could be that problem is that some of products have more then one category added?
Attaching some screenshots.

Thanks

Attachments:

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

  • Posts: 4748
  • Thank you received: 644
  • MODERATOR
8 years 6 months ago #240939

Hello,
Can you try this code :

$productClass = hikashop_get('class.product');
$categories = $productClass->getCategories($this->element->product_id);

if(in_array('158',$categories) || in_array('159',$categories) ) {

	echo	'<div class="size_guide">
            <a href="ismatavimai" target="_blank"><img src="images/ismatavimai/sizeicon.png" data-placement="top" data-toggle="hk-tooltip" data-original-title="Išmatavimų paaiškinimai"></a>
          </div>';
}

Please note that :
-!in_array('158',$categories) means, that the following command will be execute ONLY if the Id = 158 or 159 isn't found, so in this last code I provide your div will be display only for Id = 158 or 159
- '||' means OR, '&&' means AND, and so this condition won't be possible in your product page, unless a product have the 158 AND 159 categories Id.

Hope this will fit your needs.

Regards.

Last edit: 8 years 6 months ago by Philip.
The following user(s) said Thank You: kyratn

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #240944

Hi,

Thank you for replay Philip. Unfortunately it doesn't work like it should.
I have added your code provided and I have results like this:
Div is shown in category with ID 158 but not in any other. Reading your post it should be visible in category with ID 159 but it is not....
So it looks like that there is an issue with category ID 159 and others... Code don't want to work with it.

Thanks

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
8 years 6 months ago #240950

Hi,

Add the line:
var_dump($categories);
before the if and you'll see the list of categories for the product on each product page.
So you can check the id that you need to use in your if.

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #241101

Hi,

Ok, I added it and I see this:

Product in category accessories with id 158: array(1) { [0]=> string(3) "158" }
Product in category shoes with id 159: array(0) { } (same for all my other categories)
So I tried to remove view override, tried to use protostar template and results were same...

Is there anything I could do more?

Thanks

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

  • Posts: 4748
  • Thank you received: 644
  • MODERATOR
8 years 6 months ago #241102

Hello,

If your products have all a setted category that result is quite strange... I don't know what can leads to this, and so, can you provide back end user acces in order to process some tests by ourself ?

Of course, you must pass theses references thanks to our "Contact us" form, just don't forget to send it with an url link to this topic.

Awaiting news from you.

Regards.

The following user(s) said Thank You: kyratn

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #241148

Hi,

Login details have been sent.

Thanks

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

  • Posts: 13201
  • Thank you received: 2322
8 years 6 months ago #241162

Hi,

The thing is that you have products with variants, so the categories check must be done on the main product and no on a variant.
The following code will solve all your problems ;)

$productClass = hikashop_get('class.product');
$categories = $productClass->getCategories($this->element->product_id);
if($this->element->product_parent_id != '0')
    $categories = $productClass->getCategories($this->element->product_parent_id);

if(in_array(array('158','159'),$categories)) {
	echo	'<div class="size_guide">
            <a href="ismatavimai" target="_blank"><img src="images/ismatavimai/sizeicon.png" data-placement="top" data-toggle="hk-tooltip" data-original-title="Išmatavimų paaiškinimai"></a>
          </div>';
}

The following user(s) said Thank You: kyratn

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #241232

Hi,

It didn't work but adding this did the trick:

if(!in_array('158',$categories) && !in_array('159',$categories)){

Thank you very much to ALL for help.

Have a great day

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

Time to create page: 0.094 seconds
Powered by Kunena Forum