Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Possible Bug includes/modules/main_product_image.php

    I think possibly I have found a logic flaw with the code in

    includes/modules/main_product_image.php

    when a site has only small and medium images, the logic is using the small image for the $products_image_large due to the variable $products_image_medium being checked a second time.

    original code:
    PHP Code:
    $products_image_extension substr($products_imagestrrpos($products_image'.'));
    $products_image_base str_replace($products_image_extension''$products_image);
    $products_image_medium $products_image_base IMAGE_SUFFIX_MEDIUM $products_image_extension;
    $products_image_large $products_image_base IMAGE_SUFFIX_LARGE $products_image_extension;

    $medium_image_check $products_image_base IMAGE_SUFFIX_MEDIUM $products_image_extension;


    // check for a medium image else use small
    if (!file_exists(DIR_WS_IMAGES 'medium/' $products_image_medium)) {
      
    $products_image_medium DIR_WS_IMAGES $products_image;
    } else {
      
    $products_image_medium DIR_WS_IMAGES 'medium/' $products_image_medium;
    }


    // check for a large image else use medium else use small
    if (!file_exists(DIR_WS_IMAGES 'large/' $products_image_large)) {
      if (!
    file_exists(DIR_WS_IMAGES 'medium/' $products_image_medium)) {
        
    $products_image_large DIR_WS_IMAGES $products_image;
      } else {
        
    $products_image_large DIR_WS_IMAGES 'medium/' $products_image_medium;
      }
    } else {
      
    $products_image_large DIR_WS_IMAGES 'large/' $products_image_large;

    as you can see where the second check is taking place, where it is checking for the medium image, its actually looking for:
    !file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)

    and because $products_image_medium has already been defined, it will never actually find the file its looking for:
    /images/medium/images/medium/12345_MED.jpg

    Perhaps DrByte or someone can clarify incase I have my wires crossed, however I am getting around it by setting an additional variable at the top:
    PHP Code:
    $second_medium_image_check $products_image_base IMAGE_SUFFIX_MEDIUM $products_image_extension
    and then using this to carry out the second check:

    PHP Code:
    if (!file_exists(DIR_WS_IMAGES 'large/' $products_image_large)) {
      if (!
    file_exists(DIR_WS_IMAGES 'medium/' $second_medium_image_check)) {
        
    $products_image_large DIR_WS_IMAGES $products_image;
      } else {
        
    $products_image_large DIR_WS_IMAGES 'medium/' $second_medium_image_check;
      }
    } else {
      
    $products_image_large DIR_WS_IMAGES 'large/' $products_image_large;

    Let me know.

    Cheers

    Phil
    Phil Rogers
    A problem shared is a problem solved.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Possible Bug includes/modules/main_product_image.php

    I suppose if $products_image_medium is already tested and set, then there's no need to look for it again, so simplifying it even further would give you:
    Code:
    // check for a medium image else use small
    if (!file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
      $products_image_medium = DIR_WS_IMAGES . $products_image;
    } else {
      $products_image_medium = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
    }
    
    
    // check for a large image else use medium else use small
    if (!file_exists(DIR_WS_IMAGES . 'large/' . $products_image_large)) {
    /**
      if (!file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
        $products_image_large = DIR_WS_IMAGES . $products_image;
      } else {
        $products_image_large = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
      }
    */
      $products_image_large = $products_image_medium;
    } else {
      $products_image_large = DIR_WS_IMAGES . 'large/' . $products_image_large;
    }
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Possible Bug includes/modules/main_product_image.php

    Quote Originally Posted by DrByte View Post
    I suppose if $products_image_medium is already tested and set, then there's no need to look for it again, so simplifying it even further would give you:
    Code:
    // check for a medium image else use small
    if (!file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
      $products_image_medium = DIR_WS_IMAGES . $products_image;
    } else {
      $products_image_medium = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
    }
    
    
    // check for a large image else use medium else use small
    if (!file_exists(DIR_WS_IMAGES . 'large/' . $products_image_large)) {
    /**
      if (!file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
        $products_image_large = DIR_WS_IMAGES . $products_image;
      } else {
        $products_image_large = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
      }
    */
      $products_image_large = $products_image_medium;
    } else {
      $products_image_large = DIR_WS_IMAGES . 'large/' . $products_image_large;
    }
    Clever clogs ;-)

    I also included similar logic in the additional images file as there is only a large image check in there do again when small and medium used when you click the thumbnail by default zen cart only brings up the small, even though there is a medium.
    Phil Rogers
    A problem shared is a problem solved.

 

 

Similar Threads

  1. Replies: 3
    Last Post: 10 Apr 2013, 03:46 PM
  2. v151 override \includes\modules\pages\shopping_cart\header.php.php??
    By tlyczko in forum General Questions
    Replies: 7
    Last Post: 27 Nov 2012, 06:12 PM
  3. v150 PHP Fatal error: Out of memory in includes/modules/attributes.php
    By donnyb in forum General Questions
    Replies: 0
    Last Post: 6 Apr 2012, 12:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg