Category Names added to Products pages

  • Posts: 28
  • Thank you received: 1
12 years 2 months ago #64957

Hi HikaShop Support..

Im sure I had this figured out before, but seem to lost where to add this.

I would like to have the Category names automatically added to each Product page so customers can see that they are in a "certain category of products". (Enclosed: a sample of what im talking about)

Example: when customer clicks on "amino acids category" ... all amino acids products apear under the heading "Amino Acids".

Thanks again guyz... appreciate your time and work..!

Also, awaiting 1.6.0 and the "badges" to come around. section for hikashop!......hikashop is amazing.. !!

Big5hot www.tsn.sportsnutrition.com

Attachments:
Last edit: 12 years 2 months ago by big5hot.

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

  • Posts: 12953
  • Thank you received: 1778
12 years 2 months ago #65019

Hi,

I think that you'll have to :
- Go to "Hikashop->Display->Views"
- Edit the "listing_img_title" file of the "product view" of the front-end's template that you are currently using
- Add this code :

$productClass=hikashop_get('class.product');
$categories=$productClass->getCategories($this->row->product_id);
$database =& JFactory::getDBO();
$query = 'SELECT * from '.hikashop_table('category').' WHERE category_id IN ('.implode($categories, ',').')';
$database->setQuery($query);
$categories =$database->loadObjectList();
foreach($categories as $category){
	echo $category->category_name.'<br/>';
}
Hope this will help you.

The following user(s) said Thank You: bolando

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

  • Posts: 28
  • Thank you received: 1
12 years 2 months ago #65197

Hi Mohamed,

Is there a specific place/position i should insert this "code" ?. I am not very knowledgeable when it comes to code. I found the file and inserted it, but nothing happened.

Need a little more help with this one....THanks!

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

  • Posts: 12953
  • Thank you received: 1778
12 years 2 months ago #65212

Hi,

Sorry I misunderstood your question you should :
- Go to "Hikashop->Display->Views"
- Edit the "show_default" file of the "product" view of the front-end's template that you are currently using
- Add this code :

<?php 
  foreach($this->categories as $category){
  echo ($category->category_name).' - ';
  }
  ?>
after
<div id="hikashop_product_top_part" class="hikashop_product_top_part">
Hope this will help you.

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

  • Posts: 28
  • Thank you received: 1
12 years 2 months ago #65379

Hi Mohamed,

THanks for your help but im still not able to achieve my goal. Maybe I have not explained clear enough, and im sorry for that.

There are 3 pages, (1)category (2)products in category (3)products that are highlighted

I would like to display a category text in the "(2)products in category" page and not in (3).

I added the code that you gave me and it added a category text in #(3). - See Attached pics

www.tsnsportsnutrition.com

I really appreciate you taking the time in helping me. Sorry if I was not clear...

Big5hot
_______________
UPDATE:

Hi Mohamed..

After playing with the many controls, I may have stumbled on the SOLUTION. I Hide the Menu and the category title for each category appeared. Im not sure if that was the reason, but as you can see, the issue is resolved.

THANKS = Mohamed for your time and efforts... again. (PROBLEM SOLVED,)

Big5hot

Attachments:
Last edit: 12 years 2 months ago by big5hot.

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

  • Posts: 11
  • Thank you received: 0
10 years 6 months ago #156195

Hi,
I used this code to display category on product page, but I would like to display parent category/s too. Trying to figure it out I could use some help :blush:

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
10 years 6 months ago #156209

To get the parent categories of a category, you can use such code:

$categoryClass=hikashop_get('class.category');
$parents = $categoryClass->getParents($category_id);
foreach($parents as $parent){
 echo $parent->category_name;
}

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

  • Posts: 11
  • Thank you received: 0
10 years 6 months ago #156236

I tried the code and I m getting
Undefined variable: category_id in C:\xampp\htdocs\...

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
10 years 6 months ago #156251

Yes that's normal if you just copy/pasted the code I gave.
The code I gave will display the name of all the parents of the category with its id set in the $category_id. If you don't set any $category_id before that code with the id of the category for which you want to display the parents, it won't be able to work properly.

For example, you can add your code inside the categories foreach like this
foreach($this->categories as $category){
$category_id = $category->category_id;
//code from my previous message
}

Please understand that the support we provide here is about the use of HikaShop, not to code for you your customizations, although we try to help when it's not too complex. I would recommend to look for a developer to help you if you're not a developer and that you want to add advanced code modifications like these.

The following user(s) said Thank You: rada88496

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

  • Posts: 11
  • Thank you received: 0
10 years 6 months ago #156309

I am always trying to learn new stuff...
thanks your time :)

Last edit: 10 years 6 months ago by rada88496. Reason: its3am

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

  • Posts: 20
  • Thank you received: 0
10 years 1 week ago #180388

This is exactly what I was looking for but could you share with me how to make these categories links that are clickable to their respective categories?

Mohamed Thelji wrote: Hi,

Sorry I misunderstood your question you should :
- Go to "Hikashop->Display->Views"
- Edit the "show_default" file of the "product" view of the front-end's template that you are currently using
- Add this code :

<?php 
  foreach($this->categories as $category){
  echo ($category->category_name).' - ';
  }
  ?>
after
<div id="hikashop_product_top_part" class="hikashop_product_top_part">
Hope this will help you.

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

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
10 years 1 week ago #180409

Hi,

change the code:

echo ($category->category_name).' - ';

to:
$categoryClass = hikashop_get('class.category');
$categoryClass->addAlias($category);
echo '<a href="'.hikashop_contentLink('category&task=listing&cid='.$category->category_id.'&name='.$category->alias,$category).'">'.($category->category_name).'</a> - ';

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

  • Posts: 10
  • Thank you received: 0
8 years 6 months ago #239823

I have tried this solution but I get nothing but a '-' displaying on the product page view, has the code required to add a Category Name and link changed since this solution was proposed?

I have a site with sports teams listed, each team has a sub-category of the main category 'clubshops' and I would like to display this above the product name so that people can flick back to the teams main category view.

I have tried this...

<?php 
  foreach($this->categories as $category){
  $categoryClass = hikashop_get('class.category');
  $categoryClass->addAlias($category);
  echo '<a href="'.hikashop_contentLink('category&task=listing&cid='.$category->category_id.'&name='.$category->alias,$category).'">'.($category->category_name).'</a> - ';
  }
  ?>

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

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

Hi,

That code should still work fine.
Could you give a link to the page where you have that ?

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

  • Posts: 10
  • Thank you received: 0
8 years 6 months ago #239921

Hi Nicolas,

Truly bizarre, just added the same code I had tried (and pasted here) back into the page, and this time I get a Link???

Sample URL to product page: /teamshop/llansawel/product/396-training-vest

I have added code to templates/gk_storefront/html/product/show_tabular.php

However the link created goes to: /teamshop/llansawel/team/27-llansawel-rfc

And I would like it to go to: /teamshop/llansawel/

Is there anyway to change this, other than editing .htaccess to redirect?

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

  • Posts: 10
  • Thank you received: 0
8 years 6 months ago #239922

I have solved this now, by altering the canonical URL for the Category to the same as the Menu Item for that category.

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

Time to create page: 0.098 seconds
Powered by Kunena Forum