VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: dstockman on April 15, 2017, 22:26:03 PM

Title: Get Child Category Image in Category Module
Post by: dstockman on April 15, 2017, 22:26:03 PM
I tried to post this in the frontend modules forum but it kept blocking my post as a duplicate.

I am trying to adapt the virtuemart category module to show all the categories and child categories in blocks with a header with the name and the main image underneath. Sort of a meld of the all (shows all) and wall (shows only parent cats I think with images) modules, if you will. I have gotten them all to list and grabbed the media for the parent categories however this way it shows the thumbnail for the parent category not the child in the second/child instance (4th line from end).

Here is my module code:


<div class="<?php echo $class_sfx?>">
<?php 
$categoryModel->addImages($categories);
foreach ($categories as $category) {
$active_menu '';
$caturl JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$category->virtuemart_category_id);
$cattext $category->category_name;
if (in_array$category->virtuemart_category_id$parentCategories)) $active_menu 'class="active"';
?>

<div class="category col-xs-3 col-md-3 col-lg-3 vertical-separator">
<a href="<?php echo $caturl?>">
<div><h2><?php echo $cattext?></h2>
<?php echo $category->images[0]->displayMediaThumb('class=" "',false?></div></a></div>
<?php if ($category->childs ) {
foreach ($category->childs as $child) {
$caturl JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$child->virtuemart_category_id);
$cattext vmText::_($child->category_name);
?>

<div class="category col-xs-3 col-md-3 col-lg-3 vertical-separator">
<a href="<?php echo $caturl?>">
<div><h2><?php echo $cattext?></h2>
<?php echo $category->images[0]->displayMediaThumb('class=" "',false?></div></a></div>
<?php }}} ?>
</div>
<div class="clear"></div>



Some things I've tried that did not work:

$categoryModel->addImages($categories->children);  (tried adding this right under $categoryModel->addImages($categories))

I also tried each of these in place of the second $category->images[0]-> with and without the above:

$child->images[0]->
$category->childs->images[0]->
$category->$child->images[0]->
$this->category->children->images[0]->
$this->category->childs->images[0]->
$this->category->$child->images[0]->

Errors I get with $child->images[0]-> which I thought was best guess:

And with $category->childs->images[0]->:

I guess I could get the category ID, look it up in db media table and then return the file_url but I am hoping that I am just missing something simpler here.

Also, I do not think I want use echo ShopFunctionsF::renderVmSubLayout('categories',array('categories'=> $this->category->children)) since I want these child categories to fold right into the list after their parent and that seems to set them in their own templated blocks separately.

I just want to echo the file url for the child category main image (yes, they all have images). I did look through this post https://forum.virtuemart.net/index.php?topic=97744.0 which gave me many of the other ideas I tried, (thanks banquet pro for that post!) but have not come up with the right answer yet.

I am working on this on a fully updated Joomla 3.6.5/VirtueMart 3.2.1 site.

Thanks for any help.


EDIT: I should add I also first had tried some versions of echo ShopFunctionsF::renderVmSubLayout('categories',array('categories'=> $this->category->children))  with $category, $this->category, $categories->category, etc. and was not able to get that to cough up the full list including children. I want to generate the full category list as a flattened list with each category's (including children) image so maybe there is a way to render that with that. If I discover the answer myself I will update.