PHP Class PrestaShopWebservice

ファイルを表示 Open project: prestashop/prestashop-webservice-lib Class Usage Examples

Protected Properties

Property Type Description
$debug is debug activated
$key Authentification key
$url Shop URL
$version PS version

Public Methods

Method Description
__construct ( string $url, string $key, mixed $debug = true ) PrestaShopWebservice constructor. Throw an exception when CURL is not installed/activated getMessage(); } ?>
add ( array $options ) : SimpleXMLElement Add (POST) a resource

Unique parameter must take :

'resource' => Resource name
'postXml' => Full XML string to add resource

Examples are given in the tutorial

delete ( array $options ) Delete (DELETE) a resource.
edit ( array $options ) Edit (PUT) a resource

Unique parameter must take :

'resource' => Resource name ,
'id' => ID of a resource you want to edit,
'putXml' => Modified XML string of a resource

Examples are given in the tutorial

get ( array $options ) : SimpleXMLElement 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(); } ?>
getVersion ( )
head ( array $options ) : SimpleXMLElement Head method (HEAD) a resource
printDebug ( $title, $content )

Protected Methods

Method Description
checkStatusCode ( integer $status_code ) Take the status code and throw an exception if the server didn't return 200 or 201 code
executeRequest ( string $url, mixed $curl_params = [] ) : array Handles a CURL request to PrestaShop Webservice. Can throw exception.
parseXML ( string $response ) : SimpleXMLElement Load XML from string. Can throw exception

Method Details

__construct() public method

PrestaShopWebservice constructor. Throw an exception when CURL is not installed/activated getMessage(); } ?>
public __construct ( string $url, string $key, mixed $debug = true )
$url string Root URL for the shop
$key string Authentification key
$debug mixed Debug mode Activated (true) or deactivated (false)

add() public method

Add (POST) a resource

Unique parameter must take :

'resource' => Resource name
'postXml' => Full XML string to add resource

Examples are given in the tutorial

public add ( array $options ) : SimpleXMLElement
$options array
return SimpleXMLElement status_code, response

checkStatusCode() protected method

Take the status code and throw an exception if the server didn't return 200 or 201 code
protected checkStatusCode ( integer $status_code )
$status_code integer Status code of an HTTP return

delete() public method

Unique parameter must take :

'resource' => Resource name
'id' => ID or array which contains IDs of a resource(s) you want to delete

delete(array('resource' => 'orders', 'id' => 1)); Following code will not be executed if an exception is thrown. echo 'Successfully deleted.'; } catch (PrestaShopWebserviceException $ex) { echo 'Error : '.$ex->getMessage(); } ?>
public delete ( array $options )
$options array Array representing resource to delete.

edit() public method

Edit (PUT) a resource

Unique parameter must take :

'resource' => Resource name ,
'id' => ID of a resource you want to edit,
'putXml' => Modified XML string of a resource

Examples are given in the tutorial

public edit ( array $options )
$options array Array representing resource to edit.

executeRequest() protected method

Handles a CURL request to PrestaShop Webservice. Can throw exception.
protected executeRequest ( string $url, mixed $curl_params = [] ) : array
$url string Resource name
$curl_params mixed CURL parameters (sent to curl_set_opt)
return array status_code, response

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

getVersion() public method

public getVersion ( )

head() public method

Head method (HEAD) a resource
public head ( array $options ) : SimpleXMLElement
$options array Array representing resource for head request.
return SimpleXMLElement status_code, response

parseXML() protected method

Load XML from string. Can throw exception
protected parseXML ( string $response ) : SimpleXMLElement
$response string String from a CURL response
return SimpleXMLElement status_code, response

printDebug() public method

public printDebug ( $title, $content )

Property Details

$debug protected_oe property

is debug activated
protected $debug

$key protected_oe property

Authentification key
protected $key

$url protected_oe property

Shop URL
protected $url

$version protected_oe property

PS version
protected $version