order as $order) { $customer_id = (string) $order->customer_id; $customer_order_array[$customer_id][] = $order; } // Create array mapping order_id to an array of cancellations, payments, and pickups $order_status_array = array(); foreach($batch_xml->order_cancel as $order_cancel) { $order_id = (string) $order_cancel->order_id; $order_status_array[$order_id]['cancellations'][] = $order_cancel; } foreach($batch_xml->payment as $payment) { $order_id = (string) $payment->order_id; $order_status_array[$order_id]['payments'][] = $payment; } foreach($batch_xml->pickup as $pickup) { $order_id = (string) $pickup->order_id; $order_status_array[$order_id]['pickups'][] = $pickup; } // Is this order cancelled? function is_order_cancelled($order_id) { global $order_status_array; $cancellations = $order_status_array[$order_id]['cancellations']; if(empty($cancellations)) { return false; } elseif(count($cancellations) > 1) { exit("Error: order " . $order_id . " has more than one cancellation."); } else { return current($cancellations); } } // Is this order paid for? function is_order_paid_for($order_id) { global $order_status_array; $payments = $order_status_array[$order_id]['payments']; if(empty($payments)) { return false; } elseif(count($payments) > 1) { exit("Error: order " . $order_id . " has more than one payment."); } else { return current($payments); } } // Is this order picked up? function is_order_picked_up($order_id) { global $order_status_array; $pickups = $order_status_array[$order_id]['pickups']; if(empty($pickups)) { return false; } elseif(count($pickups) > 1) { exit("Error: order " . $order_id . " has more than one pickup."); } else { return current($pickups); } } // Get unique id from object function get_guid($object) { $attribute = 'guid'; $guid = (string) $object->attributes()->$attribute; return $guid; } // Get object from unique id function get_object($guid) { global $batch_xml; foreach($batch_xml->children() as $object) { if($guid == get_guid($object)) { return $object; } } } // How many customers are there right now? function number_of_customers() { global $batch_xml; return count($batch_xml->xpath('/batch/customer')); } // How many shirts have been ordered so far? function number_of_shirts() { global $batch_xml; $result = 0; foreach($batch_xml->order as $order_xml) { if(!is_order_cancelled(get_guid($order_xml))) { $result += count($order_xml->xpath('shirts/shirt')); } } return $result; } ?>