Zen Cart Logo
Forums / Customization from the Admin / Add a new Admin order search criteria

Add a new Admin order search criteria

Locked

Views: 2,577

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
11 Mar 2009, 5:30 PM
#1
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
516
Plugin Contributions:
2

Add a new Admin order search criteria

I'm trying to add a new search box to the order Admin screen that can search for orders by a order referrence number that my cart generates when an order is placed.

My Zen Cart generates a random 8 digit order reference number and writes it to table in the database, which is structured like:

TABLE NAME: order_reference_numbers
COLUMES:
refference_order_number (a randaom 8 digit number)
order_id (original order id)

Now I'm trying to figure out the code that needs to be modified in the **orders.php **found in the /admin directory, before I go crazy has anyone done this before and have an example of some code that I can reference?

I understand the Logic of what it has to do, I'm just not sure how to code it! It has to seach this custom table for the reference number then see what the original order id is then simply display that order like the current search by order id works.

Thanks!

11 Mar 2009, 5:56 PM
#2
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Add a new Admin order search criteria

Try this:
edit admin/orders.php by replacing this code (lines 35-45 in original v1.3.8 file)```
if (isset($_GET['oID'])) {
$oID = zen_db_prepare_input($_GET['oID']);

$orders = $db->Execute("select orders_id from " . TABLE_ORDERS . "
                        where orders_id = '" . (int)$oID . "'");
$order_exists = true;
if ($orders->RecordCount() <= 0) {
  $order_exists = false;
  if ($action != '') $messageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
}

}
with this
if (isset($_GET['oID'])) {
$oID = zen_db_prepare_input($_GET['oID']);

$orders = $db->Execute("select orders_id from " . TABLE_ORDERS . "
                        where orders_id = '" . (int)$oID . "'");
$order_exists = true;
if ($orders->RecordCount() <= 0) {
  $reference = $db->Execute("select order_id from " . TABLE_ORDERS_REFERENCE_NUMBER . "
                             where reference_order_number  = '" . (int)$oID . "' LIMIT 1");

  if ($reference->RecordCount() <= 0) {
    $oID = $reference->fields['reference_order_number'];
  } else {
        $order_exists = false;
        if ($action != '') $messageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
  }
}

}

this code assumes you have defined your new database table name with the constant TABLE_ORDERS_REFERENCE_NUMBER - replace with your constant as needed, and make sure the field names match what you have in your orders reference table. 

Now you should be able to enter either the zen cart order id or your own order reference number into the Order ID search box.
11 Mar 2009, 7:04 PM
#3
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
516
Plugin Contributions:
2

Re: Add a new Admin order search criteria

Thank you for your help, I added the code and it did not work?

couple things to mention...

refference_order_number was actually ref_num
order_id was actually ** orders_id**

I changed both in the code, it did not work...seems to not even try to search...when you hit enter nothing happens and what ever was entered in the search field is still there after hitting enter.

I also did not have that table defined, so I checked on how to do that and if you can tell me if I did that right:

I define it by adding a file to directory: /admin/includes/extra_datafiles

FILE NAME: orders_reference_number.php

INSIDE THAT FILE:

<?php /** * Fulfill Orders XML */ define('TABLE_ORDERS_REFERENCE_NUMBER', DB_PREFIX . 'my_table_name'); ?>

Below is the modified code that I tested:

if (isset($_GET['oID'])) {
$oID = zen_db_prepare_input($_GET['oID']);

$orders = $db->Execute("select orders_id from " . TABLE_ORDERS . "
                        where orders_id = '" . (int)$oID . "'");
$order_exists = true;
if ($orders->RecordCount() <= 0) {
  $reference = $db->Execute("select orders_id from " . TABLE_ORDERS_REFERENCE_NUMBER . "
                             where ref_num  = '" . (int)$oID . "' LIMIT 1");

  if ($reference->RecordCount() <= 0) {
    $oID = $reference->fields['ref_num'];
  } else {
        $order_exists = false;
        if ($action != '') $messageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
  }
}

}

11 Mar 2009, 7:09 PM
#4
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Add a new Admin order search criteria

Sorry, it was an error in my code.
Try this:

   if (isset($_GET['oID'])) {
    $oID = zen_db_prepare_input($_GET['oID']);

    $orders = $db->Execute("select orders_id from " . TABLE_ORDERS . "
                            where orders_id = '" . (int)$oID . "'");
    $order_exists = true;
    if ($orders->RecordCount() <= 0) {
	  $reference = $db->Execute("select orders_id from " . TABLE_ORDERS_REFERENCE_NUMBER . "
                                 where ref_num = '" . (int)$oID . "' LIMIT 1");
	
	  if ($reference->RecordCount() <= 0) {
	    $oID = $reference->fields['orders_id '];
	  } else {
            $order_exists = false;
            if ($action != '') $messageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
	  }
    }
  }
11 Mar 2009, 7:14 PM
#5
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
516
Plugin Contributions:
2

Re: Add a new Admin order search criteria

Nope...does not do anything when you hit enter?

11 Mar 2009, 7:17 PM
#6
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Add a new Admin order search criteria

give me a few minutes - I'll set up a similar table on my test site and see what happens

11 Mar 2009, 7:34 PM
#7
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Add a new Admin order search criteria

ok, after a little test I found my error.
This should work:

  if (isset($_GET['oID'])) {
    $oID = zen_db_prepare_input($_GET['oID']);

    $orders = $db->Execute("select orders_id from " . TABLE_ORDERS . "
                            where orders_id = '" . (int)$oID . "'");
    $order_exists = true;
    if ($orders->RecordCount() <= 0) {
	  $reference = $db->Execute("select orders_id from " . TABLE_ORDERS_REFERENCE_NUMBER . "
                                 where ref_num  = '" . (int)$oID . "' LIMIT 1");
	
	  if ($reference->RecordCount() > 0) {
	    $oID = $reference->fields['orders_id'];
	  } else {
        $order_exists = false;
        if ($action != '') $messageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
	  }
    }
  }
11 Mar 2009, 7:41 PM
#8
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
516
Plugin Contributions:
2

Re: Add a new Admin order search criteria

nice work thanks...worked perfect! I appreciate the help!!