VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: caesarsk on July 03, 2018, 13:39:44 PM

Title: multiple images in the category view
Post by: caesarsk on July 03, 2018, 13:39:44 PM
Hi all,

in older versions of VM I had made showing second image in the category view.
code:
if(isset($product->images[1])){
echo $product->images[0]->displayMediaThumb('class="browseProductImage MoreImg"', false);
echo $product->images[1]->displayMediaThumb('class="browseProductSecondImage"', false);
} else {
echo $product->images[0]->displayMediaThumb('class="browseProductImage theOne"', false);
}


but in new versions this code not working. $product->images return only one image.

my question.
$product->virtuemart_media_id return all media resorces. But how should I do this so that the function displayMediaThumb returns a thumb link?
I try luck with $product->virtuemart_media_id[1]->displayMediaThumb('class="browseProductSecondImage"', false);, but this no work.

I know how to make it "drastically", but I'd like to have it sorted out nicely. If it does.

any idea?
Title: Re: multiple images in the category view
Post by: caesarsk on July 03, 2018, 18:59:05 PM
here is not nice solution, but for me is quick and works.
1. override template com_virtuemart/sublayouts/products.php
2. paste function on beginning of the file (function return link to thumb of second image):

function secondImage ($id_1,$file_0_title,$thumb_path,$thumb_0_title){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName('file_title'))
->from($db->quoteName('#__virtuemart_medias'))
->where($db->quoteName('virtuemart_media_id') . " = '" . $id_1 . "'")
->setLimit('1');
$db->setQuery($query);
$result = $db->loadResult();

$explode_title_0 = explode('.',$file_0_title);
$suffix = str_replace($explode_title_0[0],"",$thumb_0_title);
$explode_title_1 = explode('.',$result);

$link_1 = $thumb_path . $explode_title_1[0] . $suffix . '.' . $explode_title_1[1];
return($link_1);
}


3. add <img src=""> tag, for example like this:

// this is original VM thumb
echo $product->images[0]->displayMediaThumb('class="browseProductImage"', false);

// this is second image
echo '<img src="'. secondImage($product->virtuemart_media_id[1],$product->images[0]->file_title,$product->images[0]->file_url_folder_thumb,$product->images[0]->file_name_thumb) . '" class="browseProductSecondImage">';
Title: Re: multiple images in the category view
Post by: Studio 42 on July 03, 2018, 20:33:19 PM
You can use VM core, add in your file JOOMLAROOT\administrator\components\com_virtuemart\virtuemart.cfg
prodimg_browse=2

then 2 images are loaded and you can use
                  <?php
                  echo $product->images[0]->displayMediaThumb('class="browseProductImage"', false);
                  ?>
                  <?php
                  if(!empty($product->images[1] ))
                     echo $product->images[1]->displayMediaThumb('class="browseProductImage"', false);
                  ?>
Title: Re: multiple images in the category view
Post by: caesarsk on July 03, 2018, 21:49:38 PM
yop, this is elegant solution. but update rewrite this, right?
Title: Re: multiple images in the category view
Post by: Studio 42 on July 03, 2018, 22:59:54 PM
No, if you do an overrdie in your template folder, then the PHP code is not modified on Virtuemart Update.
virtuemart.cfg is never modified as i know you have a virtuemart.default.cfg used on install firts time.
But you need to edit VM config and save, so the settings get saved in the Vm config table.
Title: Re: multiple images in the category view
Post by: caesarsk on July 03, 2018, 23:26:35 PM
perfect, thx very much
Title: Re: multiple images in the category view
Post by: caesarsk on July 03, 2018, 23:32:48 PM
doesnt work :(
Title: Re: multiple images in the category view
Post by: Studio 42 on July 04, 2018, 00:02:35 AM
Your VM release is ?
Have you try using protostar ?
Title: Re: multiple images in the category view
Post by: caesarsk on July 04, 2018, 07:44:05 AM
I have own template. VM 3.2.14
Title: Re: multiple images in the category view
Post by: Studio 42 on July 04, 2018, 11:07:57 AM
try to print_r($product->images);
Title: Re: multiple images in the category view
Post by: caesarsk on August 22, 2018, 00:02:55 AM
Quote from: Studio 42 on July 04, 2018, 11:07:57 AM
try to print_r($product->images);

jop, your solution works perfect. thx for help :)
Title: Re: multiple images in the category view
Post by: neleausta on January 17, 2020, 16:45:37 PM
Not working in the latest release VirtueMart 3.4.2, any solution?
Title: Re: multiple images in the category view
Post by: neleausta on January 17, 2020, 17:43:54 PM

I found a solution:
in "\components\com_virtuemart\views\category\view.html.php"
change
"$imgAmount = VmConfig::get('prodimg_browse',1);" to "$imgAmount = VmConfig::get('prodimg_browse',X);"
where X is the number of images you want to display

Then recall these images in the category layout