News:

Support the VirtueMart project and become a member

Main Menu

[Solved] VM Category Module with images

Started by sagaranvekar, March 14, 2019, 23:03:22 PM

Previous topic - Next topic

sagaranvekar

Hello,

I have Joomla 3.9.2 website with Virtuemart 3.4.2.

I am using mod_virtuemart_category to with 'all' layout.
How can I display images for categories in this module?

When i switch to 'wall' layout, it only displays parent categories with images. But i want to show images for all categories.

When i tried to find out in modules/mod_virtuemart__category/tmpl/all.php
I can get media id with $child->virtuemart_media_id
But is there any way to get full image using this media id?

Tried to find out on forum, but nobody seems to find a way to get it.

Please help.

sagaranvekar

#1
I found solution for this. May be it will help someone else looking for it.
Here is what i did.
In \modules\mod_virtuemart_category\tmpl\all.php
at line no. 4, i added :


$categoryModel->addImages($categories);


Then on line no. 20, i added this:


<div><a href="<?php echo $caturl;?>"><?php echo $category->images[0]->displayMediaFull('class="vm-categories-wall-img"',false?></a></div>


The above code only fetches category image for parent categories. I found this code in  \modules\mod_virtuemart_category\tmpl\wall.php
But for child categories, I ended up firing database query to fetch image url. To do that, on line no. 28 inside foreach loop, i added a query to retrieve file url & then inside <li> tag, i added another <div> tag to add <img> tag like this:


<ul class="menu<?php echo $class_sfx?>">
<?php
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);
/*- fire a query on database to get file url --*/
$dbb JFactory::getDBO();
$qs "SELECT file_url FROM #__virtuemart_medias WHERE virtuemart_media_id = '".$child->virtuemart_media_id[0]."'"//print_r($qs);
$dbb->setQuery($qs);
$results $dbb->loadObjectList();

?>

<li>
<div ><?php echo JHTML::link($caturl$cattext); ?></div>
<div><a href="<?php echo $caturl;?>"><img src="<?php  echo JURI::root () . $results[0]->file_url?>" /></a></div>
</li>
<?php ?>
</ul>


Final all.php looks like this:


<?php // no direct access
defined('_JEXEC') or die('Restricted access');
//JHTML::stylesheet ( 'menucss.css', 'modules/mod_virtuemart_category/css/', false );
$categoryModel->addImages($categories);
?>


<ul class="menu<?php echo $class_sfx ?>" >
<?php 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 ($active_category_id == $category->virtuemart_category_id) $active_menu = 'class="active"';
if (in_array$category->virtuemart_category_id$parentCategories)) $active_menu 'class="active"';

?>


<li <?php echo $active_menu ?>>
<div>
<?php echo JHTML::link($caturl$cattext); ?>
</div>
<div><a href="<?php echo $caturl;?>"><?php echo $category->images[0]->displayMediaFull('class="vm-categories-wall-img"',false?></a></div>
<?php if (!empty($category->childs)) { ?>
<ul class="menu<?php echo $class_sfx?>">
<?php
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);
/*- fire a query on database to get file url --*/
$dbb JFactory::getDBO();
$qs "SELECT file_url FROM #__virtuemart_medias WHERE virtuemart_media_id = '".$child->virtuemart_media_id[0]."'"//print_r($qs);
$dbb->setQuery($qs);
$results $dbb->loadObjectList();

?>

<li>
<div ><?php echo JHTML::link($caturl$cattext); ?></div>
<div><a href="<?php echo $caturl;?>"><img src="<?php  echo JURI::root () . $results[0]->file_url?>" /></a></div>
</li>
<?php ?>
</ul>
<?php  ?>
</li>
<?php
?>

</ul>


And then, i have all category images displayed below category name.

Hope it helps.

Studio 42

Have you try this code ?
foreach ($category->childs as $child) {
  $categoryModel->addImages($child);