Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2010
    Location
    Richmond, Virginia, United States
    Posts
    105
    Plugin Contributions
    0

    Default View downloads from all orders on one page

    I'm looking to create a "library" of sorts on my site, where each customer can log in and find all the download links to their purchased products on their account history page.

    I thought I could do it by implementing the Order History List plugin that I found in this forum, but that only displays the product images and links to the products on my site. There are no download links for each order.

    I've fiddled around with this but don't know PHP enough to get it to work.

    Does anyone know if this has been done before?

  2. #2
    Join Date
    Jul 2012
    Posts
    14,386
    Plugin Contributions
    17

    Default Re: View downloads from all orders on one page

    So basically, although clicking on an order from the customer's own order history would then make it possible to click on the download, you want to "consolidate" that to its own page for the customer to where all such clicks can occur from a single page rather than digging down into each order.

    I would think that if enough information is brought to the page in the order history module that you were working with to click on a link for each such product, that perhaps enough information is or could easily be made available to reference the downloaded item(s) and generate the associated link. Is there nothing about that type action in the forum for the plugin (assuming one exists)?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  3. #3
    Join Date
    Jan 2010
    Location
    Richmond, Virginia, United States
    Posts
    105
    Plugin Contributions
    0

    Default Re: View downloads from all orders on one page

    I run an ebook webstore, so ideally I would like to eliminate the order history page and replace it with the customer's library (books they already purchased).

    All I've managed to do, however, is get the last order's download to show up on that page. I can't seem to get ALL the downloads for that customer to display on the same page.

  4. #4
    Join Date
    Jul 2012
    Posts
    14,386
    Plugin Contributions
    17

    Default Re: View downloads from all orders on one page

    So this isn't exactly a "clean" method of doing this, but it would bring your downloads closer to the account history. It would probably also be better to generate an entirely new "page" instead of modifying the below, but in the few minutes that I have I thought I would try to help with what I found by looking through a few files.

    So, the "normal" process is that once a customer is logged in, they can get to their account order history by going to: index.php?main_page=account_history. There, all of their orders are presented with a link to get to their account_history_information which is accessible by index.php?main_page=account_history_info and will present the template file: includes/templates/template_default/templates/tpl_account_history_info_default.php or its template override. well, on this page is a section that specifically addresses downloads and that section could possibly be pulled out to be presented while looping through the listing of orders that are on the account_history page... Thus, a user could dig down into the order and see other details, or could directly from that page click on the download link as made available.

    So, first things first, if it doesn't exist yet in your template override directory copy the includes/templates/template_default/templates/tpl_account_history_default.php file to: includes/templates/YOUR_TEMPLATE/templates/tpl_account_history_default.php

    Now we didn't talk about ZC versions, but I'm referencing a ZC 1.5.5 related version below:

    In tpl_account_history_default.php find:
    Code:
        foreach ($accountHistory as $history) {
    ?>
    <fieldset>
    <legend><?php echo TEXT_ORDER_NUMBER . $history['orders_id']; ?></legend>
    <div class="notice forward"><?php echo TEXT_ORDER_STATUS . $history['orders_status_name']; ?></div>
    <br class="clearBoth" />
        <div class="content back"><?php echo '<strong>' . TEXT_ORDER_DATE . '</strong> ' . zen_date_long($history['date_purchased']) . '<br /><strong>' . $history['order_type'] . '</strong> ' . zen_output_string_protected($history['order_name']); ?></div>
        <div class="content"><?php echo '<strong>' . TEXT_ORDER_PRODUCTS . '</strong> ' . $history['product_count'] . '<br /><strong>' . TEXT_ORDER_COST . '</strong> ' . strip_tags($history['order_total']); ?></div>
        <div class="content forward"><?php echo '<a href="' . zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, (isset($_GET['page']) ? 'page=' . $_GET['page'] . '&' : '') . 'order_id=' . $history['orders_id'], 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_VIEW_SMALL, BUTTON_VIEW_SMALL_ALT) . '</a>'; ?></div>
    <br class="clearBoth" />
    </fieldset>
    <?php
        }
    This is where the generic details of each order are displayed as well as a link to dig into the order itself. Notice how within that section there is $history['orders_id'] made available. That can be used to then target the remaining portions of the code.

    So, then if you take a look at the tpl_account_history_info_default.php file you should see a section related to downloads:
    Code:
    /**
     * Used to display any downloads associated with the cutomers account
     */
      if (DOWNLOAD_ENABLED == 'true') require($template->get_template_dir('tpl_modules_downloads.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_downloads.php');
    Well, looking further into the associated template/module code, it expects to know/obtain the order_id primarily dependent on the current page, ie. if the current page is not the account_history_info page then it will pull the most recent order associated with the logged in customer otherwise if on the account_history_info page then it will pull the order information related to the setting of $_GET['order_id'], well use this code to pull the desired order_id information, either includes/modules/downloads.php (copied to it's template override) needs to be modified or the value of $_GET['main_page'] needs to be modified before accessing that code which is the solution I suggest for this to minimize editing, again a "quick fix" and besides will be modifying the value of $_GET['order_id'] anyways, so two wrongs, right? :)

    So in the above loop if you were to modify it as such:

    Code:
        foreach ($accountHistory as $history) {
    ?>
    <fieldset>
    <legend><?php echo TEXT_ORDER_NUMBER . $history['orders_id']; ?></legend>
    <div class="notice forward"><?php echo TEXT_ORDER_STATUS . $history['orders_status_name']; ?></div>
    <br class="clearBoth" />
         <div class="content back"><?php echo '<strong>' .  TEXT_ORDER_DATE . '</strong> ' .  zen_date_long($history['date_purchased']) . '<br /><strong>'  . $history['order_type'] . '</strong> ' .  zen_output_string_protected($history['order_name']); ?></div>
         <div class="content"><?php echo '<strong>' .  TEXT_ORDER_PRODUCTS . '</strong> ' . $history['product_count'] .  '<br /><strong>' . TEXT_ORDER_COST . '</strong> ' .  strip_tags($history['order_total']); ?></div>
        <div  class="content forward"><?php echo '<a href="' .  zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, (isset($_GET['page']) ?  'page=' . $_GET['page'] . '&' : '') . 'order_id=' .  $history['orders_id'], 'SSL') . '">' .  zen_image_button(BUTTON_IMAGE_VIEW_SMALL, BUTTON_VIEW_SMALL_ALT) .  '</a>'; ?></div>
    <br class="clearBoth" />
    </fieldset>
    <?php
      // Copy the current setting for $_GET['main_page'] and change it.
      $prevPage = $_GET['main_page'];
      $prevOrderid = (isset($_GET['order_id']) ? $_GET['order_id'] : NULL);
      $_GET['main_page'] = FILENAME_ACCOUNT_HISTORY_INFO;
      $_GET['order_id'] = $history['orders_id'];
    /**
     * Used to display any downloads associated with the cutomers account
     */
       if (DOWNLOAD_ENABLED == 'true')  require($template->get_template_dir('tpl_modules_downloads.php',DIR_WS_TEMPLATE,  $current_page_base,'templates'). '/tpl_modules_downloads.php');
    
      // restore the current setting of $_GET['main_page']
      $_GET['main_page'] = $prevPage;
      // If the order_id parameter not NULL (existed) then restore it back to what it was.  If it did not exist, then remove it from the array.
      if ($prevOrderid != NULL) {
        $_GET['order_id'] = $prevOrderid;
      } else {
        unset($_GET['order_id']);
      }
      unset($prevPage);
    
        }
    This untested code should provide the downloads that are associated with each order at the point below each order's information. Further "tweaking" is likely needed to get the intended/desired affect. Again it may be best to create a new "page" that the customer can choose to see and the code associated with that page can be modified as necessary to provide the real results for which you are looking. Found this ZC wiki link on creating new pages and have previously successfully followed its guidance however detailed or not it is.

    Again, the above is untested and generated from considering the request, what is available at that point in the code and how things are conceptually expected to work. I have not had an opportunity to test it myself and suggest testing and modifying on a demo site before implementing on your live site.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  5. #5
    Join Date
    Jan 2010
    Location
    Richmond, Virginia, United States
    Posts
    105
    Plugin Contributions
    0

    Default Re: View downloads from all orders on one page

    WOW. Okay, I'll try it out and let you know what happens! :)

  6. #6
    Join Date
    Jan 2010
    Location
    Richmond, Virginia, United States
    Posts
    105
    Plugin Contributions
    0

    Default Re: View downloads from all orders on one page

    Yes, it works, thank you!

    If I wanted to sort the list by product name, how would I do that?

    And what do I owe you? :)

  7. #7
    Join Date
    Jul 2012
    Posts
    14,386
    Plugin Contributions
    17

    Default Re: View downloads from all orders on one page

    Quote Originally Posted by jmsnyder23 View Post
    Yes, it works, thank you!

    If I wanted to sort the list by product name, how would I do that?

    And what do I owe you? :)
    Well, that's perhaps an animal of a different color as the current "sequence" is primarily determined by order number and then placement of product within the order itself when ordering. The question was something bothering me as it seemed as if the pieces were there to at least get a partial solution, just had to find them and pull them together a little.

    To present all of the downloads in some sort of sorted order would require querying for the data provided by the downloads module based on all orders of the individual sorted by the products name. The above proposed method provides all the downloads of a purchase for each purchase made which is provided in "parts" rather than whole as being sought.

    What I could see as a possibility is to duplicate some of the files to a different/override file and make the necessary modifications with the thought that the download "list" be presented say below the list of orders currently generated by ZC and then include that template file to provide the desired result.

    I can see a way that the downloads module could be modified to provide the same functionality that it has, incorporate some of the cleaning "principles" otherwise suggested for newer software and provide a level of flexibility (though still mentally toying with implementation of that aspect). The thought is to use information already made available by the header file for customer_history to feed the downloads query such that the query would use the results of the orders query as part of the "input" to the downloads query and thus allow the sorting of the display.

    So all of that said, here's code (untested, but "looks right"):
    If you get a blank screen or partial blank screen, please see the FAQ on that topic.
    The changes provided below are sequenced to allow "insertion" one at a time so as not to disable the store in the event of extra/missing information. Significantly new results won't be seen until the last file is in place; however, will see that the downloads "area" will move or not be present because of the way the "calculations" will be performed until the last file is implemented. There are certainly other ways to accomplish this, but this looked to me to be the most non-intrusive way of being able to work within the existing file though it requires the existing file to be modified. (ie. if the observer is removed below, other than an extra template file display of the downloads from the last order, the file(s) should operate as "normal".)

    Modify your template file that was "created" yesterday:
    includes/templates/YOUR_TEMPLATE/templates/tpl_account_history_default.php

    to contain the original content of includes/templates/template_default/templates/tpl_account_history_default.php (Restoring to status of before yesterday)
    then change this section:
    Code:
     <div class="navSplitPagesLinks forward"><?php echo TEXT_RESULT_PAGE . $history_split->display_links($max_display_page_links, zen_get_all_get_params(array('page', 'info', 'x', 'y', 'main_page')), $paginateAsUL); ?></div>
    <div class="navSplitPagesResult"><?php echo $history_split->display_count(TEXT_DISPLAY_NUMBER_OF_ORDERS); ?></div>
    
    <?php
      } else {
    to:
    Code:
    <div class="navSplitPagesLinks forward"><?php echo TEXT_RESULT_PAGE . $history_split->display_links($max_display_page_links, zen_get_all_get_params(array('page', 'info', 'x', 'y', 'main_page')), $paginateAsUL); ?></div>
    <div class="navSplitPagesResult"><?php echo $history_split->display_count(TEXT_DISPLAY_NUMBER_OF_ORDERS); ?></div>
    <?php
    /**
     * Used to display any downloads associated with the cutomers account
     */
      if (DOWNLOAD_ENABLED == 'true') require($template->get_template_dir('tpl_modules_downloads.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_downloads.php');
    ?>
    
    <?php
      } else {
    This will place the download results below the pagination area if there is an order history with which to contend which is another thing/aspect to consider related to this setup.

    create a new file called:
    includes/modules/YOUR_TEMPLATE/downloads.php

    This is the existing downloads file rewritten slightly to support observers and at least minor modification of the sql statement. Potentially more "edits" could be made to expand this functionality.

    Containing:
    Code:
    <?php
    /**
     * downloads module - prepares information for use in downloadable files delivery
     *  MODIFIED
     * @version $Id: downloads.php 2016-11-29 21:04:04Z mc12345678 $
     */
    if (!defined('IS_ADMIN_FLAG')) {
      die('Illegal Access');
    }
    // Now get all downloadable products in that order
    $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 = :customer_id:
                          and (o.orders_status >= '" . DOWNLOADS_CONTROLLER_ORDERS_STATUS . "'
                          and o.orders_status <= '" . DOWNLOADS_CONTROLLER_ORDERS_STATUS_END . "')
                          and o.orders_id = :last_order:
                          and o.orders_id = op.orders_id
                          and op.orders_products_id = opd.orders_products_id
                          and opd.orders_products_filename != ''";
    
    $moduleDLobserved = false;
    
    $zco_notifier->notify('NOTIFY_DOWNLOADS_MODULE_SQL_END', array(), $moduleDLobserved, $downloads_query);
    
    if ($moduleDLobserved) {
      // Don't do anything to the $last_order value, as it or the sql has been prepared/modified by the observer.
    } elseif (!($_GET['main_page']==FILENAME_ACCOUNT_HISTORY_INFO)) {
      // Get last order id for checkout_success
      $orders_lookup_query = "select orders_id
                         from " . TABLE_ORDERS . "
                         where customers_id = :customer_id:
                         order by orders_id desc limit 1";
    
      $orders_lookup_query = $db->bindVars($orders_lookup_query, ':customer_id:', $_SESSION['customer_id'], 'integer');
    
      $orders_lookup = $db->Execute($orders_lookup_query);
      $last_order = $orders_lookup->fields['orders_id'];
    } else {
      $last_order = $_GET['order_id'];
    }
    unset($moduleDLobserved);
    
    $downloads_query = $db->bindVars($downloads_query, ':customer_id:', $_SESSION['customer_id'], 'integer');
    $downloads_query = $db->bindVars($downloads_query, ':last_order:', $last_order, 'integer');
    
    $downloads = $db->Execute($downloads_query);
    
    // If there is a download in the order and they cannot get it, tell customer about download rules
    $downloads_check_query_query = "select o.orders_id, opd.orders_products_download_id
                              from " .
    TABLE_ORDERS . " o, " .
    TABLE_ORDERS_PRODUCTS_DOWNLOAD . " opd
                              where
                              o.orders_id = opd.orders_id
                              and o.orders_id = :last_order:
                              and opd.orders_products_filename != ''
                              ";
    
    $zco_notifier->notify('NOTIFY_DOWNLOADS_MODULE_SQL_CHECK_END', array(), $downloads_check_query_query);
    
    $downloads_check_query_query = $db->bindVars($downloads_check_query_query, ':last_order:', $last_order, 'integer');
    
    $downloads_check_query = $db->Execute($downloads_check_query_query);
    create a new file called:
    includes/classes/observers/auto.account_history_downloads.php
    This is the file that will insert the extra "work" to pull all of the order records in instead of just a single order record. This file is an observer file and is named following the convention of ZC 1.5.3; however, the contents of the file support older versions of ZC (ie. the update function is written to support production versions before ZC 1.5.3)

    Containing:
    Code:
    <?php
    /**
     * Account History downloads observer - prepares information for use in downloadable files delivery
     * 
     * @version $Id: 2016-11-29 21:04:04Z mc12345678 $
     */
    
    class zcObserverAccountHistoryDownloads extends base {
      $_dlsubQuery;
      function __construct() {
        $observeThis = array();
        $observeThis[] = 'NOTIFY_DOWNLOADS_MODULE_SQL_END';
        $observeThis[] = 'NOTIFY_DOWNLOADS_MODULE_SQL_CHECK_END';
        $this->attach($this, $observeThis);
      }
    
      function updateNotifyDownloadsModuleSqlEnd(&$callingClass, $notifier, $dataArray, &$moduleDLobserved, &$downloads_query) {
        if ($_GET['main_page'] == FILENAME_ACCOUNT_HISTORY) {
          global $db;
          // obtain all of the orders_id for the customer with no particular sequence.
          $this->_dlSubQuery = "SELECT o.orders_id
                            FROM   " . TABLE_ORDERS . " o
                            WHERE      o.customers_id = :customer_id:";
          $downloads_query = $db->bindVars($downloads_query, ':last_order:', '(:subquery:)', 'noquotestring');
          $downloads_query = $db->bindVars($downloads_query, ':subquery:', $this->_dlSubQuery, 'noquotestring');
          // sort total query results by products_name.
          $downloads_query = $downloads_query . " ORDER BY op.products_name";
    
          $moduleDLobserved = true;
        }
      }
    
      function updateNotifyDownloadsModuleSqlCheckEnd(&$callingClass, $notifier, $dataArray, &$downloads_query) {
        if ($_GET['main_page'] == FILENAME_ACCOUNT_HISTORY) {
          global $db;
          $downloads_query = $db->bindVars($downloads_query, ':last_order:', '(:subquery:)', 'noquotestring');
          $downloads_query = $db->bindVars($downloads_query, ':subquery:', $this->_dlSubQuery, 'noquotestring');
          $downloads_query = $db->bindVars($downloads_query, ':customer_id:', $_SESSION['customer_id'], 'integer');
    
          // sort total query results by products_name.
          $downloads_query = $downloads_query . " ORDER BY op.products_name";
        }
      }
    
      function update(&$callingClass, $notifier, $param1_array, &$param2 = NULL, &$param3 = NULL, &$param4 = NULL, &$param5 = NULL, &$param6 = NULL, &$param7 = NULL, &$param8 = NULL, &$param9 = NULL) {
        if ($notifier == 'NOTIFY_DOWNLOADS_MODULE_SQL_END') {
           global $moduleDLobserved;
           global $downloads_query;
           $this->updateNotifyDownloadsModuleSqlEnd($callingClass, $notifier, $param1_array, $moduleDLobserved, $downloads_query);
        }
        if ($notifier == 'NOTIFY_DOWNLOADS_MODULE_SQL_CHECK_END') {
          global $downloads_check_query_query;
           $this->updateNotifyDownloadsModuleSqlCheckEnd($callingClass, $notifier, $param1_array, $downloads_check_query_query);
        }
      } 
    }
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

 

 

Similar Threads

  1. Downloads remaining goes to 3 from 5 after one click
    By verzea in forum Setting Up Categories, Products, Attributes
    Replies: 10
    Last Post: 16 May 2015, 05:16 PM
  2. Replies: 2
    Last Post: 13 May 2015, 12:03 AM
  3. v151 Orders being removed from view automatically when a refund is issued.
    By PetleyJ in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 29 Jun 2013, 09:13 PM
  4. Reactivating Downloads on ALL Orders
    By jmsnyder23 in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 5 Apr 2011, 01:44 AM
  5. View all customers from a specific country
    By shirster in forum Managing Customers and Orders
    Replies: 2
    Last Post: 18 Aug 2009, 01:22 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR