| 1 |
<?php |
<?php |
| 2 |
// $Id: uc_reorder.module,v 1.6 2009/04/09 03:14:30 tr Exp $ |
// $Id: uc_reorder.module,v 1.7 2009/04/09 03:45:22 tr Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 14 |
* but still adds them to the cart. I must be missing something here... |
* but still adds them to the cart. I must be missing something here... |
| 15 |
* |
* |
| 16 |
* @author Tim Rohaly. |
* @author Tim Rohaly. |
| 17 |
* @version $Id: uc_reorder.module,v 1.6 2009/04/09 03:14:30 tr Exp $ |
* @version $Id: uc_reorder.module,v 1.7 2009/04/09 03:45:22 tr Exp $ |
| 18 |
*/ |
*/ |
| 19 |
|
|
| 20 |
|
|
| 32 |
|
|
| 33 |
if ($user->uid) { // no order info page for anonymous users |
if ($user->uid) { // no order info page for anonymous users |
| 34 |
$items['user/%/reorder/%'] = array( |
$items['user/%/reorder/%'] = array( |
| 35 |
'title' => 'Re-Order Button', |
'title' => 'Re-Order Button', |
| 36 |
'page callback' => '_uc_reorder_reorder', |
'page callback' => '_uc_reorder_reorder', |
| 37 |
'page arguments' => array(1, 3), |
'page arguments' => array(1, 3), |
| 38 |
'access callback' => TRUE, // NEED TO SET THIS PROPERLY! |
'access callback' => TRUE, // NEED TO SET THIS PROPERLY! |
| 39 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 40 |
); |
); |
| 41 |
// element 'access' is deliberately not set - that makes this menu |
// element 'access' is deliberately not set - that makes this menu |
| 42 |
// inherit permissions, so anyone who can view user/# |
// inherit permissions, so anyone who can view user/# |
| 53 |
function uc_reorder_menu_alter(&$items) { |
function uc_reorder_menu_alter(&$items) { |
| 54 |
global $user; |
global $user; |
| 55 |
|
|
| 56 |
// Modify user/#/orders menu to callback to uc_reorder_order_history() |
// Modify user/#/uc-orders menu to callback to uc_reorder_order_history() |
| 57 |
// instead of uc_order_history(). Allows us to modify core behavior |
// instead of uc_order_history(). Allows us to modify core behavior |
| 58 |
// without hacking uc_order.module. |
// without hacking uc_order.module. |
| 59 |
if ($user->uid) { // no order info page for anonymous users |
if ($user->uid) { // no order info page for anonymous users |
| 60 |
$items['user/%user/orders']['page callback'] = 'uc_reorder_order_history'; |
$items['user/%user/uc-orders']['page callback'] = 'uc_reorder_order_history'; |
| 61 |
} |
} |
| 62 |
} |
} |
| 63 |
|
|
| 79 |
// Check to see if the user has permission to see this order |
// Check to see if the user has permission to see this order |
| 80 |
$order_uid = db_result(db_query("SELECT uid FROM {uc_orders} WHERE order_id = %d", $order_id)); |
$order_uid = db_result(db_query("SELECT uid FROM {uc_orders} WHERE order_id = %d", $order_id)); |
| 81 |
if (!user_access('view all orders') && $order_uid != $uid) { |
if (!user_access('view all orders') && $order_uid != $uid) { |
| 82 |
drupal_goto('user/'. $uid .'/orders'); |
drupal_goto('user/'. $uid .'/uc-orders'); |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
// Loop over all products in the specified Order |
// Loop over all products in the specified Order |
| 138 |
); |
); |
| 139 |
|
|
| 140 |
$result = pager_query("SELECT o.order_id, o.created, os.title, SUM(op.qty) AS products, o.order_total AS total FROM {uc_orders} AS o LEFT JOIN {uc_order_statuses} AS os ON o.order_status = os.order_status_id LEFT JOIN {uc_order_products} AS op ON o.order_id = op.order_id WHERE o.uid = %d AND o.order_status IN ". uc_order_status_list('general', TRUE) ." GROUP BY o.order_id, o.created, os.title, o.order_total". tablesort_sql($header), 20, 0, "SELECT COUNT(*) FROM {uc_orders} WHERE uid = %d AND order_status NOT IN ". uc_order_status_list('specific', TRUE), $user->uid); |
$result = pager_query("SELECT o.order_id, o.created, os.title, SUM(op.qty) AS products, o.order_total AS total FROM {uc_orders} AS o LEFT JOIN {uc_order_statuses} AS os ON o.order_status = os.order_status_id LEFT JOIN {uc_order_products} AS op ON o.order_id = op.order_id WHERE o.uid = %d AND o.order_status IN ". uc_order_status_list('general', TRUE) ." GROUP BY o.order_id, o.created, os.title, o.order_total". tablesort_sql($header), 20, 0, "SELECT COUNT(*) FROM {uc_orders} WHERE uid = %d AND order_status NOT IN ". uc_order_status_list('specific', TRUE), $user->uid); |
| 141 |
|
$context = array( |
| 142 |
|
'revision' => 'themed-original', |
| 143 |
|
'location' => 'order-history', |
| 144 |
|
); |
| 145 |
// Build a table based on the customer's orders. |
// Build a table based on the customer's orders. |
| 146 |
while ($order = db_fetch_object($result)) { |
while ($order = db_fetch_object($result)) { |
| 147 |
|
$context['subject'] = array('order' => $order); |
| 148 |
$link = l($order->order_id, 'user/'. $user->uid .'/order/'. $order->order_id); |
$link = l($order->order_id, 'user/'. $user->uid .'/order/'. $order->order_id); |
| 149 |
if (user_access('view all orders')) { |
if (user_access('view all orders')) { |
| 150 |
$link .= '<span class="order-admin-icons">'. uc_order_actions($order, TRUE) .'</span>'; |
$link .= '<span class="order-admin-icons">'. uc_order_actions($order, TRUE) .'</span>'; |
| 154 |
array('data' => $link, 'nowrap' => 'nowrap'), |
array('data' => $link, 'nowrap' => 'nowrap'), |
| 155 |
array('data' => $order->title), |
array('data' => $order->title), |
| 156 |
array('data' => (!is_null($order->products) ? $order->products : 0), 'align' => 'center'), |
array('data' => (!is_null($order->products) ? $order->products : 0), 'align' => 'center'), |
| 157 |
array('data' => uc_currency_format($order->total, TRUE), 'align' => 'right'), |
array('data' => uc_price($order->total, $context), 'align' => 'right'), |
| 158 |
array('data' => drupal_get_form('uc_reorder_reorder_form', 'user/'. $user->uid .'/reorder/'. $order->order_id)), |
array('data' => drupal_get_form('uc_reorder_reorder_form', 'user/'. $user->uid .'/reorder/'. $order->order_id)), |
| 159 |
); |
); |
| 160 |
} |
} |