We kept a provision for different order statuses when we designed the orders
table. The status field is an enumerated field, and can contain one of the
three values: N for New order, P for orders in Process, and C for Completed
orders. Let's add a function to our Order class to update this field. The
following code shows the function:
public function UpdateStatus($status)
{
$query = "UPDATE ".$this->table." SET status = '$status'
WHERE id = '".$this->_id."'";
if ($GLOBALS["db"]->UpdateQuery($query))
{
$this->status = $status;
return true;
}
return false;
}
2. Next, let's list new orders. For this, we query the orders table for all orders
with status "N". With each item in the list, we will add a checkbox so that
we can mark them as dispatched. Let us make a new file processOrders.
inc.php for this. We also need to add the action "processOrders" to the
$validActions array in index.php. The following code shows the code to
generate this list:
// File to process orders and mark them as dispatched
$prodObj = new Product();
$products = $prodObj->GetAll("categoryId = 1", "priority asc");
$varObj = new Variation();
$varObj = $varObj->GetAll("", "type asc");
$ordObj = new Order($prodObj, $varObj);
// Load all new orders
$pendingOrders = $ordObj->GetAll("status = 'N'", "orderDate asc");
echo '
Process New Orders
';
if (count($pendingOrders) > 0)
{
echo '