Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need help fixing an old contrib - Report Missing and Unassigned Images


Guest

Recommended Posts

I had this old contribution working in my 2.2 MS2 site for years.  Trying to clean it up and get it running in 2.3.4.1 CE with PHP 7.0

If you have any thumbnails missing from your images folder, it gives you a list of what is missing.  Or comforts you with the news that all images are present.

When browsing my live site the other evening, I stumbled on a product where the thumbnail in public_html/images got whacked somehow.  That's why I'm trying to get this running now...to see what else might be missing.

I've had to clean it up a bit, mostly cosmetic stuff, but...it's displaying a report of all items in the site, whether they have an image assigned or not.  Like this:

missingimages.JPG.a4c8514256c2a9bac359c8b00f293eae.JPG

I'm hoping someone can take a look at this piece of code and maybe...you see something obvious?  The contrib I downloaded is here.

//Change this line if you keep your images stored in a strange directory.
  //Don't touch it unless you're having problems.
  $image_directory = DIR_FS_CATALOG . DIR_WS_IMAGES;
  

  /*  ** Image Columns **
   *  If you have various image contributions installed and have more than one  
   *  image column in your database, add additional items to this array to include them.
   *  For example, if you have UltraPics installed, the array would look like this:
   *  $image_columns = array('products_image',
   *                         'products_image_med', 	
   *                         'products_image_lrg', 	
   *                         'products_image_sm_1', 	
   *                         'products_image_xl_1', 	
   *                         'products_image_sm_2', 	
   *                         'products_image_xl_2', 	
   *                         'products_image_sm_3', 	
   *                         'products_image_xl_3', 	
   *                         'products_image_sm_4', 	
   *                         'products_image_xl_4', 	
   *                         'products_image_sm_5', 	
   *                         'products_image_xl_5', 	
   *                         'products_image_sm_6', 	
   *                         'products_image_xl_6');
   */
  $image_columns = array('products_image');
  
  /* ------------------ STOP EDITING HERE -------------------- */
  
  $column_query_string = '';
  $image_count = 0;
  
  foreach ($image_columns as $column) {
    if ($column_query_string != '') $column_query_string .= ', ';
    $column_query_string .= $column;
  }
  
  $image_array = array();
  $images_query = tep_db_query("SELECT products_id, " . $column_query_string . " FROM " . TABLE_PRODUCTS);
  
  while ($row = tep_db_fetch_array($images_query)) {
    $image_array[$row['products_id']] = array();
    
    foreach ($image_columns as $column) {
      if ($row[$column] != '') {
        $image_array[$row['products_id']][] = array('image' => $row[$column], 'column' => $column);
        $image_count++;
      }
    }
  }
  
  /* Our image array is now built, start checking files. */
  $missing_images = array();
  
  foreach ($image_array as $id => $product) {
    foreach ($product as $image) {
      if (!is_file($image_directory . $image['image'])) {
        if (!is_array($missing_images[$id])) $missing_images[$id] = array();
        
        $missing_images[$id][] = $image['image'] . '&nbsp;&nbsp;<i>(Col: ' . $image['column'] . ')</i>';
      }
    }
  }
?>
      <tr>
        <td class="main">
<?  if (count($missing_images) > 0) { ?>
          <table border="0" width="100%" cellspacing="0" cellpadding="0">
            <tr>
              <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                <tr class="dataTableHeadingRow">
                  <td class="dataTableHeadingContent" align="center" width="30"><?php echo TABLE_HEADING_PRODUCT_ID; ?></td>
                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCT_NAME; ?></td>
                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCT_IMAGES; ?></td>
                </tr>
<?
      foreach ($missing_images as $id => $files) { 
        $product_query = tep_db_query("SELECT products_name FROM products_description WHERE products_id = '" . (int)$id . "' AND language_id = '" . ($language_id > 0 ? (int)$language_id : '1') . "'");
        $product = tep_db_fetch_array($product_query);
?>
                <tr>
                  <td class="dataTableContent" align="center" width="30"><? echo $id; ?></td>
                  <td class="dataTableContent"><a href="<? echo tep_href_link('categories.php', 'pID=' . $id . '&action=new_product') . '">' . $product['products_name']; ?></a></td>
                  <td class="dataTableContent">
<?     
        foreach ($files as $f) {
          echo $f . '<br />';
        }
?>
                  </td>
                </tr>
                <tr>
                  <td colspan="3" style="padding: 0px; height: 1px; font-size: 1px; background-color: #EFEFEF"></td>
                </tr>
<?
      }
?>
                </tr>
              </table></td>
            </tr>
          </table>
<?
    } else { ?>
          <table border="0" width="100%" height="100">
            <tr>
              <td class="main" valign="middle" align="center"><b><h2>Congratulations!</h2><br />You have <? echo $image_count . ' product image' . ($image_count == 1 ? '' : 's'); ?> in your store and they are all accounted for!</b></td>
            </tr>
          </table>
<?  } ?>
        </td>
      </tr>
    </table></td>

See anything interesting?  Your help is most appreciated - thank you!

- Andrea

Link to comment
Share on other sites

@puggybelle

In the latest Community Edition, many of the paths are now hard coded. Find:

  $image_directory = DIR_FS_CATALOG . DIR_WS_IMAGES;

and try changing it to something like this:

  $image_directory = DIR_FS_CATALOG . 'images/' ;

(you may have to play with the leading and trailing '/' )

HTH

Malcolm

Link to comment
Share on other sites

Thank You, @ArtcoInc - that was it!  Feeling foolish after being 'wise' enough to correct some other hard-coded entries before testing it.  Thanks very much for taking the time to look it over - I appreciate it!

missingfixed.JPG.a01af9fb7c54c059cec3a32b0a800ba4.JPG

@valquiria23 - how does one update an existing contribution?  This one is probably a decade old, but very useful.

- Andrea

Link to comment
Share on other sites

Hi Andrea, how are you?

You have to go to the addon page: https://apps.oscommerce.com/Mzfqi&report-missing-and-unassignes-images

and touch the submit update button.

I am not a coder,  but if you send me the updated zip file I can add screenshots and an image and upload ( giving you all the credits).

Or maybe it would be nice to upload it directly as a new addon for version 2.3.

Best regards

Valqui

update.thumb.jpg.d82c47e11ff430bbb148d19b0ae7965a.jpg

 

:heart: Community Oscommerce fan :heart: You'll find the latest osC community version here.

 

Link to comment
Share on other sites

Hi Andrea @puggybellehow are you?

Did you manage to run this addon?

I managed to put it in the reports menu, adding this code to the array in the file catalog / admin / includes / boxes / reports.php

array (
         'code' => 'missing_pics.php',
         'title' => 'Missing Pictures',
         'link' => tep_href_link ('missing_pics.php')
       )

But when I click on "Missing Pictures" it shows me the missing files correctly (see image) but then the style of the page is broken.

The other problem he gives me is that he says: "Congratulations! You have 30, all products are with images! "When not all the 30 images are present....

Some brave who can take a look a it? Attached ZIP file with the files and installation instructions that you modify.

Best regards

Valqui

1755283013_Sinimagen.thumb.jpg.cd19ce54d03a7a208c3c1de8b9d7e179.jpg

 

Report Missing and Unassigned Images.zip

:heart: Community Oscommerce fan :heart: You'll find the latest osC community version here.

 

Link to comment
Share on other sites

1 hour ago, valquiria23 said:

Did you manage to run this addon?

Run's fine but your zip file has old code which needs updating. Also this add-on is only usable if you have only one image per product and all images are in one dir..

image.thumb.png.157956838bfb1b271f062f06445b457b.png

 

Link to comment
Share on other sites

Hi Andrea @puggybelle,

Your file did the magic, excellent work!
Just a little problem, if the image is located in the catalog / images directory the link to that product does not appear. The name of the file and its ID did appear.

please watch attachment screenshot.

If it does not bother you, when it works I willupload it as a new addon so the rest of the community will enjoy it too :) 

Best regards.

Valqui

1210301514_Sinttulo.jpg.802932799c47a837d98032a3e680e0a1.jpg

:heart: Community Oscommerce fan :heart: You'll find the latest osC community version here.

 

Link to comment
Share on other sites

Hi Zahid @JcMagpie, how are you?

9 minutes ago, JcMagpie said:

Run's fine but your zip file has old code which needs updating. Also this add-on is only usable if you have only one image per product and all images are in one dir..

Yes, that's right, I did not know how to adapt the code even though I was fighting with it  :) Andrea did it wonderfully. 

Yes, the code need an apdate, but at least serve to detect if the main image is missing, that image is the most important because it is the first view by the client, and if it is not found its left a bad taste of the web site ... .

Best regards

Valqui

:heart: Community Oscommerce fan :heart: You'll find the latest osC community version here.

 

Link to comment
Share on other sites

32 minutes ago, valquiria23 said:

Just a little problem, if the image is located in the catalog / images directory the link to that product does not appear. The name of the file and its ID did appear.

I don't know why that's happening on your site.  The product name appears just fine in mine.  I'm using the identical missing_pics.php file I posted before.

missingpics.JPG.c181561d77807a595eca327f116a22d7.JPG

Are you sure the product with the missing image actually has a product name assigned to it?  Your first screenshot shows some products with and without names.

- Andrea

Link to comment
Share on other sites

Hi, Andrea @puggybelle,

All my products have product name.
In my first screenshot the product name of the articles that are inside a directory like /images/matrox/ was shown correct , but the product name of the articles within the folder /images are not shown.

I do not know why that happens, have your store is in the root or inside in a folder like CATALOG?
The same thing happens to me in my new Frozen store just installed and in a live EDGE store older than frozen.

Can someone else try it and tell us how it was?

Thank you very much !!

Valqui

:heart: Community Oscommerce fan :heart: You'll find the latest osC community version here.

 

Link to comment
Share on other sites

Hi, Andrea @puggybelleI found the problem,

My store is only in Spanish and you can see that the following code brings only the product name of the English language, ( $language_id : '1') , therefore its showed me an empty field in the product name. In the first screenshot, the first articles have product name in English and Spanish, but the new ones only in Spanish and that's why they were not shown.

$product_query = tep_db_query("SELECT products_name FROM products_description WHERE products_id = '" . (int)$id . "' AND language_id = '" . ($language_id > 0 ? (int)$language_id : '1') . "'");

Changing $language_id : '1' to $language_id : '2' fix the problem !!!

Thank you very much to everyone who helped.

Andrea with your permission I'll put it together in a zip file and upload it as a new addon with the corresponding credits, :)  so everyone can enjoy it !!

Best regards.

Valqui

 

 

 

:heart: Community Oscommerce fan :heart: You'll find the latest osC community version here.

 

Link to comment
Share on other sites

8 hours ago, valquiria23 said:

Andrea with your permission I'll put it together in a zip file and upload it as a new addon with the corresponding credits, :)  so everyone can enjoy it !!

Be my guest!  Glad you got it sorted out.

- Andrea

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...