function ExecuteOrderCommand($order, $command, $comments, $carrierData, $tracking) { try { // to change statuses, we need to unhold if necessary if ($order->canUnhold()) { $order->unhold(); $order->save(); } switch (strtolower($command)) { case "complete": CompleteOrder($order, $comments, $carrierData, $tracking); break; case "cancel": $order->cancel(); $order->addStatusToHistory($order->getStatus(), $comments); $order->save(); break; case "hold": $order->hold(); $order->addStatusToHistory($order->getStatus(), $comments); $order->save(); break; default: outputError(80, "Unknown order command '{$command}'."); break; } writeStartTag("Debug"); writeElement("OrderStatus", $order->getStatus()); writeCloseTag("Debug"); } catch (Exception $ex) { outputError(90, "Error Executing Command. " . $ex->getMessage()); } }
function Action_GetOrders() { $start = 0; $maxcount = 50; if (isset($_REQUEST['start'])) { $start = $_REQUEST['start']; } if (isset($_REQUEST['maxcount'])) { $maxcount = $_REQUEST['maxcount']; } // NOTE: Drupal stored time commly by unix timestamp, so below codes maybe need some change. // Only get orders through 2 seconds ago. $end = date("Y-m-d H:i:s", time() - 2); // Convert to local SQL time $start = toLocalSqlDate($start); // Write the params for easier diagnostics writeStartTag("Parameters"); writeElement("Start", $start); writeElement("End", $end); writeElement("MaxCount", $maxcount); writeCloseTag("Parameters"); writeStartTag("Orders"); $orders = array(); $items = array(); $items[] = array('item_id' => 'item_001', 'product_id' => 'product_001', 'code' => '001', 'sku' => '001', 'name' => 'Product name 001', 'quantity' => 30, 'unit_price' => 30.55, 'weight' => 12.5); $items[] = array('item_id' => 'item_002', 'product_id' => 'product_002', 'code' => '002', 'sku' => '002', 'name' => 'Product name 002', 'quantity' => 40, 'unit_price' => 12.55, 'weight' => 0.5); $items[] = array('item_id' => 'item_003', 'product_id' => 'product_003', 'code' => '003', 'sku' => '003', 'name' => 'Product name 003', 'quantity' => 15, 'unit_price' => 12.55, 'weight' => 15); $orders[] = array('order_number_prefix' => '', 'order_number' => '00001', 'order_number_postfix' => '', 'order_date' => gmdate("Y-m-d\\TH:i:s", strtotime('2014-08-15')), 'last_modified' => gmdate("Y-m-d\\TH:i:s", time() - 3000), 'shipping_method' => 'Horse', 'status_code' => '001', 'customer_id' => '125', 'shipping_address' => array('full_name' => 'Steve Jobs', 'company' => 'Banana', 'street1' => 'Street 1 content', 'street2' => 'Street 2 content', 'street3' => 'Street 3 content', 'city' => 'Shanghai', 'postal_code' => '200000', 'country' => 'cn', 'phone' => '0086-021-88888888'), 'billing_address' => array('full_name' => 'Bill Gates', 'company' => 'MicroHard', 'street1' => 'Street 1 content', 'street2' => 'Street 2 content', 'street3' => 'Street 3 content', 'city' => 'Shanghai', 'postal_code' => '200000', 'country' => 'cn', 'phone' => '0086-021-66666666'), 'items' => $items); $orders[] = array('order_number_prefix' => '', 'order_number' => '00002', 'order_number_postfix' => '', 'order_date' => gmdate("Y-m-d\\TH:i:s", strtotime('2014-08-26')), 'last_modified' => gmdate("Y-m-d\\TH:i:s", time() - 1200), 'shipping_method' => 'Donkey', 'status_code' => '002', 'customer_id' => '130', 'shipping_address' => array('full_name' => 'Bill Gates', 'company' => 'MicroHard', 'street1' => 'Street 1 content', 'street2' => 'Street 2 content', 'street3' => 'Street 3 content', 'city' => 'Shanghai', 'postal_code' => '200000', 'country' => 'cn', 'phone' => '0086-021-88888888'), 'billing_address' => array('full_name' => 'Bill Gates', 'company' => 'MicroHard', 'street1' => 'Street 1 content', 'street2' => 'Street 2 content', 'street3' => 'Street 3 content', 'city' => 'Shanghai', 'postal_code' => '200000', 'country' => 'cn', 'phone' => '0086-021-66666666'), 'items' => $items); $orders[] = array('order_number_prefix' => '', 'order_number' => '00003', 'order_number_postfix' => '', 'order_date' => gmdate("Y-m-d\\TH:i:s", strtotime('2014-09-05')), 'last_modified' => gmdate("Y-m-d\\TH:i:s", time() - 200), 'shipping_method' => 'Camel', 'status_code' => '003', 'customer_id' => '133', 'shipping_address' => array('full_name' => 'Bill Gates', 'company' => 'MicroHard', 'street1' => 'Street 1 content', 'street2' => 'Street 2 content', 'street3' => 'Street 3 content', 'city' => 'Shanghai', 'postal_code' => '200000', 'country' => 'cn', 'phone' => '0086-021-88888888'), 'billing_address' => array('full_name' => 'Bill Gates', 'company' => 'MicroHard', 'street1' => 'Street 1 content', 'street2' => 'Street 2 content', 'street3' => 'Street 3 content', 'city' => 'Shanghai', 'postal_code' => '200000', 'country' => 'cn', 'phone' => '0086-021-66666666'), 'items' => $items); // ShipWorks will make repeated calls to GetOders to download order data, and will cease when the response contains no orders. // So in this test server, we need uncomment below code (empty orders) when start downloading to avoid unlimited circle. $orders = array(); foreach ($orders as $order) { writeStartTag("Order"); writeElement("OrderNumberPrefix", $order['order_number_prefix']); writeElement("OrderNumber", $order['order_number']); writeElement("OrderNumberPostfix", $order['order_number_postfix']); writeElement("OrderDate", $order['order_date']); writeElement("LastModified", $order['last_modified']); writeElement("ShippingMethod", $order['shipping_method']); writeElement("StatusCode", $order['status_code']); writeElement("CustomerID", $order['customer_id']); writeStartTag("ShippingAddress"); writeElement("FullName", $order['shipping_address']['full_name']); writeElement("Company", $order['shipping_address']['company']); writeElement("Street1", $order['shipping_address']['street1']); writeElement("Street2", $order['shipping_address']['street2']); writeElement("Street3", $order['shipping_address']['street3']); writeElement("City", $order['shipping_address']['city']); writeElement("PostalCode", $order['shipping_address']['postal_code']); writeElement("Country", $order['shipping_address']['country']); writeElement("Phone", $order['shipping_address']['phone']); writeCloseTag("ShippingAddress"); writeStartTag("BillingAddress"); writeElement("FullName", $order['billing_address']['full_name']); writeElement("Company", $order['billing_address']['company']); writeElement("Street1", $order['billing_address']['street1']); writeElement("Street2", $order['billing_address']['street2']); writeElement("Street3", $order['billing_address']['street3']); writeElement("City", $order['billing_address']['city']); writeElement("PostalCode", $order['billing_address']['postal_code']); writeElement("Country", $order['billing_address']['country']); writeElement("Phone", $order['billing_address']['phone']); writeCloseTag("BillingAddress"); writeStartTag("Items"); $items = $order['items']; foreach ($items as $item) { writeStartTag("Item"); writeElement("ItemID", $item['item_id']); writeElement("ProductID", $item['product_id']); writeElement("Code", $item['code']); writeElement("SKU", $item['sku']); writeElement("Name", $item['name']); writeElement("Quantity", (int) $item['quantity']); writeElement("UnitPrice", $item['unit_price']); writeElement("Weight", $item['weight']); writeCloseTag("Item"); } writeCloseTag("Items"); writeStartTag("Totals"); writeCloseTag("Totals"); writeCloseTag("Order"); } writeCloseTag("Orders"); }
public static function initializeSCO() { global $link; global $SCOInstanceID; // has the SCO previously been initialized? $this->_db =& JFactory::getDbo(); $result = $this->_db->setQuery("select count(VarName) from #__gg_scormvars where (SCOInstanceID={$SCOInstanceID})"); list($count) = $this->_db->loadResult(); FB::log($count, "count"); // $result = mysql_query("select count(VarName) from #__gg_scormvars where (SCOInstanceID=$SCOInstanceID)",$link); // list($count) = mysql_fetch_row($result); // not yet initialized - initialize all elements if (!$count) { // elements that tell the SCO which other elements are supported by this API initializeElement('cmi.core._children', 'student_id,student_name,lesson_location,credit,lesson_status,entry,score,total_time,exit,session_time'); initializeElement('cmi.core.score._children', 'raw'); // student information initializeElement('cmi.core.student_name', getFromLMS('cmi.core.student_name')); initializeElement('cmi.core.student_id', getFromLMS('cmi.core.student_id')); // test score initializeElement('cmi.core.score.raw', ''); initializeElement('adlcp:masteryscore', getFromLMS('adlcp:masteryscore')); // SCO launch and suspend data initializeElement('cmi.launch_data', getFromLMS('cmi.launch_data')); initializeElement('cmi.suspend_data', ''); // progress and completion tracking initializeElement('cmi.core.lesson_location', ''); initializeElement('cmi.core.credit', 'credit'); initializeElement('cmi.core.lesson_status', 'not attempted'); initializeElement('cmi.core.entry', 'ab-initio'); initializeElement('cmi.core.exit', ''); // seat time initializeElement('cmi.core.total_time', '0000:00:00'); initializeElement('cmi.core.session_time', ''); } // new session so clear pre-existing session time writeElement('cmi.core.session_time', ''); // create the javascript code that will be used to set up the javascript cache, $initializeCache = "var cache = new Object();\n"; $result = mysql_query("select VarName,VarValue from #__gg_scormvars where (SCOInstanceID={$SCOInstanceID})", $link); while (list($varname, $varvalue) = mysql_fetch_row($result)) { // make the value safe by escaping quotes and special characters $jvarvalue = addslashes($varvalue); // javascript to set the initial cache value $initializeCache .= "cache['{$varname}'] = '{$jvarvalue}';\n"; } // return javascript for cache initialization to the calling program return $initializeCache; }