From 2b55c7a1896132cbc547e94bf12e3eeb6ab6c341 Mon Sep 17 00:00:00 2001 From: Daniel Schipper Date: Mon, 13 May 2024 17:23:13 +0200 Subject: [PATCH 1/8] Add plugin service --- .../config/services.service.shopware.xml | 4 ++ src/Service/Shopware/PluginService.php | 69 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/Service/Shopware/PluginService.php diff --git a/src/Resources/config/services.service.shopware.xml b/src/Resources/config/services.service.shopware.xml index 8999b42e..5294678d 100644 --- a/src/Resources/config/services.service.shopware.xml +++ b/src/Resources/config/services.service.shopware.xml @@ -59,5 +59,9 @@ + + + + diff --git a/src/Service/Shopware/PluginService.php b/src/Service/Shopware/PluginService.php new file mode 100644 index 00000000..aafd4646 --- /dev/null +++ b/src/Service/Shopware/PluginService.php @@ -0,0 +1,69 @@ +pluginService = $pluginService; + } + + /** + * @param Context $context + * @return PluginEntity + */ + public function getPlugin(Context $context): PluginEntity + { + return $this->pluginService->getPluginByName($this->getPluginName(), $context); + } + + /** + * @param Context $context + * @return string + */ + public function getAuthor(Context $context): string + { + return $this->getPlugin($context)->getAuthor() ?? ''; + } + + /** + * @param Context $context + * @return string + */ + public function getVersion(Context $context): string + { + return $this->getPlugin($context)->getVersion(); + } + + /** + * @param Context $context + * @return string + */ + public function getUpgradeVersion(Context $context): string + { + return $this->getPlugin($context)->getUpgradeVersion() ?? ''; + } + + /** + * @return string + */ + public function getPluginName(): string + { + $className = PostNLShopware::class; + $chunks = explode('\\', $className); + return end($chunks); + } +} From 08f11f895ea16a5932dd7a46eba55f1781d97034 Mon Sep 17 00:00:00 2001 From: Daniel Schipper Date: Mon, 13 May 2024 17:23:57 +0200 Subject: [PATCH 2/8] Add version provider class --- .../config/services.service.postnl.xml | 8 +- src/Service/PostNL/VersionProvider.php | 74 +++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/Service/PostNL/VersionProvider.php diff --git a/src/Resources/config/services.service.postnl.xml b/src/Resources/config/services.service.postnl.xml index 6d652436..14ceea24 100644 --- a/src/Resources/config/services.service.postnl.xml +++ b/src/Resources/config/services.service.postnl.xml @@ -28,10 +28,12 @@ - - + + - + + %kernel.shopware_version% + diff --git a/src/Service/PostNL/VersionProvider.php b/src/Service/PostNL/VersionProvider.php new file mode 100644 index 00000000..c567342d --- /dev/null +++ b/src/Service/PostNL/VersionProvider.php @@ -0,0 +1,74 @@ +shopwareVersion = $shopwareVersion; + $this->pluginService = $pluginService; + } + + public function getAllAsString(Context $context): string + { + $versions = []; + + foreach($this->getAll($context) as $key => $version) { + $versions[] = sprintf('%s/%s', $key, $version); + } + + return implode(' ', $versions); + } + + public function getAll(Context $context): array + { + return array_filter([ + 'Shopware' => $this->getShopwareVersion(), + $this->pluginService->getPluginName() => $this->getPluginVersion($context), + 'SDK' => $this->getSDKVersion(), + 'PHP' => $this->getPHPVersion(), + ]); + } + + public function getShopwareVersion(): string + { + return $this->shopwareVersion; + } + + public function getPluginVersion(Context $context): string + { + return $this->pluginService->getVersion($context); + } + + public function getSDKVersion(): string + { + if(!class_exists(InstalledVersions::class)) { + return ''; + } + + try { + return InstalledVersions::getPrettyVersion('firstred/postnl-api-php') ?? ''; + } + catch (\OutOfBoundsException $e) { + return ''; + } + } + + public function getPHPVersion(): string + { + return phpversion(); + } +} \ No newline at end of file From 837cb69048902bb800647f1cd30875f8d2a9e9ea Mon Sep 17 00:00:00 2001 From: Daniel Schipper Date: Mon, 13 May 2024 17:24:35 +0200 Subject: [PATCH 3/8] Add headers to request from version provider --- .../config/services.service.postnl.xml | 1 + src/Service/PostNL/Factory/ApiFactory.php | 35 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Resources/config/services.service.postnl.xml b/src/Resources/config/services.service.postnl.xml index 14ceea24..4be26d29 100644 --- a/src/Resources/config/services.service.postnl.xml +++ b/src/Resources/config/services.service.postnl.xml @@ -9,6 +9,7 @@ + diff --git a/src/Service/PostNL/Factory/ApiFactory.php b/src/Service/PostNL/Factory/ApiFactory.php index 4aa95024..7bb259c9 100644 --- a/src/Service/PostNL/Factory/ApiFactory.php +++ b/src/Service/PostNL/Factory/ApiFactory.php @@ -5,32 +5,29 @@ use Firstred\PostNL\Entity\Address; use Firstred\PostNL\Entity\Customer; use Firstred\PostNL\Exception\InvalidArgumentException; +use Firstred\PostNL\Exception\PostNLException; use PostNL\Shopware6\Component\PostNL\Factory\GuzzleRequestFactory; use PostNL\Shopware6\Component\PostNL\PostNL; use PostNL\Shopware6\Exception\PostNL\ClientCreationException; +use PostNL\Shopware6\Service\PostNL\VersionProvider; use PostNL\Shopware6\Service\Shopware\ConfigService; use Psr\Log\LoggerInterface; use Shopware\Core\Framework\Context; class ApiFactory { - /** - * @var ConfigService - */ - private $configService; + protected ConfigService $configService; + protected VersionProvider $versionProvider; + protected LoggerInterface $logger; - /** - * @var LoggerInterface - */ - private $logger; - - /** - * @param ConfigService $configService - * @param LoggerInterface $logger - */ - public function __construct(ConfigService $configService, LoggerInterface $logger) + public function __construct( + ConfigService $configService, + VersionProvider $versionProvider, + LoggerInterface $logger + ) { $this->configService = $configService; + $this->versionProvider = $versionProvider; $this->logger = $logger; } @@ -55,6 +52,11 @@ public function createClient( $requestFactory = new GuzzleRequestFactory(); $requestFactory->addHeader('SourceSystem', 25); + $requestFactory->addHeader('X-PostNL-Client-Versions', $this->versionProvider->getAllAsString(Context::createDefaultContext())); + + if (function_exists("php_uname")) { + $requestFactory->addHeader('X-PostNL-Client-Info', php_uname()); + } $client = new PostNL($customer, $apiKey, $sandbox); $client->setRequestFactory($requestFactory); @@ -77,11 +79,6 @@ public function createClient( } } - /** - * @param string $salesChannelId - * @param Context $context - * @return PostNL - */ public function createClientForSalesChannel(string $salesChannelId, Context $context): PostNL { $this->logger->debug("Creating API client for saleschannel", [ From 5b12bdfe17071adc398372e3fdb0c6174b8b3050 Mon Sep 17 00:00:00 2001 From: Daniel Schipper Date: Tue, 14 May 2024 12:21:19 +0200 Subject: [PATCH 4/8] Load plugin once, remove unnecessary doc, add getPath --- src/Service/Shopware/PluginService.php | 34 +++++++++----------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/Service/Shopware/PluginService.php b/src/Service/Shopware/PluginService.php index aafd4646..04d21221 100644 --- a/src/Service/Shopware/PluginService.php +++ b/src/Service/Shopware/PluginService.php @@ -12,54 +12,42 @@ class PluginService { protected ShopwarePluginService $pluginService; + protected ?PluginEntity $plugin = null; - /** - * @param ShopwarePluginService $pluginService - */ public function __construct(ShopwarePluginService $pluginService) { $this->pluginService = $pluginService; } - /** - * @param Context $context - * @return PluginEntity - */ public function getPlugin(Context $context): PluginEntity { - return $this->pluginService->getPluginByName($this->getPluginName(), $context); + if(!$this->plugin instanceof PluginEntity) { + $this->plugin = $this->pluginService->getPluginByName($this->getPluginName(), $context); + } + + return $this->plugin; } - /** - * @param Context $context - * @return string - */ public function getAuthor(Context $context): string { return $this->getPlugin($context)->getAuthor() ?? ''; } - /** - * @param Context $context - * @return string - */ + public function getPath(Context $context): string + { + return $this->getPlugin($context)->getPath() ?? ''; + } + public function getVersion(Context $context): string { return $this->getPlugin($context)->getVersion(); } - /** - * @param Context $context - * @return string - */ public function getUpgradeVersion(Context $context): string { return $this->getPlugin($context)->getUpgradeVersion() ?? ''; } - /** - * @return string - */ public function getPluginName(): string { $className = PostNLShopware::class; From 5473809e79d924b1b22704814491f4b79530060e Mon Sep 17 00:00:00 2001 From: Daniel Schipper Date: Tue, 14 May 2024 12:21:46 +0200 Subject: [PATCH 5/8] Change loading installed packages --- .../config/services.service.postnl.xml | 1 + src/Service/PostNL/VersionProvider.php | 53 +++++++++++++------ 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/Resources/config/services.service.postnl.xml b/src/Resources/config/services.service.postnl.xml index 4be26d29..7e933b43 100644 --- a/src/Resources/config/services.service.postnl.xml +++ b/src/Resources/config/services.service.postnl.xml @@ -34,6 +34,7 @@ %kernel.shopware_version% + %kernel.project_dir% diff --git a/src/Service/PostNL/VersionProvider.php b/src/Service/PostNL/VersionProvider.php index c567342d..8f92e055 100644 --- a/src/Service/PostNL/VersionProvider.php +++ b/src/Service/PostNL/VersionProvider.php @@ -4,21 +4,25 @@ namespace PostNL\Shopware6\Service\PostNL; -use Composer\InstalledVersions; use PostNL\Shopware6\Service\Shopware\PluginService; use Shopware\Core\Framework\Context; class VersionProvider { protected string $shopwareVersion; + protected string $shopwareRootPath; protected PluginService $pluginService; + private array $composerPackages = []; + public function __construct( string $shopwareVersion, + string $shopwareRootPath, PluginService $pluginService, ) { $this->shopwareVersion = $shopwareVersion; + $this->shopwareRootPath = $shopwareRootPath; $this->pluginService = $pluginService; } @@ -26,7 +30,7 @@ public function getAllAsString(Context $context): string { $versions = []; - foreach($this->getAll($context) as $key => $version) { + foreach ($this->getAll($context) as $key => $version) { $versions[] = sprintf('%s/%s', $key, $version); } @@ -35,12 +39,14 @@ public function getAllAsString(Context $context): string public function getAll(Context $context): array { - return array_filter([ - 'Shopware' => $this->getShopwareVersion(), - $this->pluginService->getPluginName() => $this->getPluginVersion($context), - 'SDK' => $this->getSDKVersion(), - 'PHP' => $this->getPHPVersion(), - ]); + return array_filter( + [ + 'Shopware' => $this->getShopwareVersion(), + $this->pluginService->getPluginName() => $this->getPluginVersion($context), + 'SDK' => $this->getSDKVersion($context), + 'PHP' => $this->getPHPVersion(), + ] + ); } public function getShopwareVersion(): string @@ -53,18 +59,33 @@ public function getPluginVersion(Context $context): string return $this->pluginService->getVersion($context); } - public function getSDKVersion(): string + public function getSDKVersion(Context $context): string { - if(!class_exists(InstalledVersions::class)) { - return ''; - } + if (empty($this->composerPackages)) { + $path = $this->pluginService->getPath($context); + $fullPath = sprintf( + '%s/%s/%s', + rtrim($this->shopwareRootPath, '/'), + rtrim($path, '/'), + 'vendor/composer/installed.php' + ); - try { - return InstalledVersions::getPrettyVersion('firstred/postnl-api-php') ?? ''; + if (!file_exists($fullPath)) { + return ''; + } + + try { + $this->composerPackages = include $fullPath; + } + catch (\Throwable $exception) { + return ''; + } } - catch (\OutOfBoundsException $e) { + + if (!isset($this->composerPackages['versions']['firstred/postnl-api-php']['pretty_version'])) { return ''; - } + }; + return $this->composerPackages['versions']['firstred/postnl-api-php']['pretty_version']; } public function getPHPVersion(): string From 5245ece9e93c28c51a1611b90c464a7470eb7fe3 Mon Sep 17 00:00:00 2001 From: Daniel Schipper Date: Wed, 10 Jul 2024 11:43:39 +0200 Subject: [PATCH 6/8] Update readme --- README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 19d29c7f..0dd70c76 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ -# Shopware -Voor de handleiding ga naar https://postnl.github.io/shopware \ No newline at end of file +# PostNL integratie voor Shopware 6 + +## Welke versie moet ik gebruiken? +Vanwege breaking changes in Shopware zijn we genoodzaakt om voor bepaalde Shopware versies een nieuwe major versie van de plugin uit te brengen. Zie onderstaande tabel welke versie van de plugin geschikt is voor jouw Shopware installatie. + +| Shopware | Plugin | +|-------------------|------------| +| 6.5 vanaf 6.5.2.0 | Versie 3.x | +| 6.4 vanaf 6.4.1.0 | Versie 2.x | + +#### Laatste versies +![Shopware 6.5](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpostnl%2Fshopware%2Fraw%2Fmaster-sw65%2Fcomposer.json&query=version&prefix=Versie%20&style=flat-square&label=Shopware%206.5&color=ed7000) +![Shopware 6.4](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fpostnl%2Fshopware%2Fraw%2Fmaster-sw64%2Fcomposer.json&query=version&prefix=Versie%20&style=flat-square&label=Shopware%206.4&color=ed7000) + +## Installatie +De installatie handleiding is te vinden op https://postnl.github.io/shopware + +Installatie via Composer of door deze repository te clonen is mogelijk, maar wordt niet officieel ondersteunt. Hiervoor zijn extra stappen nodig die niet in de handleiding worden beschreven. + + From ecf96bdfbe33237c69353206598ef7fa4fd2bd7a Mon Sep 17 00:00:00 2001 From: Daniel Schipper Date: Wed, 10 Jul 2024 11:43:47 +0200 Subject: [PATCH 7/8] Update changelogs --- CHANGELOG.md | 3 +++ CHANGELOG_de-DE.md | 3 +++ CHANGELOG_nl-NL.md | 3 +++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bde84ca..520c8134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 3.1.3 +- Added extra headers to the API calls. This enables us to provide better support by monitoring used Shopware and plugin versions. + # 3.1.2 - An incompatibility with the returns management section of the Shopware Commercial plugin was discovered, which caused the PostNL order overview to no longer work. A workaround has been implemented - (Minor) Fixed missing images in the plugin configuration diff --git a/CHANGELOG_de-DE.md b/CHANGELOG_de-DE.md index b283428b..7eb69aee 100644 --- a/CHANGELOG_de-DE.md +++ b/CHANGELOG_de-DE.md @@ -1,3 +1,6 @@ +# 3.1.3 +- Es wurden zusätzliche Header zu den API-Aufrufen hinzugefügt. Dies ermöglicht uns eine bessere Unterstützung durch Überwachung der verwendeten Shopware- und Plugin-Versionen. + # 3.1.2 - Es wurde eine Inkompatibilität mit der Retourenverwaltung des Shopware Commercial Plugins entdeckt, die dazu führte, dass die PostNL Bestellübersicht nicht mehr funktionierte. Ein Workaround wurde implementiert - (Minor) Fehlende Bilder in der Plugin-Konfiguration behoben diff --git a/CHANGELOG_nl-NL.md b/CHANGELOG_nl-NL.md index 9858a75e..d52deaed 100644 --- a/CHANGELOG_nl-NL.md +++ b/CHANGELOG_nl-NL.md @@ -1,3 +1,6 @@ +# 3.1.3 +- Extra headers toegevoegd aan de API-aanroepen. Hierdoor kunnen we betere ondersteuning bieden door de gebruikte Shopware en plugin versies te monitoren. + # 3.1.2 - Er is een incompatibiliteit ontdekt met het retourmanagementgedeelte van de Shopware Commercial plugin, waardoor het PostNL besteloverzicht niet meer werkt. Er is een workaround geïmplementeerd - (Minor) Ontbrekende afbeeldingen in de plugin configuratie opgelost From a39ce23b59d8f998f48ce2c282fc4ccb0265bfbd Mon Sep 17 00:00:00 2001 From: Daniel Schipper Date: Wed, 10 Jul 2024 11:43:54 +0200 Subject: [PATCH 8/8] Update version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 166964be..d798988c 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "postnl/shopware6", "description": "PostNL", "type": "shopware-platform-plugin", - "version": "3.1.2", + "version": "3.1.3", "license": "proprietary", "authors": [ {