Shopware 6 PHP SDK
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.
If you're familiar with Shopware 6 DAL syntax and how to retrieve it you might see this example is predictable and straightforward
Installation
Install with Composer
composer require vin-sw/shopware-sdk
The SDK main features:
-
Admin API
- CRUD API
- Sync Api
- Other services
- ... (TODO)
-
Webhook helper
- Webhook registration
- Webhook authentication
- Webhook receiver
Usage
More in the examples folder, for integrating the sdk in an App, have a look at this repository
Admin Authentication
- Supported 3 grant types, you can create one of these 3 grant type for authentication:
Using Password grant type
$grantType = new PasswordGrantType($username, $password);
Using Client credential grant type
$grantType = new ClientCredentialsGrantType($clientId, $clientSecret);
Using Refresh token grant type
$grantType = new RefreshTokenGrantType($refreshToken);
Or dynamically via
$grantType = GrantType::createFromConfig($config);
Check the authentication example for the reference.
After having a GrantType object, you can fetch the admin's access token using the AdminAuthenticator
$adminClient = new AdminAuthenticator($grantType, $shopUrl);
$accessToken = $adminClient->fetchAccessToken();
$context = new Context($shopUrl, $accessToken);
Notice: You might want to store the access token object into the database so you can create the object without request for another access token for every Admin API request.
Working with Criteria and Repositories
It's pretty identical to what you expected when working with Shopware's core or repositories in the SW administration.
This is an example to retrieve a product that have free shipping
// Create the repository for the entity
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
// Create the criteria
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('shippingFree', true));
// Using this criteria and the context object that you create from authentication step, you can retrieving the result
$products = $productRepository->search($criteria, $context);
Each shopware's entity is mapped into Entity and Collection Classes which can be found in Data/Entity so you can easily access their properties when retrieving data from Admin API.
Support methods get
, search
, searchIds
, create
, update
, delete
, syncDeleted
, createVersion
, mergeVersion
, deleteVersion
, clone
, schema
. Each method requires a Context object
Check examples/entity-repository.php for some useful references.
Working with API Services
- Current supported services:
- InfoService
- UserService
- StateMachineService
- SyncService
- For other services that does not have a concrete class, use: AdminActionService
An ApiService requires a Context object as its first argument. Check examples/sync-service.php or examples/info-service.php for some references.
Change log
Please see CHANGELOG for more information on what has changed recently.
Working with Webhook
- Check the integration on our AppExample
Contribution
Feels free to create an issue on Github issues page or contact me directly at [email protected]
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Requirements
- ext-curl
- PHP 7.4
- SW >= 6.4
This SDK is mainly dedicated to Shopware 6.4 and onwards, earlier SW application may still be usable without test
Credits
License
The MIT License (MIT). Please see License File for more information.