News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

multiple images in the category view

Started by caesarsk, July 03, 2018, 13:39:44 PM

Previous topic - Next topic

caesarsk

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?

caesarsk

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">';

Studio 42

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);
                  ?>

caesarsk

yop, this is elegant solution. but update rewrite this, right?

Studio 42

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.

caesarsk



Studio 42

Your VM release is ?
Have you try using protostar ?

caesarsk


Studio 42


caesarsk

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 :)

neleausta

Not working in the latest release VirtueMart 3.4.2, any solution?

neleausta


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

rupan@joomlapro.com

Will the solution be overridden when updating the VirtueMart version? Any other ways with custom template overrides in VirtueMart?

Ghost

Yes, this will be overwritten. You can instead add the option to virtuemart.cfg.