axro/shopware-oauth2-client

Shopware 6 OAuth2 API Client

3.0.0 2024-02-06 07:32 UTC

This package is auto-updated.

Last update: 2024-05-06 08:00:01 UTC


README

Use it to send requests to Shopware 6 API.

Controls the authentication and renewal of the token independently.

Installation

Install package:

composer require axro/shopware-oauth2-client

Usage

Requests

use AxroShopware\Client\ShopwareClient;

// Create an instance with your credentials
$client = new ShopwareClient(
    $baseUrl, $clientId, $clientSecret
);

// add your monolog logger LoggerInterface
$client->setLogger($logger);

// send a request with the payload requested by the api.
$client->request('PATCH', '/api/_action/example_extension/update', $payload);

// to return a object instead of an array, set 4th argument to true
$client->request('PATCH', '/api/_action/example_extension/update', $payload, true);
$client->request('GET', 'api/product/', [], true);

Async Requests

use AxroShopware\Client\ShopwareClient;

// Create an instance with your credentials
$client = new ShopwareClient(
    $baseUrl, $clientId, $clientSecret
);

// add your monolog logger LoggerInterface
$client->setLogger($logger);

// send a request with the payload requested by the api.
foreach(something...) {
    // create $payload with your data from foreach etc.
    $client->requestAsync('PATCH', '/api/_action/example_extension/update', $payload);
}
$responses = $client->promise();

// to return objects in numeric array instead of an array, set argument to true
$responses = $client->promise(true);

You can use the HTTP methods: GET, POST, PATCH, PUT, DELETE

Indexing

Indexing is set by default to "use-queue-indexing".

You can change it to synchronously or disable.

$client->indexing(const::INDEXING_SYNC)->requestAsync('PATCH', '/api/_action/example_extension/update', $payload);

Following constants are defined for sync behavior in ShopwareClient:

INDEXING_SYNC    => Data will be indexed synchronously
INDEXING_QUEUE   => Data will be indexed asynchronously
INDEXING_DISABLE => Data indexing is completely disabled