Author Topic: How to display the real sum of displayed additional images?  (Read 382 times)

hazael

  • Beginner
  • *
  • Posts: 35
    • Biżuteria etniczna i orientalna
  • VirtueMart Version: 3.2.14
I hid some of the images using the class names - My modification:
Code: [Select]
$start_image = VmConfig::get('add_img_main', 1) ? 0 : 1;
for ($i = $start_image; $i < count($this->product->images); $i++) {
$image = $this->product->images[$i];
if ((strstr($image->file_class, "class-1")!==False) || (strstr($image->file_class, "class-2")!==False)) {
echo  $image->displayMediaThumb("",true,"rel='vm-additional-images'",true,$image->file_description);
}}
My problem - variable $i  shows 100% of images (with hidden ones).  How to do it so that the variable $i shows the actual number of display images?

Jörgen

  • Global Moderator
  • Full Member
  • *
  • Posts: 2158
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: How to display the real sum of displayed additional images?
« Reply #1 on: July 29, 2018, 16:41:13 pm »
If you can hide images as your code sais. Simply create a new var $iv that counts the visible images. Simply put in your loop.
Regards
Jörgen @ Kreativ Fotografi
Joomla 3.9.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

hazael

  • Beginner
  • *
  • Posts: 35
    • Biżuteria etniczna i orientalna
  • VirtueMart Version: 3.2.14
Re: How to display the real sum of displayed additional images?
« Reply #2 on: July 29, 2018, 17:20:19 pm »
OMG. I'm stupid - it's simple :)

Quote
$real = 0;
$start_image = VmConfig::get('add_img_main', 1) ? 0 : 1;
for ($i = $start_image; $i < count($this->product->images); $i++) {
$image = $this->product->images[$i];
if ((strstr($image->file_class, "class-1")!==False) || (strstr($image->file_class, "class-2")!==False)) {
$real++
echo  $image->displayMediaThumb("",true,"rel='vm-additional-images'",true,$image->file_description);
}}
echo $real;

Jörgen

  • Global Moderator
  • Full Member
  • *
  • Posts: 2158
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: How to display the real sum of displayed additional images?
« Reply #3 on: July 29, 2018, 21:19:21 pm »
Nice that You got it solved

Jörgen @ Kreativ Fotografi
Joomla 3.9.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3826
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: How to display the real sum of displayed additional images?
« Reply #4 on: July 30, 2018, 00:17:33 am »
Id dont know if this is the core code but
Code: [Select]
$i < count($this->product->images)is bad because he count on each iteration
Code: [Select]
$totalimage = count($this->product->images);
for ($i = $start_image; $i <  $totalimage; $i++) {
is a better code
And you dont need to count in the loop
YOu can do
$real = $totalimage-$start_image;
The complet code is then

Code: [Select]
$start_image = VmConfig::get('add_img_main', 1) ? 0 : 1;
$totalimage = count($this->product->images);
$real = $totalimage-$start_image;
for ($i = $start_image; $i < $totalimage; $i++) {
$image = $this->product->images[$i];
if ((strstr($image->file_class, "class-1")!==False) || (strstr($image->file_class, "class-2")!==False)) {
echo  $image->displayMediaThumb("",true,"rel='vm-additional-images'",true,$image->file_description);
}}
echo $real;