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");
}
예제 #2
0
function Action_GetOrders()
{
    $storeId = Mage::app()->getStore()->storeId;
    $start = 0;
    $maxcount = 50;
    if (isset($_REQUEST['start'])) {
        $start = $_REQUEST['start'];
    }
    if (isset($_REQUEST['maxcount'])) {
        $maxcount = $_REQUEST['maxcount'];
    }
    // 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");
    // setup the query
    $orders = Mage::getModel('sales/order')->getCollection();
    $orders->addAttributeToSelect("*")->getSelect()->where("(updated_at > '{$start}' AND updated_at <= '{$end}' AND store_id = {$storeId})")->order('updated_at', 'asc');
    // configure paging
    $orders->setCurPagE(1)->setPageSize($maxcount)->loadData();
    writeStartTag("Orders");
    $lastModified = null;
    $processedIds = "";
    foreach ($orders as $order) {
        // keep track of the ids we've downloaded
        $lastModified = $order->getUpdatedAt();
        if ($processedIds != "") {
            $processedIds .= ", ";
        }
        $processedIds .= $order->getEntityId();
        WriteOrder($order);
    }
    // if we processed some orders we may have to get some more
    if ($processedIds != "") {
        $orders = Mage::getModel('sales/order')->getCollection();
        $orders->addAttributeToSelect("*")->getSelect()->where("updated_at = '{$lastModified}' AND entity_id not in ({$processedIds}) AND store_id = {$storeId}");
        foreach ($orders as $order) {
            WriteOrder($order);
        }
    }
    writeCloseTag("Orders");
}