I have a quick little modification/add-on almost ready. It creates a simple report that is in a table format ready for printing. It starts with a dropdown for order status. Select the status you need and it populates a long table with the order number, delivery name and address, and then the products in the order. It can be printed out to create a "pull sheet" for those of us who prefer to work from a sheet in the warehouse that's not the packing slip. (My warehouse is wet and dirty. I don't want my packing slips out there). It will print the necessary information for dozens of orders on just a couple of pages; saving space and paper. Might also be useful for drop shippers who use order status in unusual ways like I do.
Anyway, it's almost ready. I have just 1 problem in the code. Everything formats beautifully but the products in each order. Only the products for the very first order in the database appear and they appear for every order.
I'm sure I'm just asking for the products the wrong way and could use some help to tweak the code. I'm going to include it because it's a fairly short file. The part asking for the products is:
PHP Code:
$order = new order($orders);
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
echo $order->products[$i]['qty'] . ' ' . $order->products[$i]['name'];
and the whole file is here:
PHP Code:
<?php
require('includes/application_top.php');
include(DIR_WS_CLASSES . 'order.php');
// prepare order-status pulldown list
$orders_statuses = array();
$orders_status_array = array();
$orders_status = $db->Execute("select orders_status_id, orders_status_name
from " . TABLE_ORDERS_STATUS . "
where language_id = '" . (int)$_SESSION['languages_id'] . "'");
while (!$orders_status->EOF) {
$orders_statuses[] = array('id' => $orders_status->fields['orders_status_id'],
'text' => $orders_status->fields['orders_status_name'] . ' [' . $orders_status->fields['orders_status_id'] . ']');
$orders_status_array[$orders_status->fields['orders_status_id']] = $orders_status->fields['orders_status_name'];
$orders_status->MoveNext();
}
$action = (isset($_GET['action']) ? $_GET['action'] : '');
$order_exists = false;
if (isset($_GET['oID']) && trim($_GET['oID']) == '') unset($_GET['oID']);
if ($action == 'edit' && !isset($_GET['oID'])) $action = '';
if (isset($_GET['oID'])) {
$oID = zen_db_prepare_input(trim($_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');
}
}
$order_status = $select_order_status;
$display_order_status = $order_status;
if ($order_status == "")
{
$order_status = 1;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>OrderList</title>
</head>
<body>
<h1>Orderlist</h1><br>
<script language="javascript">
<!--
document.write(Date());
-->
</script>
<h2>
<tr><?php echo zen_draw_form('status', orderlist, '', 'get', '', true); ?>
<td class="smallText" align="right">
<?php
echo "Choose Status:" . ' ' . zen_draw_pull_down_menu('status', array_merge(array(array('id' => '', 'text' => "All")), $orders_statuses), $_GET['status'], 'onChange="this.form.submit();"');
echo zen_hide_session_id();
?>
</td>
</form></tr>
</h2>
<TABLE width="100%" align=center cellSpacing=1 cellPadding=1 border=1>
<?php
if ($_GET['status'] != '') {
$status = zen_db_prepare_input($_GET['status']);
$orders_query_raw = "select o.orders_id, o.customers_id, o.delivery_name, o.delivery_street_address, o.delivery_city, o.delivery_state, o.delivery_postcode, o.customers_email_address, o.date_purchased,o.last_modified, o.currency_value, s.orders_status_name, ot.text as order_total" .
$new_fields . "
from (" . TABLE_ORDERS . " o, " .
TABLE_ORDERS_STATUS . " s " .
$new_table . ")
left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id) " . "
where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$_SESSION['languages_id'] . "' and s.orders_status_id = '" . (int)$status . "' and ot.class = 'ot_total' " .
$search . " order by o.orders_id ASC";
}
$orders = $db->Execute($orders_query_raw);
while (!$orders->EOF) {
if ((!isset($_GET['oID']) || (isset($_GET['oID']) && ($_GET['oID'] == $orders->fields['orders_id']))) && !isset($oInfo)) {
$oInfo = new objectInfo($orders->fields);
}
if (isset($oInfo) && is_object($oInfo) && ($orders->fields['orders_id'] == $oInfo->orders_id)) {
echo ' <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . zen_href_link(FILENAME_ORDER_EDIT, zen_get_all_get_params(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=edit', 'NONSSL') . '\'">' . "\n";
} else {
echo ' <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . zen_href_link(FILENAME_ORDER_EDIT, zen_get_all_get_params(array('oID')) . 'oID=' . $orders->fields['orders_id'], 'NONSSL') . '\'">' . "\n";
}
?>
<td class="dataTableContent" align="center" width="60"><?php echo $orders->fields['orders_id']; ?></td>
<td class="dataTableContent" align="center" width="70"> S H P D </td>
<td class="dataTableContent"><?php echo $orders->fields['delivery_name'] . '<br />' . $orders->fields['delivery_street_address'] . '<br />' . $orders->fields['delivery_state'] . $orders->fields['delivery_postcode'] . '<br />' . $orders->fields['customers_email_address'] ; ?></td>
<td class="dataTableContent" align="left"> <?php
$order = new order($orders);
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
echo $order->products[$i]['qty'] . ' ' . $order->products[$i]['name'];
}
?></td>
</tr>
<?php
$orders->MoveNext();
}
?>
</table>
</body>
</html>
I think this will be useful for plenty of zenners and hope someone can clear up that one bit for me. Thanks!
Bookmarks