News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Showing Categories in Product details default

Started by Agaton, September 12, 2017, 11:21:21 AM

Previous topic - Next topic

Agaton

Versions: vm 3.2.4 Joomla 3.7.5

I am currently trying to create a list of categories relevant to the product. I want to display them at the bottom of the product page as tags.

Example: Product One is associated with 15 random categories I would like to display the categories associated with that product.

Related products is not suitable as that requires a manual action and I want it to be automated on every product.
Plugins are useful but I would prefer to code direct to the product_details template as that it is easier to control and manipulate.

I understand how to turn category id's into links etc, I understand mysql and understand intermediate php. What I am struggling with is the best way to import the data I need into the template.

Its the arrays at the beginning of templates that I struggle with, is there any documentation that could help me or could someone point me in the right direction.





Spiros Petrakis

Hi,
you can create the list with the following code:


<ul>
<?php
foreach($this->product->categoryItem as $tagcategory) {
    
$tagURL =  JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$tagcategory['virtuemart_category_id'], FALSE);
    
$tagName vmText::_($tagcategory['category_name']) ;
    echo 
'<li><a href="' $tagURL '">' $tagName '</a></li>';
}
?>

</ul>
Joomla templates and extensions development
https://www.yourgeek.gr

Agaton

Thank you Spyros, I had actually come up with this solution late Friday night....

$categoryModel = VmModel::getModel('category');
$categoryArray = array();
foreach ($this->product->categories as $catid) :
$categoryArray[] = $categoryModel->getCategory ($catid, true);
endforeach;


foreach ($categoryArray as $category) :

// Category Link
$caturl = JRoute::_ ( 'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category->virtuemart_category_id );

echo '<p><a href="'.$caturl .'" class="'. $category->category_name . '">'. $category->category_name .'</a></p>';

endforeach;


But your solution looks so much more efficient.

Many Thanks

Agaton

Just to confirm that Spryros solution is much better

<ul>
<?php
foreach($this->product->categoryItem as $tagcategory) {
$tagURL =  JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$tagcategory['virtuemart_category_id'], FALSE);
$tagName vmText::_($tagcategory['category_name']) ;
echo '<li><a href="' $tagURL '">' $tagName '</a></li>';
}
?>

</ul>