News:

Looking for documentation? Take a look on our wiki

Main Menu

[SOLVED] Product page: get any Category title by id?

Started by EvanGR, April 27, 2020, 11:14:09 AM

Previous topic - Next topic

EvanGR

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

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

Thanks, I am getting an error about '$categoryModel'. It's probably not defined in the product page. How do I reference that?

Thanks

pinochico

Try this code before another:

$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

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

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!