Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.80 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. function internal_parse_json($json) {
  3.    if(version_compare(PHP_VERSION,"5.2.0",">=")) {
  4.      return json_decode($json, true);
  5.     }
  6.        include_once('JSON.php');
  7.        $json_parser = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
  8.        return $json_parser->decode($json);
  9.    }
  10.  
  11.    function internal_fetch_url_libcurl($url) {
  12.        if (intval($timeout) <= 0)
  13.            $timeout = 90;
  14.        if (!function_exists('curl_init'))
  15.            return array("code"=>"0","data"=>"libcurl is not installed");
  16.        $headers[] = "Content-Type: application/x-www-form-urlencoded";
  17.        $ch = curl_init();
  18.  
  19.        curl_setopt ($ch, CURLOPT_URL, $url);
  20.        curl_setopt ($ch, CURLOPT_HEADER, 0);
  21.        curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
  22.        curl_setopt ($ch, CURLOPT_HTTPGET, 1);
  23.        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  24.  
  25.        $body = curl_exec ($ch);
  26.        $errno = curl_errno ($ch);
  27.        $error = curl_error($ch);
  28.  
  29.        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  30.        $result = array();
  31.        if( $error ) {
  32.            return array("code"=>"0","data"=>"libcurl error($errno): $error");
  33.        }
  34.  
  35.        return array("code"=>$httpcode, "data"=>$body);
  36.    }
  37.  
  38.  
  39. $orders = internal_fetch_url_libcurl("https://app.ecwid.com/api/v1/XXXXXXXX/orders?secure_auth_key=XXXXXXXXXXXX&statuses=NEW,ACCEPTED");
  40. $orders = $orders["data"];
  41. $orders = internal_parse_json($orders);
  42. $orders = $orders["orders"];
  43. //print_r($orders);
  44. $message = "";
  45. foreach($orders as $order) {
  46. $message = $message . "\n\nOrder #" . $order["number"];
  47.         foreach ($order["items"] as $item) {
  48. $message .= "\n\t" . $item["name"] . "\t" . $item["sku"];
  49. if (is_array($item["options"]))
  50. foreach($item["options"] as $option) {
  51. $message .= "\n\t\t" . $option["name"] . " - " . $option["value"];
  52. }
  53.  
  54. }
  55.  
  56. }
  57. //echo $message;
  58. //send $message
  59. ?>