Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    2
    Plugin Contributions
    0

    Default [Done 1.3.9] media_manager.php sets $zv_product_has_media incorrectly

    Zen Cart v1.3.8a

    I was having trouble getting media collections to display on product pages. The files were being uploaded properly, and the products were there in the "assign to" box, and the assignment seemed to be taking place, and the media manager block of code was showing up in the final product page - but the block in the final page was almost always empty (it did work for some products, tho.)

    Looking through the forums I saw a couple of other reports of this happening, which only ever seemed to be fixed by deleting the products and restarting.

    Looking at the code, I noticed that in tpl_modules_media_manager.php the variable $zv_product_has_media was evaluating "false", so I looked at modules/media_manager.php to see why.

    What I found is that the initial query ( $zv_collection_query ) was returning multiple "media IDs" for a product that I know only had a single collection assigned to it.

    Moreover, as the code then iterated over those IDs looking eventually for the actual clips, some of the queries were failing to find data and $zv_product_has_media was being set to "false" - even though there was valid media found for one of the IDs.

    There appear to be 2 issues going on here:

    a) In modules/media_manager.php, $zv_product_has_media should initially be set to "false" (as it currently is), and then if ANY valid media clip is found it should be set to "true". No condition should ever set it to "false" again.

    This change is enough to cause the cart to work properly, and should be made, but it doesn't address the root issue, I don't think.

    b) Now, I'm just a Zen cart noob, and don't know much about the database structure, but it appears to me that when a media collection (or clip) is deleted using the "media manager" the relation assigning it to a product is not being removed from TABLE_MEDIA_TO_PRODUCTS. That;s deeper in the code that I want to look, however.

    -jim berry

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

    Default Re: media_manager.php sets $zv_product_has_media incorrectly

    Does it help if you simply add the following to the end of the /includes/modules/media_manager.php file? (before the closing ?> line)
    Code:
    $zv_product_has_media = (sizeof($za_media_manager)) > 0 ? TRUE : FALSE;
    This should help prevent incorrect display in cases where incorrect cleanup has occurred.

    The following post contains a code fix to prevent incorrect cleanup ...
    .

    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
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: media_manager.php sets $zv_product_has_media incorrectly

    Making the following edit to the /admin/media_manager.php file should help ensure better cleanup when deleting items from the media-manager screens:

    Find this line (approx line 106):
    Code:
            $db->Execute("delete from " . TABLE_MEDIA_MANAGER . "
                          where media_id = '" . (int)$media_id . "'");
    and add these lines immediately after it:
    Code:
            $db->Execute("delete from " . TABLE_MEDIA_TO_PRODUCTS . "
                          where media_id = '" . (int)$media_id . "'");
            $db->Execute("delete from " . TABLE_MEDIA_CLIPS . "
                          where media_id = '" . (int)$media_id . "'");
    .

    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.

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

    Default Re: media_manager.php sets $zv_product_has_media incorrectly

    And you can probably clean up orphaned data by running the following SQL:
    Code:
    delete from media_to_products where media_id not in (SELECT media_id FROM media_manager);
    delete from media_clips where media_id not in (SELECT media_id FROM media_manager);
    .

    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.

  5. #5
    Join Date
    Jan 2009
    Posts
    2
    Plugin Contributions
    0

    Default Re: media_manager.php sets $zv_product_has_media incorrectly

    Quote Originally Posted by DrByte View Post
    Does it help if you simply add the following to the end of the /includes/modules/media_manager.php file? (before the closing ?> line)
    Code:
    $zv_product_has_media = (sizeof($za_media_manager)) > 0 ? TRUE : FALSE;
    Not really.

    $zq_media_manager is assigned in a loop, and that only checks whether or not the LAST collection assigned to the product has a non-empty $zq_media_manager.

    Also, it's not really the size of $zq_media_manager that's the issue - it's certainly possible for the query that populates $zf_media_manager_query to say that "Yeah, there's clips" when in fact the clips themselves are not in the DB. Yeah, it shouldn't happen. But it's what WAS happening.

    A simpler approach which will always do the right thing is simply to remove all assignments to $zv_product_has_media except for the first one, at the top of the file, which initializes it to false.

    Then, father down, where it actually fetches the clip names, change:

    Code:
          $zq_clips = $db->Execute($zv_clips_query);
          if ($zq_clips->RecordCount() < 1) {
            // $zv_product_has_media = false; <-- we removed this, remember?
          } else {
            
            while (!$zq_clips->EOF) {
    to

    Code:
          $zq_clips = $db->Execute($zv_clips_query);
          if ($zq_clips->RecordCount() > 0) {
    
            $zv_product_has_media = true; 
            
            while (!$zq_clips->EOF) {
    Of course, if the clip file doesn't exist the whole thing will come crashing to the ground. Testing it's existence seems like overkill, tho.

    Thanks for the DB cleanup code.

    -jim

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

    Default Re: media_manager.php sets $zv_product_has_media incorrectly

    You'll note that the code change I suggested was for the $za array, not the $zf or $zq variables.
    Using the sizeof check completely ignores the existing false/true lines. I could have told you to delete them, since the line I suggested renders them all moot.
    Nevertheless, if you fix up the data, you should get the right results by making the changes suggested.
    .

    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.

 

 

Similar Threads

  1. v155 [Done v155] Upgrade of config files sets ssl to true
    By badarac in forum Bug Reports
    Replies: 2
    Last Post: 22 Mar 2016, 12:46 PM
  2. Replies: 1
    Last Post: 2 Nov 2010, 12:22 PM
  3. Replies: 14
    Last Post: 24 Apr 2010, 07:04 AM
  4. Replies: 5
    Last Post: 30 Mar 2010, 11:48 PM

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