Is there an extension available which shows all categories with the full path (i.a. Goods => Home => Kitchen => Cups) a product is assigned in product details ?
The problem is:
When a customer is on product details in this view I need the information in which other categories this products is assigned, too. (with link and full category path).
Is there any solution for this? I need to show path too.
I dont have time to re-write this code for you,
but I will tell you what it does
It combines
all categories a product is in & children category, & related categories
It removes duplicates
<?php defined ( '_JEXEC' ) or die ( 'Restricted access' );
?>
<div class="category-view related-childs related-categories">
<?php
$i=0;
$tt=0;
$html='';
foreach ($this->product->categoryItem as $category){
if ($category['published']==0)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'];
$tt++;
}
foreach ($this->category->children as $category) {
if (in_array($category->virtuemart_category_id,$skip2, TRUE)){
continue;
}
$caturl=JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category->virtuemart_category_id, FALSE);
$catname=$category->category_name;
$categoriescombined[]= array($caturl,$catname,$category->virtuemart_category_id);
$tt++;
}
if (!empty($this->product->customfieldsSorted['related_categories'])){ foreach ($this->product->customfieldsSorted['related_categories'] as $field) {
$tt++;
} }
$tt=$tt-1;
$html.='<h3>Related Categories</h3>';
$html.='<ul class="ul width30">';
if (!empty($this->product->customfieldsSorted['related_categories'])){ foreach ($this->product->customfieldsSorted['related_categories'] as $field) {
$skip[]=$field->customfield_value;
$field->display = str_replace( 'target="_blank"', '', $field->display);
$html.='<li class="i'.$i.'">'.$field->display.'</li>';
$i++;
if ($i==5 && $tt>5){$html.='</ul><ul class="ul width30">';}
} }
foreach ($categoriescombined as $categoriescombined){
if (!empty($skip)){ if (in_array($categoriescombined[2],$skip, TRUE)){
continue;
} }
$html.='<li class="i'.$i.'"><a href="'.$categoriescombined[0].'" title="'.$categoriescombined[1].'">'.$categoriescombined[1].'</a></li>';
$i++;
if ($i==5 && $tt>5){$html.='</ul><ul class="ul width30">';}
}
$html.='</ul>';
echo $html;
?>
</div>
all the cats assigned are available in the this->product object in the prod details
just get them and render them out nicely
$this->product->categoryItem
Thank you! I study it.
Worked! Now it echos:
Category path: > Parent 0 > Parent 2 > Parent 1
I see it is in id -order, that is not exactly what we want to see.
##
Not perfect view ( first > unnecessary )
Below not working in category view.
##
<div class="From PRO's category-view related-childs related-categories">
<?php
/* components/com_virtuemart/views/productdetails/tmpl */
$i=0;
$tt=0;
foreach ($this->product->categoryItem as $category){
if ($category['published']==0)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']);
$tt++;
$skip[]=$field->customfield_value;
}
$html.='Category path: ';
foreach ($categoriescombined as $categoriescombined){
if (!empty($skip)){ if (in_array($categoriescombined[2],$skip, TRUE)){
continue;
} }
$html.=' > <a href="'.$categoriescombined[0].'"title="'.$categoriescombined[1].'" > '.$categoriescombined[1].'</a>';
$i++;
if ($i==5 && $tt>5);
}
echo $html;
?>
</div>
I am thinking that these should be used this type of way.
category_parent_id > category_parent_id >category_child_id
I am stucked.
I tried to mimic from this code but without luck
<?php // no direct access
defined('_JEXEC') or die('Restricted access');
/**
* Category menu module
*
* @package VirtueMart
* @subpackage Modules
* @copyright Copyright (C) OpenGlobal E-commerce. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL V3, see LICENSE.php
* @author OpenGlobal E-commerce
*
*/
function printCategories($params, $virtuemart_categories, $class_sfx, $parentCategories) {
$use_vm_accordion = $params->get('use_vm_accordion');
echo '<ul class="menu'.$class_sfx.'" >';
foreach ($virtuemart_categories as $category) {
$active_menu = 'VmClose';
$caturl = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$category->virtuemart_category_id);
$images = $category->images;
if (1 == $params->get('show_images')) {
$image = $images[0]->file_url_thumb;
} else if (2 == $params->get('show_images')) {
$image = $images[0]->file_url;
}
$cattext = (isset($image) ? '<img src="'.$image.'" alt="'.$category->category_name.'" />' : '').'<span>'.$category->category_name.'</span>';
if (is_array($parentCategories)) {// Need this check because $parentCategories will be null if we're at category 0
if (in_array( $category->virtuemart_category_id, $parentCategories)) {
$active_menu = 'active VmOpen';
}
}
if ($category->childs) {
$active_menu .= ' parent';
}
echo '<li class="'.$active_menu.'"><div>'.JHTML::link($caturl, $cattext).(($use_vm_accordion && $category->childs) ? '<span class="VmArrowdown"> </span>' : '').'</div>';
if ($category->childs) {
printCategories($params, $category->childs, $class_sfx, $parentCategories);
}
echo '</li>';
}
echo '</ul>';
}
Quote from: maxispin on September 27, 2016, 17:01:14 PM
Below not working in category view.
https://forum.virtuemart.net/index.php?topic=100696.0
change
$this->product to $product
Thanks for reminding ::)