Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Orders through money order are deleted automatically if not completed within 30 days?


fut

Recommended Posts

I have an Order Status I created called "Money Order [Pending]" Any order that a customer chooses to pay by Money Order is put into that list. Most people don't send the money order.

 

Is there anyway for any order remaining in that status for more then 30 days to be deleted?

 

Thanks.

Link to comment
Share on other sites

backup files and your database first, then open your catalog\admin\includes\functions\general.php just before the last

 

?>

 

add:

  function tep_remove_old_orders() {
// Remove orders that are older than a month in pending state
tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_status='1' and (curdate()+0) > ((date_format(date_purchased, '%Y%m%d')+0)+100)");
while ($order = tep_db_fetch_array($order_query)) {
  tep_db_query("delete from " . TABLE_ORDERS . " where orders_id = '" . (int)$order['orders_id'] . "'");
  tep_db_query("delete from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order['orders_id'] . "'");
  tep_db_query("delete from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order['orders_id'] . "'");
  tep_db_query("delete from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . (int)$order['orders_id'] . "'");
  tep_db_query("delete from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order['orders_id'] . "'");
}
 }

 

open your catalog\admin\orders.php

find:

  if (tep_not_null($action)) {
switch ($action) {

just below add

	  case 'remove_old':
	tep_remove_old_orders();
	tep_redirect(tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action'))));
	break;

 

same file locate:

			  <tr>
			<td colspan="5"><table border="0" width="100%" cellspacing="0" cellpadding="2">
			  <tr>
				<td class="smallText" valign="top"><?php echo $orders_split->display_count($orders_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_ORDERS); ?></td>
				<td class="smallText" align="right"><?php echo $orders_split->display_links($orders_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'], tep_get_all_get_params(array('page', 'oID', 'action'))); ?></td>
			  </tr>
			</table></td>
		  </tr>

 

Right below add:

			  <tr>
			<td><?php echo '<a href="' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=remove_old')  . '">' . tep_image_button('button_delete.gif', 'Remove Old Orders') . '</a>'; ?></td>
		  </tr>

 

Once you hit delete orders in pending status older than a month should be deleted.

 

You could setup a cron job to run the script if you want it fully automated.

Link to comment
Share on other sites

  • 1 year later...

An old thread, but ... I'm trying to implement it and it is simple obviously, however, i keep getting this error when pressing the delete button:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Users\osc-new\admin\includes\functions\database.php on line 99

Warning: Cannot modify header information - headers already sent by (output started at C:\Users\osc-new\admin\includes\functions\database.php:99) in C:\Users\osc-new\admin\includes\functions\general.php on line 22

 

 

Any clues?

Link to comment
Share on other sites

Before anyone asks, it did try several things:

 

Printed out the query and ran it in phpmyadmin, 197 results

select orders_id from orders where orders_status='1' and (curdate()+0) > ((date_format(date_purchased, '%Y%m%d')+0)+400)

 

// commented out the following, took care of the second warning, not the first

// tep_redirect(tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action'))));

Link to comment
Share on other sites

ok done. The posted function misses a variable setting:

 

function tep_remove_old_orders() {
// Remove orders that are older than a month in pending state
$order_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_status='1' and (curdate()+0) > ((date_format(date_purchased, '%Y%m%d')+0)+400)");
while ($order = tep_db_fetch_array($order_query)) {
  tep_db_query("delete from " . TABLE_ORDERS . " where orders_id = '" . (int)$order['orders_id'] . "'");
  tep_db_query("delete from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order['orders_id'] . "'");
  tep_db_query("delete from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order['orders_id'] . "'");
  tep_db_query("delete from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . (int)$order['orders_id'] . "'");
  tep_db_query("delete from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order['orders_id'] . "'");
}
 }

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...