PrestaShopWebservice::get PHP Method

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
    public function get($options)
    {
        if (isset($options['url'])) {
            $url = $options['url'];
        } elseif (isset($options['resource'])) {
            $url = $this->url . '/api/' . $options['resource'];
            $url_params = array();
            if (isset($options['id'])) {
                $url .= '/' . $options['id'];
            }
            $params = array('filter', 'display', 'sort', 'limit', 'id_shop', 'id_group_shop');
            foreach ($params as $p) {
                foreach ($options as $k => $o) {
                    if (strpos($k, $p) !== false) {
                        $url_params[$k] = $options[$k];
                    }
                }
            }
            if (count($url_params) > 0) {
                $url .= '?' . http_build_query($url_params);
            }
        } else {
            throw new PrestaShopWebserviceException('Bad parameters given');
        }
        $request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET'));
        self::checkStatusCode($request['status_code']);
        // check the response validity
        return self::parseXML($request['response']);
    }

Usage Example

コード例 #1
0
*  @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';
        }
All Usage Examples Of PrestaShopWebservice::get