Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Add Download File Size to Product Info Page

    I would like to know if it's possible to add the filesize in Mb's of each download part to the product info page like in the attached example....not in red though of course, that's just to highlight where I want it if possible to get it there LOL

    My product info pages, you can see an example of one here:

    http://www.havendesignz.com/store/in...products_id=91

    I *think* the filesize displays in the download section after purchase but I'm not overly sure of that, and if this can be done I would really appreciate a hand on how :)
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  2. #2
    Join Date
    Jan 2006
    Posts
    117
    Plugin Contributions
    0

    Default Re: Add Download File Size to Product Info Page

    It is possible, as I have done it. However, I set up the system back on zencart 1.2 when there was no existing measure of filename, and I noticed when I upgraded to 1.3.8 that there was some language already existing for the filesize in the english.php file.

    The way I did it was to add a filesize variable into the database that works almost exactly like the weight variable. I have to manually put in the filesize for each product, though I suspect there is a PHP way that it could have been automatically read, this was just simpler to code. I basically copied the language and display and entry systems from weight (ignoring any place the site actually uses the weight, eg: for shipping.

    I'd actually be curious to know what the filesize language variables are used for in zen 1.3.8. If there is no way to easily do it on the current zen, I can talk you through what I did; it wasn't that hard. But I'll wait and see if there are any more integrated suggestions.

  3. #3
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Add Download File Size to Product Info Page

    This is the code in my tpl_modules_downloads.php and I'm highlighting in red the sections I believe build and output the filesize, I am just not overly sure exactly how to implement that where I want it without screwing it up LOL

    Code:
    <?php
    /**
     * Module Template
     *
     * @package templateSystem
     * @copyright Copyright 2003-2006 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_modules_downloads.php 6374 2007-05-25 20:24:42Z drbyte $
     */
    /**
     * require the downloads module
     */
      require(DIR_WS_MODULES . zen_get_module_directory('downloads.php'));
    ?>
    
    <?php
    // download is available
      if ($downloads->RecordCount() > 0) {
    ?>
    
    <table border="0" width="100%" cellspacing="0" cellpadding="0" id="downloads">
    <caption><h4><?php echo HEADING_DOWNLOAD; ?></h4></caption>
      <tr class="tableHeading">
          <th scope="col" id="dlFileNameHeading"><?php echo TABLE_HEADING_PRODUCT_NAME; ?></th>
          <th scope="col" id="dlByteSize"><?php echo TABLE_HEADING_BYTE_SIZE; ?></th>
          <th scope="col" id="dlButtonHeading"><?php echo TABLE_HEADING_DOWNLOAD_FILENAME; ?></th>
          <th scope="col" id="dlDateHeading"><?php echo TABLE_HEADING_DOWNLOAD_DATE; ?></th>
          <th scope="col" id="dlCountHeading"><?php echo TABLE_HEADING_DOWNLOAD_COUNT; ?></th>
          <th scope="col" id="dlButtonHeading">&nbsp;</th>
              </tr>
    <!-- list of products -->
    <?php
        while (!$downloads->EOF) {
    // MySQL 3.22 does not have INTERVAL
          list($dt_year, $dt_month, $dt_day) = explode('-', $downloads->fields['date_purchased_day']);
          $download_timestamp = mktime(23, 59, 59, $dt_month, $dt_day + $downloads->fields['download_maxdays'], $dt_year);
          $download_expiry = date('Y-m-d H:i:s', $download_timestamp);
    
          $is_downloadable = ( (file_exists(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']) && (($downloads->fields['download_count'] > 0 && $download_timestamp > time()) || $downloads->fields['download_maxdays'] == 0)) ) ? true : false;
          $zv_filesize = filesize (DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']);
          if ($zv_filesize >= 1024) {
            $zv_filesize = number_format($zv_filesize/1024/1024,2);
            $zv_filesize_units = TEXT_FILESIZE_MEGS;
          } else {
            $zv_filesize = number_format($zv_filesize);
            $zv_filesize_units = TEXT_FILESIZE_BYTES;
          }
    ?>
              <tr class="tableRow">
    <!-- left box -->
    <?php
    // The link will appear only if:
    // - Download remaining count is > 0, AND
    // - The file is present in the DOWNLOAD directory, AND EITHER
    // - No expiry date is enforced (maxdays == 0), OR
    // - The expiry date is not reached
    
    //      if ( ($downloads->fields['download_count'] > 0) && (file_exists(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename'])) && ( ($downloads->fields['download_maxdays'] == 0) || ($download_timestamp > time())) ) {
          if  ($is_downloadable) {
    ?>
          <td class=""><?php echo '<a href="' . zen_href_link(FILENAME_DOWNLOAD, 'order=' . $last_order . '&id=' . $downloads->fields['orders_products_download_id']) . '">' . $downloads->fields['products_name'] . '</a>'; ?></td>
    <?php } else { ?>
          <td class=""><?php echo $downloads->fields['products_name']; ?></td>
    <?php
          }
    ?>
          <td class=""><?php echo $zv_filesize . $zv_filesize_units; ?></td>
          <td class=""><?php echo $downloads->fields['orders_products_filename']; ?></td>
          <td class=""><?php echo ($downloads->fields['download_maxdays'] == 0 ? TEXT_DOWNLOADS_UNLIMITED : zen_date_short($download_expiry)); ?></td>
          <td class="centeredContent"><?php echo ($downloads->fields['download_maxdays'] == 0 ? TEXT_DOWNLOADS_UNLIMITED_COUNT : $downloads->fields['download_count']); ?></td>
          <td class="centeredContent"><?php echo ($is_downloadable) ? '<a href="' . zen_href_link(FILENAME_DOWNLOAD, 'order=' . $last_order . '&id=' . $downloads->fields['orders_products_download_id']) . '">' . zen_image_button(BUTTON_IMAGE_DOWNLOAD, BUTTON_DOWNLOAD_ALT) . '</a>' : '&nbsp;'; ?></td>
        </tr>
    <?php
        $downloads->MoveNext();
        }
    ?>
      </table>
    
    <?php
    // old way
    //    if (!strstr($PHP_SELF, FILENAME_ACCOUNT_HISTORY_INFO)) {
    // new way
          if (!($_GET['main_page']==FILENAME_ACCOUNT_HISTORY_INFO)) {
    ?>
    <p><?php printf(FOOTER_DOWNLOAD, '<a href="' . zen_href_link(FILENAME_ACCOUNT, '', 'SSL') . '">' . HEADER_TITLE_MY_ACCOUNT . '</a>'); ?></p>
    <?php } else { ?>
    <?php
    // other pages if needed
          }
    ?>
    
    <?php
    } // $downloads->RecordCount() > 0
    ?>
    
    <?php
    // download is not available yet
    if ($downloads_check_query->RecordCount() > 0 and $downloads->RecordCount() < 1) {
    ?>
     <fieldset><?php echo DOWNLOADS_CONTROLLER_ON_HOLD_MSG ?></fieldset>
    <?php
    }
    ?>
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  4. #4
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Add Download File Size to Product Info Page

    I just realised that since my internet went haywire for a sec yesterday and helped me create duplicate posts LOL which a mod has so kindly removed for me (thank you!) this post doesn't have the attachment I reference in the first post, so attaching here cos the visual helps for seeing where I wanna put the code
    Attached Images Attached Images  
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  5. #5
    Join Date
    Jan 2006
    Posts
    117
    Plugin Contributions
    0

    Default Re: Add Download File Size to Product Info Page

    There are two issues. The first is "part 1 of 3". Is that "part 1 of 3 of Download 1" or "Download 1 is part 1 of 3 of the whole thing"?

    Because the first thing I'll say is that if you have a 3 part download and you want to total filesize, the filesize output (you posted) is probably going to be harder to impliment.

    The other issue is that even if you want each download's filesize to post with the attribute, the problem is that the code you mention is in the download module; The only pages that call that module are the checkout and account pages (the pages where you can actually do the download). The first line of that template (all you have there is a template) is a call to the actual downloads.php module. The Module will show you that the Query which creates $downloads is as follows:

    Code:
    $downloads_query = "select date_format(o.date_purchased, '%Y-%m-%d') as date_purchased_day,
                                 opd.download_maxdays, op.products_name, opd.orders_products_download_id,
                                 opd.orders_products_filename, opd.download_count, opd.download_maxdays
                          from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, "
    . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " opd
                          where o.customers_id = '" . (int)$_SESSION['customer_id'] . "'
                          and (o.orders_status >= '" . DOWNLOADS_CONTROLLER_ORDERS_STATUS . "'
                          and o.orders_status <= '" . DOWNLOADS_CONTROLLER_ORDERS_STATUS_END . "')
                          and o.orders_id = '" . (int)$last_order . "'
                          and o.orders_id = op.orders_id
                          and op.orders_products_id = opd.orders_products_id
                          and opd.orders_products_filename != ''";
    
    $downloads = $db->Execute($downloads_query);
    As you can hopefully see, this query pulls the download_id WHERE the customer is the one viewing the order, and the order has the downloadable product. So clearly this is not a viable option for displaying the filesize on the product_info page; that template only looks at the attribute, not the download. So what you would have to do if you are set on having an automated system is create a brand new query that looks at the attribute being displayed, sees if it is associated with a download, and then pull the 'orders_products_filename', and at THAT point, you can use the code you placed in red to display the filesize.

  6. #6
    Join Date
    Jan 2006
    Posts
    117
    Plugin Contributions
    0

    Default Re: Add Download File Size to Product Info Page

    This actually intrigued me, and due to your posting of the filesize code, I took it upon myself to automate the filesize (I believe when I set it up manually, I did not know enough php/sql to properly deal with it.

    But I do now! This is code that will add the TOTAL filesize of all attributes to the page; If you need them separate, you can modify it (I'll mention below).

    On the product_info page's Modules/pages/product_info/header_php.php (and any other module for other product types), you will need to add this (the first line is already there, the second line is modified with an else):

    Code:
        header('HTTP/1.1 404 Not Found');
      } else {	
      //~~~! Add download filesize check
    	$downloads_query = "select pa.products_attributes_id , pa.products_id, pad.products_attributes_filename as filename
                          from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
                          where pa.products_id = '" . (int)$_GET['products_id'] . "'
    					  and pa.products_attributes_id = pad.products_attributes_id";
    	$downloads = $db->Execute($downloads_query);
    }
    What this does is, ELSE (ie: if NOT "there is no product with that product_id"), grab the filename of any download attribute associated with that product_id.

    Then, in your product template you need to add the following wherever you want the filesize to appear:
    Code:
    	<?php 
    		//calculate filesize
    			$filesize = 0;
    	    while (!$downloads->EOF) {
    			$filesize = $filesize + filesize (DIR_FS_DOWNLOAD . $downloads->fields['filename']);
    			$downloads->MoveNext();
    			}
          if ($filesize >= 1024) {
            $filesize = number_format($filesize/1024/1024,2);
            $filesize_units = TEXT_FILESIZE_MEGS;
          } else {
            $filesize = number_format($filesize);
            $filesize_units = TEXT_FILESIZE_BYTES;
          }
    	 echo (($filesize !=0) ? TEXT_PRODUCT_FILESIZE . $filesize . $filesize_units : '&nbsp;');
    	?>
    Note: TEXT_PRODUCT_FILESIZE is a language variable I added to my custom english.php - or you could add it to a custom language file. TEXT_PRODUCT_FILESIZE is defined as "Filesize: " - you could also hardcode the actual text into the template if you wanted.

    Note: The code in the "While" basically totals the filesizes of all downloads for that product. If you wanted to echo the filesizes one by one, you'd have to do two things: Instead of adding "$filesize + filesize..." you want to move the calculation if statement and the echo into the while, so that it calculates and echos the filesize for each file one by one. BUT the second thing you have to do is figure out a way to get the downloads to echo in the right order. Either you can figure out what is used to sort the attributes and add a SORT BY to the SQL query, or you could probably use the attribute_id to identify which download is which, but I'm not going to get into that myself.

    Hope this helps. I'm guessing it's quite possible to use similar techniques to have filesizes appear on product listing pages, and or other places, but it's easiest on the product_info page, because there is only one product to lookup, not multiple.

  7. #7
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Add Download File Size to Product Info Page

    Thanx! I am going to try this....I may have a small problem though that I didn't think about before...I have one product and most likely more to be added similar, where I have a drop down choice between two download sizes and I am guessing that this might add up both of those downloads into the one total size? I can always pop something into the description about that though or seperate them into two products lol

    http://www.havendesignz.com/store/pa...apers-01-p-135

    *going off to try it now*
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  8. #8
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Add Download File Size to Product Info Page

    Unfortunately when I did this I got a blank page on my product info page, so I restored the files and will have another look later on to see where I might have gone wrong LOL
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  9. #9
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Add Download File Size to Product Info Page

    Revisiting this thread to add that while it did not work on my previous store...and I have no idea why, user error most likely LOL the above code is implemented and working great on my new store :)

    Example: http://www.amomentinscrap.com/shop/d...d-joy-page-kit
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  10. #10
    Join Date
    Apr 2004
    Location
    UK
    Posts
    5,821
    Plugin Contributions
    2

    Default Re: Add Download File Size to Product Info Page

    Quote Originally Posted by LissaE View Post
    Revisiting this thread to add that while it did not work on my previous store...and I have no idea why, user error most likely LOL the above code is implemented and working great on my new store :)

    Example: http://www.amomentinscrap.com/shop/d...d-joy-page-kit
    Looks great..well done...can you just clarify exact file name
    where 2nd block of code is entered...not clear in that post, so other members wishing to use code may get confused.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. How to download directly off product info page
    By Parafanaylya in forum General Questions
    Replies: 43
    Last Post: 1 Aug 2015, 08:35 PM
  2. Digital Download File Size Cap?
    By bowserhound in forum General Questions
    Replies: 12
    Last Post: 1 Sep 2010, 06:25 PM
  3. How to Use Medium Size Pic. in Product Info. Page?
    By Stenrique in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 20 Oct 2006, 10:39 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