
Originally Posted by
jmsnyder23
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);
}
}
}
Bookmarks