Skip to content

Commit

Permalink
Merge pull request #30 from vienthuong/1.4.0
Browse files Browse the repository at this point in the history
Release 1.4.0
  • Loading branch information
vienthuong authored Mar 4, 2022
2 parents b6dc82f + 24e04d4 commit 30686d8
Show file tree
Hide file tree
Showing 58 changed files with 880 additions and 23 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to `shopware-php-sdk` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

### 1.4.0
- Updated Latest DAL Classes
- Added NotificationService to allow sending/getting notification from external app (success/error/warning/info)
- Added UserConfigService to getting/saving admin's config
- Added AdminSearchService to search for multiple entities as one request
- Added more service's examples
- Deprecated SystemConfigService::saveConfiguration, use SystemConfigService::save instead
- Deprecated SystemConfigService::batchSaveConfiguration, use SystemConfigService::batchSave instead

### 1.3.3
- [Use correct sync operator for syncDeleted](https://github.com/vienthuong/shopware-php-sdk/pull/16)
- [Remove extends HttpClient from GuzzleClient](https://github.com/vienthuong/shopware-php-sdk/issues/5)
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ If you're familiar with Shopware 6 DAL syntax and how to retrieve it you might s

![image](https://i.imgur.com/NyXy2db.png)

Or sending notification from external server
![image](https://i.imgur.com/26LdTab.png)

## Installation
Install with Composer
```shell
Expand All @@ -25,6 +28,9 @@ composer require vin-sw/shopware-sdk
- Admin API
- CRUD API
- Sync Api
- User Config API
- Notification API
- Admin Search API
- Other services
- ... (TODO)

Expand Down Expand Up @@ -165,6 +171,9 @@ new OpenModalResponse($shopSecret, $iframeUrl, OpenModalResponse::LARGE_SIZE, tr
- [UserService](/src/Service/UserService.php)
- [StateMachineService](/src/Service/StateMachineService.php)
- [SyncService](/src/Service/SyncService.php)
- [NotificationService](/src/Service/NotificationService.php)
- [UserConfigService](/src/Service/UserConfigService.php)
- [AdminSearchService](/src/Service/AdminSearchService.php)
- For other services that does not have a concrete class, use: [AdminActionService](/src/Service/AdminActionService.php)

An ApiService requires a [Context](src/Data/Context.php) object as its first argument.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A PHP SDK for Shopware 6 Platform",
"type": "library",
"license": "MIT",
"version": "1.3.3",
"version": "1.4.0",
"authors": [
{
"name": "vin",
Expand Down
37 changes: 37 additions & 0 deletions examples/admin-search-service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use Vin\ShopwareSdk\Data\Context;
use Vin\ShopwareSdk\Service\AdminSearchService;
use Vin\ShopwareSdk\Data\Criteria;
use Vin\ShopwareSdk\Service\Struct\KeyValuePairs;
use Vin\ShopwareSdk\Service\Struct\KeyValuePair;

class AdminSearchExample {
public function execute(): void
{
require __DIR__ . '/token.php';

$context = new Context($config['shop_url'], $accessToken);
$service = new AdminSearchService($context);

$productCriteria = new Criteria();
$productCriteria->addAssociation('categories');
$productCriteria->setTerm('feeb9f03a8ca49749f8cce86c9a3d4d7');

$customerCriteria = new Criteria();
$customerCriteria->setTerm('501e41803e7b4ca8b54a7ed72b498568pharvey@example.com');

$criteriaCollection = new KeyValuePairs();
$criteriaCollection->add(KeyValuePair::create('product', $productCriteria));
$criteriaCollection->add(KeyValuePair::create('customer', $customerCriteria));

$result = $service->search($criteriaCollection);

dd($result);
}
}

$example = new AdminSearchExample();
$example->execute();
27 changes: 27 additions & 0 deletions examples/notification-service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use Vin\ShopwareSdk\Data\Context;
use Vin\ShopwareSdk\Service\NotificationService;
use Vin\ShopwareSdk\Service\Struct\Notification;

class NotificationServiceExample {
public function execute(): void
{
require __DIR__ . '/token.php';

$context = new Context($config['shop_url'], $accessToken);
$service = new NotificationService($context);

$notification = Notification::createNotificationSuccess('Hello from External App!');

$service->sendNotification($notification);

$notifications = $service->fetchNotification();
dump($notifications);
}
}

$example = new NotificationServiceExample();
$example->execute();
27 changes: 27 additions & 0 deletions examples/system-config-service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use Vin\ShopwareSdk\Data\Context;
use Vin\ShopwareSdk\Service\SystemConfigService;
use Vin\ShopwareSdk\Service\Struct\KeyValuePair;

class SystemConfigServiceExample {
public function execute(): void
{
require __DIR__ . '/token.php';

$context = new Context($config['shop_url'], $accessToken);
$service = new SystemConfigService($context);

$config = KeyValuePair::create('my.config.key1', ['test' => 'my.config.value1']);

$service->save($config);

$config = $service->getConfiguration('core.basicInformation');
dump($config);
}
}

$example = new SystemConfigServiceExample();
$example->execute();
31 changes: 31 additions & 0 deletions examples/user-config-service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use Vin\ShopwareSdk\Data\Context;
use Vin\ShopwareSdk\Service\UserConfigService;
use Vin\ShopwareSdk\Service\Struct\KeyValuePair;
use Vin\ShopwareSdk\Service\Struct\KeyValuePairs;

class UserConfigServiceExample {
public function execute(): void
{
require __DIR__ . '/token.php';

$context = new Context($config['shop_url'], $accessToken);
$service = new UserConfigService($context);

$config1 = KeyValuePair::create('my.config.key1', ['test' => 'my.config.value1']);
$config2 = KeyValuePair::create('my.config.key2', ['another' => 'my.config.value2']);

$pairs = new KeyValuePairs([$config1, $config2]);

$service->saveConfigMe($pairs);

$configs = $service->getConfigMe($pairs->getKeys());
dump($configs);
}
}

$example = new UserConfigServiceExample();
$example->execute();
5 changes: 5 additions & 0 deletions script/src/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ private static function escapeJson(array $input) {

private static function getTypedProperty(string $entityNamespace, string $entityName, ClassGenerator $class, Property $property): ?string
{
// TODO: hotfix for ConfigJsonFieldSerializer bug in core
if ($entityName === 'SystemConfig' && $property->name === 'configurationValue') {
return null;
}

$prefix = '?';

// $flags = $property->flags;
Expand Down
6 changes: 6 additions & 0 deletions src/Data/Aggregation/HistogramAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
class HistogramAggregation extends Aggregation
{
public const PER_MINUTE = 'minute';

public const PER_HOUR = 'hour';

public const PER_DAY = 'day';

public const PER_WEEK = 'week';

public const PER_MONTH = 'month';

public const PER_QUARTER = 'quarter';

public const PER_YEAR = 'year';

public string $name;
Expand Down
1 change: 1 addition & 0 deletions src/Data/Entity/App/AppDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getSchema() : Schema
new Property('customFieldSets', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), new Flag('cascade_delete', 1), ]), ['entity' => 'custom_field_set', 'referenceField' => 'appId', 'localField' => 'id', 'relation' => 'one_to_many', ]),
new Property('actionButtons', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), new Flag('cascade_delete', 1), ]), ['entity' => 'app_action_button', 'referenceField' => 'appId', 'localField' => 'id', 'relation' => 'one_to_many', ]),
new Property('templates', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), new Flag('cascade_delete', 1), ]), ['entity' => 'app_template', 'referenceField' => 'appId', 'localField' => 'id', 'relation' => 'one_to_many', ]),
new Property('scripts', 'association', new FlagCollection([new Flag('cascade_delete', 1), ]), ['entity' => 'script', 'referenceField' => 'appId', 'localField' => 'id', 'relation' => 'one_to_many', ]),
new Property('webhooks', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), new Flag('cascade_delete', 1), ]), ['entity' => 'webhook', 'referenceField' => 'appId', 'localField' => 'id', 'relation' => 'one_to_many', ]),
new Property('paymentMethods', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), new Flag('set_null_on_delete', 1), ]), ['entity' => 'app_payment_method', 'referenceField' => 'appId', 'localField' => 'id', 'relation' => 'one_to_many', ]),
new Property('cmsBlocks', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), new Flag('cascade_delete', 1), ]), ['entity' => 'app_cms_block', 'referenceField' => 'appId', 'localField' => 'id', 'relation' => 'one_to_many', ]),
Expand Down
3 changes: 3 additions & 0 deletions src/Data/Entity/App/AppEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Vin\ShopwareSdk\Data\Entity\CustomFieldSet\CustomFieldSetCollection;
use Vin\ShopwareSdk\Data\Entity\AppActionButton\AppActionButtonCollection;
use Vin\ShopwareSdk\Data\Entity\AppTemplate\AppTemplateCollection;
use Vin\ShopwareSdk\Data\Entity\Script\ScriptCollection;
use Vin\ShopwareSdk\Data\Entity\Webhook\WebhookCollection;
use Vin\ShopwareSdk\Data\Entity\AppPaymentMethod\AppPaymentMethodCollection;
use Vin\ShopwareSdk\Data\Entity\AppCmsBlock\AppCmsBlockCollection;
Expand Down Expand Up @@ -71,6 +72,8 @@ class AppEntity extends Entity

public ?AppTemplateCollection $templates = null;

public ?ScriptCollection $scripts = null;

public ?WebhookCollection $webhooks = null;

public ?AppPaymentMethodCollection $paymentMethods = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function getSchema() : Schema
new Property('identifier', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), new Flag('required', 1), ]), []),
new Property('payUrl', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
new Property('finalizeUrl', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
new Property('validateUrl', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
new Property('captureUrl', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
new Property('appId', 'uuid', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
new Property('app', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), ['entity' => 'app', 'referenceField' => 'id', 'localField' => 'appId', 'relation' => 'many_to_one', ]),
new Property('originalMediaId', 'uuid', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
Expand Down
4 changes: 4 additions & 0 deletions src/Data/Entity/AppPaymentMethod/AppPaymentMethodEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class AppPaymentMethodEntity extends Entity

public ?string $finalizeUrl = null;

public ?string $validateUrl = null;

public ?string $captureUrl = null;

public ?string $appId = null;

public ?AppEntity $app = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Entity/Country/CountryDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function getSchema() : Schema
new Property('name', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), new Flag('required', 1), new Flag('search_ranking', 500), new Flag('translatable', 1), ]), []),
new Property('iso', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), new Flag('search_ranking', 250), ]), []),
new Property('position', 'int', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('taxFree', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), new Flag('deprecated', unserialize('a:3:{s:16:"deprecated_since";s:6:"v6.4.0";s:18:"will_be_removed_in";s:6:"v6.5.0";s:11:"replaced_by";N;}')), ]), []),
new Property('active', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('shippingAvailable', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('iso3', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), new Flag('search_ranking', 250), ]), []),
Expand All @@ -48,6 +47,7 @@ public function getSchema() : Schema
new Property('companyTaxFree', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), new Flag('deprecated', unserialize('a:3:{s:16:"deprecated_since";s:6:"v6.4.0";s:18:"will_be_removed_in";s:6:"v6.5.0";s:11:"replaced_by";N;}')), ]), []),
new Property('checkVatIdPattern', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('vatIdRequired', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('taxFree', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), new Flag('deprecated', unserialize('a:3:{s:16:"deprecated_since";s:6:"v6.4.0";s:18:"will_be_removed_in";s:6:"v6.5.0";s:11:"replaced_by";N;}')), ]), []),
new Property('vatIdPattern', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('customFields', 'json_object', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), new Flag('translatable', 1), ]), []),
new Property('customerTax', 'json_object', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), ['properties' => json_decode('{"enabled":{"type":"boolean","flags":{"read_protected":[["Shopware\\Core\\Framework\\Api\\Context\\AdminApiSource"]],"required":true}},"currencyId":{"type":"string","flags":{"read_protected":[["Shopware\\Core\\Framework\\Api\\Context\\AdminApiSource"]],"required":true}},"amount":{"type":"float","flags":{"read_protected":[["Shopware\\Core\\Framework\\Api\\Context\\AdminApiSource"]],"required":true}}}', true), ]),
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Entity/Country/CountryEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class CountryEntity extends Entity

public ?int $position = null;

public ?bool $taxFree = null;

public ?bool $active = null;

public ?bool $shippingAvailable = null;
Expand All @@ -41,6 +39,8 @@ class CountryEntity extends Entity

public ?bool $vatIdRequired = null;

public ?bool $taxFree = null;

public ?string $vatIdPattern = null;

public ?array $customerTax = null;
Expand Down
1 change: 1 addition & 0 deletions src/Data/Entity/Customer/CustomerDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getSchema() : Schema
new Property('guest', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('firstLogin', 'date', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('lastLogin', 'date', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('newsletterSalesChannelIds', 'json_object', new FlagCollection([new Flag('write_protected', [['system']]), ]), []),
new Property('newsletter', 'boolean', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('birthday', 'date', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), ]), []),
new Property('lastOrderDate', 'date', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource', 'Shopware\Core\Framework\Api\Context\SalesChannelApiSource']]), new Flag('write_protected', [['system']]), ]), []),
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Entity/Customer/CustomerEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class CustomerEntity extends Entity

public ?\DateTimeInterface$lastLogin = null;

public ?array $newsletterSalesChannelIds = null;

public ?bool $newsletter = null;

public ?\DateTimeInterface$birthday = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getSchema() : Schema
new Property('username', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
new Property('profileName', 'string', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
new Property('config', 'json_object', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), new Flag('required', 1), ]), []),
new Property('result', 'json_object', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), []),
new Property('user', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), ['entity' => 'user', 'referenceField' => 'id', 'localField' => 'userId', 'relation' => 'many_to_one', ]),
new Property('profile', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), ['entity' => 'import_export_profile', 'referenceField' => 'id', 'localField' => 'profileId', 'relation' => 'many_to_one', ]),
new Property('file', 'association', new FlagCollection([new Flag('read_protected', [['Shopware\Core\Framework\Api\Context\AdminApiSource']]), ]), ['entity' => 'import_export_file', 'referenceField' => 'id', 'localField' => 'fileId', 'relation' => 'one_to_one', ]),
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Entity/ImportExportLog/ImportExportLogEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ImportExportLogEntity extends Entity

public ?array $config = null;

public ?array $result = null;

public ?UserEntity $user = null;

public ?ImportExportProfileEntity $profile = null;
Expand Down
Loading

0 comments on commit 30686d8

Please sign in to comment.