News:

Support the VirtueMart project and become a member

Main Menu

Show all assigned categories (full path) in product detail

Started by lostmail, June 19, 2016, 08:05:44 AM

Previous topic - Next topic

lostmail

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).
VirtueMart VirtueMart 4.4.0 11095 | Joomla 5.x | PHP 8.3 | Vp_neoteric 1.6

maxispin

Is there any solution for this? I need to show path too.
VM 3.0.17.6 | VM 2.0.24c | VM 1.1.9

PRO

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>

GJC Web Design

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
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

maxispin

VM 3.0.17.6 | VM 2.0.24c | VM 1.1.9

maxispin

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>
VM 3.0.17.6 | VM 2.0.24c | VM 1.1.9

maxispin

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 (
== $params->get('show_images')) {
                        
$image $images[0]->file_url_thumb;
                } else if (
== $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>';
}
VM 3.0.17.6 | VM 2.0.24c | VM 1.1.9


maxispin

VM 3.0.17.6 | VM 2.0.24c | VM 1.1.9