get() public method

Retrieve (GET) a resource

Unique parameter must take :

'url' => Full URL for a GET request of Webservice (ex: http://mystore.com/api/customers/1/)
OR
'resource' => Resource name,
'id' => ID of a resource you want to get

get(array('resource' => 'orders', 'id' => 1)); Here in $xml, a SimpleXMLElement object you can parse foreach ($xml->children()->children() as $attName => $attValue) echo $attName.' = '.$attValue.'
'; } catch (PrestaShopWebserviceException $ex) { echo 'Error : '.$ex->getMessage(); } ?>
public get ( array $options ) : SimpleXMLElement
$options array Array representing resource to get.
return SimpleXMLElement status_code, response
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
* PrestaShop Webservice Library
* @package PrestaShopWebservice
*/
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://www.myshop.com/');
define('PS_WS_AUTH_KEY', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ');
require_once './PSWebServiceLibrary.php';
// Here we use the WebService to get the schema of "customers" resource
try {
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
    $opt = array('resource' => 'customers');
    if (isset($_GET['Create'])) {
        $xml = $webService->get(array('url' => PS_SHOP_PATH . '/api/customers?schema=blank'));
    } else {
        $xml = $webService->get($opt);
    }
    $resources = $xml->children()->children();
} catch (PrestaShopWebserviceException $e) {
    // Here we are dealing with errors
    $trace = $e->getTrace();
    if ($trace[0]['args'][0] == 404) {
        echo 'Bad ID';
    } else {
        if ($trace[0]['args'][0] == 401) {
            echo 'Bad auth key';
        } else {
            echo 'Other error';
        }
* PrestaShop Webservice Library
* @package PrestaShopWebservice
*/
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://www.myshop.com/');
define('PS_WS_AUTH_KEY', 'VIVELADIVISIONMOBILEDEPRESTASHOP');
require_once './PSWebServiceLibrary.php';
// First : We always get the customer's list or a specific one
try {
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
    $opt = array('resource' => 'customers');
    if (isset($_GET['id'])) {
        $opt['id'] = $_GET['id'];
    }
    $xml = $webService->get($opt);
    // Here we get the elements from children of customer markup which is children of prestashop root markup
    $resources = $xml->children()->children();
} catch (PrestaShopWebserviceException $e) {
    // Here we are dealing with errors
    $trace = $e->getTrace();
    if ($trace[0]['args'][0] == 404) {
        echo 'Bad ID';
    } else {
        if ($trace[0]['args'][0] == 401) {
            echo 'Bad auth key';
        } else {
            echo 'Other error';
        }
    }
}
Example #3
0
function add_product_feature_value($feature_id, $value){
        $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
	$opt1 = array('resource' => 'product_feature_values');
        $xml1 = $webService->get(array('url' => PS_SHOP_PATH.'/api/product_feature_values?schema=blank'));
	$resources1 = $xml1->children()->children();
        $resources1->value->language[0]=$value;
        $resources1->value->language[1]=$value;
        $resources1->id_feature=$feature_id;
        $resources1->custom=1;
        $opt1['postXml'] = $xml1->asXML();
        $xml1 = $webService -> add($opt1);
        $result1 = $xml1->children()->children();
        return $result1->{'id'};
}
Example #4
0
// Статус заказа "Истекает срок хранения заказа для самовывоза"
define('N', 14);
// Через сколько дней высылать напоминание о самовывозе
define('ID_EMPLOYEE', 0);
// Сотрудник, от чьего имени обновляется статус
define('LOG_FILENAME', 'selfdelivery_state_change.log');
require_once './PSWebServiceLibrary.php';
$n = isset($_GET['n']) && !empty($_GET['n']) && is_numeric($_GET['n']) ? $_GET['n'] : N;
$log_str .= "Установлен срок хранения " . $n . " дней\r\n";
// Here we make the WebService Call
try {
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
    // Here we set the option array for the Webservice : we want orders resources
    $opt['resource'] = 'orders';
    // Call
    $xml = $webService->get($opt);
    // Here we get the elements from children of customers markup "orders"
    $orders_resources = $xml->orders->children();
} catch (PrestaShopWebserviceException $e) {
    // Here we are dealing with errors
    $trace = $e->getTrace();
    if ($trace[0]['args'][0] == 404) {
        echo 'Bad ID';
    } else {
        if ($trace[0]['args'][0] == 401) {
            echo 'Bad auth key';
        } else {
            echo 'Other error';
        }
    }
}
    include "PSWebServiceLibrary.php";
} else {
    echo "<br><br>";
    echo "PrestaShop Web Service Library  file ({$filename}) is missing.<br>Please, make sure \"{$filename}\" file is present in the root folder of store i.e. same folder where ShippingZ integration files are placed.";
    exit;
}
//Extract Path to Prestashop
$folder_path = $_SERVER['SCRIPT_NAME'];
$folder_path_temp = explode("/", $folder_path);
$actual_file_name = $folder_path_temp[count($folder_path_temp) - 1];
$folder_path = "http://" . $_SERVER['HTTP_HOST'] . str_replace($actual_file_name, "", $folder_path);
echo "Checking accessibility of prestashop webservice API and permission of required prestashop resources.........<br>";
try {
    //Make API call
    $webService = new PrestaShopWebservice($folder_path, PRESTASHOP_API_KEY, true);
} catch (PrestaShopWebserviceException $ex) {
    //get user friendly error message
    echo "<br>" . $ex->getMessage();
}
try {
    //Get Order Details using API
    $xml = $webService->get(array('resource' => 'orders', 'id' => $test_order_id));
    $order_resources = $xml->children()->children();
    //Get Customer Details
    $opt = array('resource' => 'customers');
    $opt['id'] = $order_resources->id_customer;
    $xml = $webService->get($opt);
} catch (PrestaShopWebserviceException $ex) {
    //get user friendly error message
    echo "<br>" . $ex->getMessage();
}
Example #6
0
    } while ($hasComb && $i < count($combArray));
}
try {
    ob_start();
    try {
        $cat = simplexml_load_file('cat_template_1.9.xml');
        echo "<html><body><pre>";
        // creating web service access
        $ws = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, false);
        trc("PS WebService created");
        $cres = new psCategory($ws, PS_ID_LANG);
        $vat = new psVat($ws, PS_ID_LANG);
        $combRes = new psCombinationResolver($ws, PS_ID_LANG);
        $vat->setup();
        //$xml = $ws->get(array('resource' => 'products','display' => 'full'));
        $xml = $ws->get(array('resource' => 'products'));
        //        dbg($xml->children()->asXML());
        $prodCnt = 1;
        foreach ($xml->children()->children() as $product_url) {
            //           if ($product_url['id'] != 162) {
            //               continue;
            //           }
            trc("Processing product " . $prodCnt);
            $prodCnt++;
            //            $product_url = $xml->children()->children()[5];
            //            dbgvar($product_url);
            dbg("product id=" . $product_url['id']);
            $xml = $ws->get(array('url' => 'http://' . PS_SHOP_PATH . '/api/products/' . $product_url['id']));
            //            dbg($xml->asXML());
            addCItem($cat, $ws, $xml->children(), PS_ID_LANG);
        }
 function Fetch_DB_Orders($datefrom, $dateto)
 {
     global $db_pdo;
     $datefrom_timestamp = $this->GetServerTimeLocal(false, $datefrom);
     $dateto_timestamp = $this->GetServerTimeLocal(false, $dateto);
     $order_status_filter = $this->PreparePrestaShopOrderStatusFilter();
     $sql = "SELECT  a.id_order, oh.id_order_state  FROM `" . _DB_PREFIX_ . "orders` a\n\t\tLEFT JOIN `" . _DB_PREFIX_ . "order_history` oh ON (oh.`id_order` = a.`id_order`)\n\t\tWHERE " . $order_status_filter . "  (( DATE_FORMAT(a.date_add,\"%Y-%m-%d %T\") between :dateform and :dateto) OR  ( DATE_FORMAT(a.date_upd,\"%Y-%m-%d %T\") between :dateform  and :dateto)) AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `" . _DB_PREFIX_ . "order_history` moh WHERE moh.`id_order` = a.`id_order`)";
     $result = $db_pdo->prepare($sql);
     $data = array(':dateform' => $this->GetServerTimeLocal(true, $datefrom), ':dateto' => $this->GetServerTimeLocal(true, $dateto));
     $result->execute($data);
     $counter = 0;
     foreach ($result as $order_result) {
         $order_id = $order_result['id_order'];
         $id_order_state = $order_result['id_order_state'];
         //Extract Path to Prestashop
         $folder_path = $_SERVER['SCRIPT_NAME'];
         $folder_path_temp = explode("/", $folder_path);
         $actual_file_name = $folder_path_temp[count($folder_path_temp) - 1];
         $folder_path = "http://" . $_SERVER['HTTP_HOST'] . str_replace($actual_file_name, "", $folder_path);
         // call to retrieve order details
         $webService = new PrestaShopWebservice($folder_path, PRESTASHOP_API_KEY, false);
         try {
             //Get Order Details
             $xml = $webService->get(array('resource' => 'orders', 'id' => $order_id));
             $order_resources = $xml->children()->children();
             //Get Customer Details
             $opt = array('resource' => 'customers');
             $opt['id'] = $order_resources->id_customer;
             $xml = $webService->get($opt);
             $prestashop_orders_temp = $xml->children()->children();
             //Prepare order array
             $this->prestashop_orders[$counter]->orderid = $this->GetFieldNumber($order_resources, "id", -2);
             //Shipping details
             $address_result = $db_pdo->prepare("SELECT * FROM `" . _DB_PREFIX_ . "address` where `id_address`=:id_address");
             $address_result->execute(array(':id_address' => $this->GetFieldNumber($order_resources, "id_address_delivery", -2)));
             foreach ($address_result as $shipping_address) {
                 $this->prestashop_orders[$counter]->order_shipping["FirstName"] = $this->GetFieldString($shipping_address, "firstname");
                 $this->prestashop_orders[$counter]->order_shipping["LastName"] = $this->GetFieldString($shipping_address, "lastname");
                 $this->prestashop_orders[$counter]->order_shipping["Company"] = $this->GetFieldString($shipping_address, "company");
                 $this->prestashop_orders[$counter]->order_shipping["Address1"] = $this->GetFieldString($shipping_address, "address1");
                 $this->prestashop_orders[$counter]->order_shipping["Address2"] = $this->GetFieldString($shipping_address, "address2");
                 $this->prestashop_orders[$counter]->order_shipping["City"] = $this->GetFieldString($shipping_address, "city");
                 $this->prestashop_orders[$counter]->order_shipping["PostalCode"] = $this->GetFieldString($shipping_address, "postcode");
                 $this->prestashop_orders[$counter]->order_shipping["Phone"] = $this->GetFieldString($shipping_address, "phone");
                 $this->prestashop_orders[$counter]->order_shipping["State"] = "";
                 $state_result = $db_pdo->prepare("SELECT iso_code  from `" . _DB_PREFIX_ . "state`  where `id_state` =:id_state");
                 $state_result->execute(array(':id_state' => $this->GetFieldNumber($shipping_address, "id_state")));
                 foreach ($state_result as $state_code) {
                     $this->prestashop_orders[$counter]->order_shipping["State"] = $this->GetFieldString($state_code, "iso_code");
                 }
                 $country_result = $db_pdo->prepare("SELECT iso_code  from `" . _DB_PREFIX_ . "country`  where `id_country` = :id_country");
                 $country_result->execute(array(':id_country' => $this->GetFieldNumber($shipping_address, "id_country")));
                 foreach ($country_result as $country_code) {
                     $this->prestashop_orders[$counter]->order_shipping["Country"] = $this->GetFieldString($country_code, "iso_code");
                 }
             }
             $this->prestashop_orders[$counter]->order_shipping["EMail"] = $this->GetFieldString($prestashop_orders_temp, "email", -2);
             //billing details
             $billing_address_result = $db_pdo->prepare("SELECT * FROM `" . _DB_PREFIX_ . "address`  where `id_address` = :id_address");
             $billing_address_result->execute(array(':id_address' => $this->GetFieldNumber($order_resources, "id_address_invoice", -2)));
             foreach ($billing_address_result as $billing_address) {
                 $this->prestashop_orders[$counter]->order_billing["FirstName"] = $this->GetFieldString($billing_address, "firstname");
                 $this->prestashop_orders[$counter]->order_billing["LastName"] = $this->GetFieldString($billing_address, "lastname");
                 $this->prestashop_orders[$counter]->order_billing["Company"] = $this->GetFieldString($billing_address, "company");
                 $this->prestashop_orders[$counter]->order_billing["Address1"] = $this->GetFieldString($billing_address, "address1");
                 $this->prestashop_orders[$counter]->order_billing["Address2"] = $this->GetFieldString($billing_address, "address2");
                 $this->prestashop_orders[$counter]->order_billing["City"] = $this->GetFieldString($billing_address, "city");
                 $this->prestashop_orders[$counter]->order_billing["PostalCode"] = $this->GetFieldString($billing_address, "postcode");
                 $this->prestashop_orders[$counter]->order_billing["Phone"] = $this->GetFieldString($billing_address, "phone");
                 $this->prestashop_orders[$counter]->order_billing["State"] = "";
                 $state_result = $db_pdo->prepare("SELECT iso_code  from `" . _DB_PREFIX_ . "state`  where `id_state` =:id_state");
                 $state_result->execute(array(':id_state' => $this->GetFieldNumber($billing_address, "id_state")));
                 foreach ($state_result as $state_code) {
                     $this->prestashop_orders[$counter]->order_billing["State"] = $this->GetFieldString($state_code, "iso_code");
                 }
                 $sql_country = $db_pdo->prepare("SELECT iso_code  from `" . _DB_PREFIX_ . "country`  where `id_country` = :id_country");
                 $country_result->execute(array(':id_country' => $this->GetFieldNumber($billing_address, "id_country")));
                 foreach ($country_result as $country_code) {
                     $this->prestashop_orders[$counter]->order_billing["Country"] = $this->GetFieldString($country_code, "iso_code");
                 }
             }
             //order info
             $this->prestashop_orders[$counter]->order_info["OrderDate"] = $this->ConvertServerTimeToUTC(true, strtotime(stripslashes($this->GetFieldString($order_resources, "date_add", -2))));
             $this->prestashop_orders[$counter]->order_info["ItemsTotal"] = stripslashes($this->GetField($order_resources, "total_products", -2));
             $this->prestashop_orders[$counter]->order_info["Total"] = stripslashes($this->GetField($order_resources, "total_paid", -2));
             $this->prestashop_orders[$counter]->order_info["ShippingChargesPaid"] = stripslashes($this->GetField($order_resources, "total_shipping", -2));
             $shipping_result = $db_pdo->prepare("SELECT name  from `" . _DB_PREFIX_ . "carrier`  where `id_carrier` =:id_carrier");
             $shipping_result->execute(array(':id_carrier' => $this->GetFieldNumber($order_resources, "id_carrier", -2)));
             $this->prestashop_orders[$counter]->order_info["ShipMethod"] = "Not Available";
             if ($shipping_result->rowCount() > 0) {
                 foreach ($shipping_result as $shipping_method_details) {
                     $this->prestashop_orders[$counter]->order_info["ShipMethod"] = $this->GetFieldString($shipping_method_details, "name");
                 }
             }
             $this->prestashop_orders[$counter]->order_info["ItemsTax"] = 0;
             $this->prestashop_orders[$counter]->order_info["Comments"] = "";
             $this->prestashop_orders[$counter]->order_info["OrderNumber"] = $this->prestashop_orders[$counter]->orderid;
             //get payment type
             $this->prestashop_orders[$counter]->order_info["PaymentType"] = $this->ConvertPaymentType($this->GetFieldString($order_resources, "payment", -2));
             if ($id_order_state != "1" && $id_order_state != "10" && $id_order_state != "11") {
                 $this->prestashop_orders[$counter]->order_info["PaymentStatus"] = 2;
             } else {
                 $this->prestashop_orders[$counter]->order_info["PaymentStatus"] = 0;
             }
             //Show Order status
             if ($id_order_state == "4" || $id_order_state == "5") {
                 $this->prestashop_orders[$counter]->order_info["IsShipped"] = 1;
             } else {
                 $this->prestashop_orders[$counter]->order_info["IsShipped"] = 0;
             }
             $this->prestashop_orders[$counter]->order_info["Comments"] = "";
             //Customer Comments
             $comments_result = $db_pdo->prepare("SELECT *  from `" . _DB_PREFIX_ . "message`  where `id_customer`=:id_customer and `id_order` =:id_order ");
             $comments_result->execute(array('id_customer' => $order_resources->id_customer, ':id_order' => $this->prestashop_orders[$counter]->orderid));
             foreach ($comments_result as $comment_data_arr) {
                 $this->prestashop_orders[$counter]->order_info["Comments"] = $this->GetFieldString($comment_data_arr, "message");
             }
             //Gift message
             if ($this->GetFieldNumber($order_resources, "gift", -2) == "1") {
                 if ($this->prestashop_orders[$counter]->order_info["Comments"] != "") {
                     $this->prestashop_orders[$counter]->order_info["Comments"] .= " (Gift Message-" . stripslashes($this->GetFieldString($order_resources, "gift_message", -2)) . ")";
                 } else {
                     $this->prestashop_orders[$counter]->order_info["Comments"] .= "Gift Message-" . stripslashes($this->GetFieldString($order_resources, "gift_message", -2));
                 }
             }
             //Get Products
             $product_result = $db_pdo->prepare("SELECT *  from `" . _DB_PREFIX_ . "order_detail`  where `id_order` =:id_order ");
             $product_result->execute(array(':id_order' => $this->prestashop_orders[$counter]->orderid));
             $i = 0;
             foreach ($product_result as $product_data_arr) {
                 $this->prestashop_orders[$counter]->order_product[$i]["Name"] = $this->GetFieldString($product_data_arr, "product_name");
                 $this->prestashop_orders[$counter]->order_product[$i]["Price"] = $this->GetFieldMoney($product_data_arr, "product_price");
                 //reduction price
                 $reduction_amount = $this->GetFieldMoney($product_data_arr, "reduction_amount");
                 $reduction_percent = $this->GetFieldMoney($product_data_arr, "reduction_percent");
                 if ($reduction_percent != "0.00") {
                     $reduction_amount = $reduction_percent / 100 * $this->prestashop_orders[$counter]->order_product[$i]["Price"];
                 }
                 $this->prestashop_orders[$counter]->order_product[$i]["Price"] = $this->prestashop_orders[$counter]->order_product[$i]["Price"] - $reduction_amount;
                 $this->prestashop_orders[$counter]->order_product[$i]["Quantity"] = $this->GetFieldNumber($product_data_arr, "product_quantity");
                 $this->prestashop_orders[$counter]->order_product[$i]["Total"] = $this->FormatNumber($this->prestashop_orders[$counter]->order_product[$i]["Price"] * $this->GetFieldNumber($product_data_arr, "product_quantity"));
                 $this->prestashop_orders[$counter]->order_product[$i]["Total_Product_Weight"] = $this->GetFieldNumber($product_data_arr, "product_weight") * $this->GetFieldNumber($product_data_arr, "product_quantity");
                 $tax = $this->prestashop_orders[$counter]->order_product[$i]["Price"] * $this->GetFieldNumber($product_data_arr, "tax_rate") * $this->GetFieldNumber($product_data_arr, "product_quantity") / 100;
                 $this->prestashop_orders[$counter]->order_product[$i]["ExternalID"] = $this->GetFieldString($product_data_arr, "product_id");
                 $this->prestashop_orders[$counter]->order_info["ItemsTax"] += $tax;
                 $i++;
             }
             $this->prestashop_orders[$counter]->num_of_products = $i;
         } catch (PrestaShopWebserviceException $ex) {
             //$trace = $ex->getTrace();
             echo "Could not access prestashop API";
             exit;
         }
         $counter++;
     }
 }