iq2i / prestashop-webservice
A PHP library that let you interact with PrestaShop API
dev-main
2022-01-11 09:41 UTC
Requires
- php: >=8.0.2
- ext-curl: *
- ext-simplexml: *
- psr/log: ^1|^2|^3
- symfony/http-client: ^5.4|^6.0
- symfony/http-client-contracts: ^3
- symfony/serializer: ^5.4|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.3
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^8|^9
This package is auto-updated.
Last update: 2024-11-19 19:33:32 UTC
README
A PHP client library to interact with PrestaShop API.
Installation
composer require iq2i/prestashop-webservice
Basic usage
- Create a client instance:
use IQ2i\PrestashopWebservice\Http\Client; $client = new Client([ 'url' => 'https://my-prestashop.com/api/', 'key' => '6MBWZM37S6XCZXYT81GD6XD41SKZ14TP', ]);
- Create a request:
use IQ2i\PrestashopWebservice\Http\Request\GetRequest; /** GET /api/categories/1 */ $request = new GetRequest('categories', 1);
- Execute request
$response = $client->execute($request);
- Use client's response:
$statusCode = $response->getStatusCode(); $header = $response->getHeaders(); $content = $response->getContent();
The response's content is an array, client automatically decode XML.
A request for each action
use IQ2i\PrestashopWebservice\Http\QueryAttribute\Schema; use IQ2i\PrestashopWebservice\Http\Request\SchemaRequest; /** GET /api/categories?schema=synopsis */ $request = new SchemaRequest('categories'); $request->addQueryAttribute(new Schema(Schema::SYNOPSIS))
use IQ2i\PrestashopWebservice\Http\Request\ListRequest; /** GET /api/categories */ $request = new ListRequest('categories');
use IQ2i\PrestashopWebservice\Http\Request\GetRequest; /** GET /api/categories/1 */ $request = new GetRequest('categories', 1);
use IQ2i\PrestashopWebservice\Http\Request\CreateRequest; /** POST /api/categories */ $request = new CreateRequest('categories'); $request->setBody('XML content');
use IQ2i\PrestashopWebservice\Http\Request\UpdateRequest; /** PUT /api/categories/1 */ $request = new UpdateRequest('categories', 1); $request->setBody('XML content');
use IQ2i\PrestashopWebservice\Http\Request\DeleteRequest; /** DELETE /api/categories/1 */ $request = new DeleteRequest('categories', 1);
Use query attributes
PrestaShop defines list options for webservice: https://devdocs.prestashop.com/1.7/webservice/cheat-sheet/#list-options
These options are available in this library:
use IQ2i\PrestashopWebservice\Http\QueryAttribute\Schema; /** GET /api/categories?schema=synopsis */ $request = new SchemaRequest('categories'); $request->addQueryAttribute(new Schema(Schema::SYNOPSIS));
use IQ2i\PrestashopWebservice\Http\QueryAttribute\Filter; use IQ2i\PrestashopWebservice\Http\QueryAttribute\Sort; /** GET /api/categories?filter[name]=%[clothes]&sort=[name_ASC] */ $request = new ListRequest('categories'); $request->addQueryAttribute(new Filter('name', 'clothes', Filter::END)); $request->addQueryAttribute(new Sort('name', Sort::ASC));
Issues and feature requests
Please report issues and request features at https://github.com/iq2i/prestashop-webservice/issues.
License
This bundle is under the MIT license. For the whole copyright, see the LICENSE file distributed with this source code.