PHP Класс PrestaShopWebservice

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$debug is debug activated
$key Authentification key
$url Shop URL
$version PS version

Открытые методы

Метод Описание
__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 )

Защищенные методы

Метод Описание
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

Описание методов

__construct() публичный Метод

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() публичный Метод

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
Результат SimpleXMLElement status_code, response

checkStatusCode() защищенный Метод

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() публичный Метод

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() публичный Метод

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() защищенный Метод

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)
Результат array status_code, response

get() публичный Метод

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.
Результат SimpleXMLElement status_code, response

getVersion() публичный Метод

public getVersion ( )

head() публичный Метод

Head method (HEAD) a resource
public head ( array $options ) : SimpleXMLElement
$options array Array representing resource for head request.
Результат SimpleXMLElement status_code, response

parseXML() защищенный Метод

Load XML from string. Can throw exception
protected parseXML ( string $response ) : SimpleXMLElement
$response string String from a CURL response
Результат SimpleXMLElement status_code, response

printDebug() публичный Метод

public printDebug ( $title, $content )

Описание свойств

$debug защищенное свойство

is debug activated
protected $debug

$key защищенное свойство

Authentification key
protected $key

$url защищенное свойство

Shop URL
protected $url

$version защищенное свойство

PS version
protected $version