Skip to content

Commit d2fc0be

Browse files
committed
First release
1 parent 365ed49 commit d2fc0be

File tree

695 files changed

+21503
-3069
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

695 files changed

+21503
-3069
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor/
2-
/var/*
2+
/var/*
3+
.idea

.idea/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

.idea/php.xml

Lines changed: 0 additions & 107 deletions
This file was deleted.

.idea/shopware-sdk.iml

Lines changed: 0 additions & 97 deletions
This file was deleted.

.idea/sonarlint/issuestore/index.pb

Whitespace-only changes.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Shopware 6 PHP SDK
2+
3+
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.
4+
5+
If you're familiar with Shopware 6 DAL syntax and how to retrieve it you might see this example is predictable and straightforward
6+
7+
![image](https://i.imgur.com/NyXy2db.png)
8+
9+
## Installation
10+
Install with Composer
11+
```shell
12+
composer require vin-sw/shopware-sdk
13+
```
14+
15+
# The SDK main features:
16+
17+
- Admin API
18+
- CRUD API
19+
- Sync Api
20+
- Other services
21+
- ... (TODO)
22+
23+
- Webhook helper
24+
- Webhook registration
25+
- Webhook authentication
26+
- Webhook receiver
27+
28+
## Usage
29+
30+
More in the examples folder, for integrating the sdk in an App, have a look at this [repository](https://github.com/vienthuong/AppExample)
31+
32+
## Admin Authentication
33+
- Supported 3 grant types, you can create one of these 3 grant type for authentication:
34+
35+
Using Password grant type
36+
```php
37+
$grantType = new PasswordGrantType($username, $password);
38+
```
39+
40+
Using Client credential grant type
41+
42+
```php
43+
$grantType = new ClientCredentialsGrantType($clientId, $clientSecret);
44+
```
45+
46+
Using Refresh token grant type
47+
48+
```php
49+
$grantType = new RefreshTokenGrantType($refreshToken);
50+
```
51+
52+
Or dynamically via
53+
54+
```php
55+
$grantType = GrantType::createFromConfig($config);
56+
```
57+
58+
Check the [authentication](examples/authentication.php) example for the reference.
59+
60+
After having a GrantType object, you can fetch the admin's access token using the AdminAuthenticator
61+
62+
```php
63+
$adminClient = new AdminAuthenticator($grantType, $shopUrl);
64+
$accessToken = $adminClient->fetchAccessToken();
65+
$context = new Context($shopUrl, $accessToken);
66+
```
67+
68+
**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.
69+
70+
## Working with Criteria and Repositories
71+
72+
It's pretty identical to what you expected when working with Shopware's core or repositories in the SW administration.
73+
74+
This is an example to retrieve a product that have free shipping
75+
```php
76+
// Create the repository for the entity
77+
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
78+
79+
// Create the criteria
80+
$criteria = new Criteria();
81+
$criteria->addFilter(new EqualsFilter('shippingFree', true));
82+
83+
// Using this criteria and the context object that you create from authentication step, you can retrieving the result
84+
$products = $productRepository->search($criteria, $context);
85+
```
86+
87+
Each shopware's entity is mapped into Entity and Collection Classes which can be found in [Data/Entity](/src/Data/Entity) so you can easily access their properties when retrieving data from Admin API.
88+
89+
Support methods `get`, `search`, `searchIds`, `create`, `update`, `delete`, `syncDeleted`, `createVersion`, `mergeVersion`, `deleteVersion`, `clone`, `schema`.
90+
Each method requires a [Context](src/Data/Context.php) object
91+
92+
Check [examples/entity-repository.php](/examples/entity-repository.php) for some useful references.
93+
94+
## Working with API Services
95+
- Current supported services:
96+
- [InfoService](/src/Service/InfoService.php)
97+
- [UserService](/src/Service/UserService.php)
98+
- [StateMachineService](/src/Service/StateMachineService.php)
99+
- [SyncService](/src/Service/SyncService.php)
100+
- For other services that does not have a concrete class, use: [AdminActionService](/src/Service/AdminActionService.php)
101+
102+
An ApiService requires a [Context](src/Data/Context.php) object as its first argument.
103+
Check [examples/sync-service.php](/examples/sync-service.php) or [examples/info-service.php](/examples/info-service.php) for some references.
104+
105+
## Working with Webhook
106+
- Check the integration on our [AppExample](https://github.com/vienthuong/AppExample)
107+
108+
## Contribution
109+
Feels free to create an issue on Github issues page or contact me directly at levienthuong@gmail.com
110+
111+
### Requirements
112+
- ext-curl
113+
- PHP 7.4
114+
- SW >= 6.4
115+
116+
This SDK is mainly dedicated to Shopware 6.4 and onwards, earlier SW application may still be usable without test

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"name": "vin-sw/shopware-php-sdk",
2+
"name": "vin-sw/shopware-sdk",
33
"description": "A PHP SDK for Shopware 6 Platform",
44
"type": "library",
55
"license": "MIT",
6+
"version": "1.0.0",
67
"authors": [
78
{
89
"name": "vin",
@@ -20,7 +21,8 @@
2021
"squizlabs/php_codesniffer": "3.*",
2122
"symplify/easy-coding-standard": "9.3.20",
2223
"symplify/config-transformer": "^9.3",
23-
"phpstan/phpstan": "^0.12.89"
24+
"phpstan/phpstan": "^0.12.89",
25+
"symfony/var-dumper": "^5.3"
2426
},
2527
"autoload": {
2628
"psr-4": {

0 commit comments

Comments
 (0)