Author Topic: [SOLVED] Product page: get any Category title by id?  (Read 1041 times)

EvanGR

  • Jr. Member
  • **
  • Posts: 468
[SOLVED] Product page: get any Category title by id?
« on: April 27, 2020, 11:14:09 am »
In single product page, I have an array of category ids. I want to display the titles of these categories. Anyone have the code handy, or know where to find it?
Basically I want the function to get the category title by providing its id.

Thanks

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1441
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Product page: get any Category title by id?
« Reply #1 on: April 27, 2020, 12:41:46 pm »
Try this:

Quote
$active_category_id = vRequest::getInt('virtuemart_category_id', '0');
$category = $categoryModel->getCategory($active_category_id, false, false);
$catname = $category->category_name;
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

EvanGR

  • Jr. Member
  • **
  • Posts: 468
Re: Product page: get any Category title by id?
« Reply #2 on: April 28, 2020, 13:58:04 pm »
Thanks, I am getting an error about '$categoryModel'. It's probably not defined in the product page. How do I reference that?

Thanks

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1441
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Product page: get any Category title by id?
« Reply #3 on: April 28, 2020, 14:14:48 pm »
Try this code before another:

Code: [Select]
$categoryModel = VmModel::getModel('Category');
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10431
  • VirtueMart Version: 3+
Re: Product page: get any Category title by id?
« Reply #4 on: April 28, 2020, 17:57:32 pm »
are you wanting the categories info the product is in? Like all the categories the product is in? The data is already available on product page.

Its available with     $this->product->categoryItem

The code below isnt exactly what you want, but you can see the variables and how i do it.

foreach ($this->product->categoryItem as $category){
if ($category['published']==0)continue;
if ($category['virtuemart_category_id']==85)continue;
$caturl = JRoute::_ ( 'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category['virtuemart_category_id'] );
 $catname=$category['category_name'];
 $categoriescombined[]= array($caturl,$catname,$category['virtuemart_category_id']);
 $skip2[]=$category['virtuemart_category_id'];

}

EvanGR

  • Jr. Member
  • **
  • Posts: 468
Re: Product page: get any Category title by id?
« Reply #5 on: April 28, 2020, 20:56:00 pm »
Thank you very much!

I am not looking for the categories the product is in, in this case, but thanks for the info it will definitely be useful!