Skip to content

Commit

Permalink
Merge branch 'release/3.1.3' into master-sw65
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-memo-ict committed Jul 10, 2024
2 parents 10bbfca + a39ce23 commit a36c2e2
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG_nl-NL.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# Shopware
Voor de handleiding ga naar https://postnl.github.io/shopware
# 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.


2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "postnl/shopware6",
"description": "PostNL",
"type": "shopware-platform-plugin",
"version": "3.1.2",
"version": "3.1.3",
"license": "proprietary",
"authors": [
{
Expand Down
10 changes: 7 additions & 3 deletions src/Resources/config/services.service.postnl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<service id="PostNL\Shopware6\Service\PostNL\Factory\ApiFactory">
<argument type="service" id="PostNL\Shopware6\Service\Shopware\ConfigService"/>
<argument type="service" id="PostNL\Shopware6\Service\PostNL\VersionProvider"/>
<argument type="service" id="postnl.logger"/>
</service>

Expand All @@ -28,10 +29,13 @@
<argument type="service" id="Shopware\Core\Content\Media\MediaService"/>
</service>

<service id="PostNL\Shopware6\Service\PostNL\RuleCreatorService">
</service>
<service id="PostNL\Shopware6\Service\PostNL\RuleCreatorService"/>
<service id="PostNL\Shopware6\Service\PostNL\ShippingRulePriceCreatorService"/>

<service id="PostNL\Shopware6\Service\PostNL\ShippingRulePriceCreatorService">
<service id="PostNL\Shopware6\Service\PostNL\VersionProvider">
<argument>%kernel.shopware_version%</argument>
<argument>%kernel.project_dir%</argument>
<argument type="service" id="PostNL\Shopware6\Service\Shopware\PluginService"/>
</service>

<service id="PostNL\Shopware6\Service\PostNL\ShipmentService">
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/config/services.service.shopware.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@
<argument type="service" id="PostNL\Shopware6\Service\Attribute\Factory\AttributeFactory"/>
<argument type="service" id="PostNL\Shopware6\Service\Shopware\ConfigService"/>
</service>

<service id="PostNL\Shopware6\Service\Shopware\PluginService">
<argument type="service" id="Shopware\Core\Framework\Plugin\PluginService"/>
</service>
</services>
</container>
35 changes: 16 additions & 19 deletions src/Service/PostNL/Factory/ApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand All @@ -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", [
Expand Down
95 changes: 95 additions & 0 deletions src/Service/PostNL/VersionProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

declare(strict_types=1);

namespace PostNL\Shopware6\Service\PostNL;

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;
}

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($context),
'PHP' => $this->getPHPVersion(),
]
);
}

public function getShopwareVersion(): string
{
return $this->shopwareVersion;
}

public function getPluginVersion(Context $context): string
{
return $this->pluginService->getVersion($context);
}

public function getSDKVersion(Context $context): string
{
if (empty($this->composerPackages)) {
$path = $this->pluginService->getPath($context);
$fullPath = sprintf(
'%s/%s/%s',
rtrim($this->shopwareRootPath, '/'),
rtrim($path, '/'),
'vendor/composer/installed.php'
);

if (!file_exists($fullPath)) {
return '';
}

try {
$this->composerPackages = include $fullPath;
}
catch (\Throwable $exception) {
return '';
}
}

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
{
return phpversion();
}
}
57 changes: 57 additions & 0 deletions src/Service/Shopware/PluginService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace PostNL\Shopware6\Service\Shopware;

use PostNL\Shopware6\PostNLShopware;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Plugin\PluginEntity;
use Shopware\Core\Framework\Plugin\PluginService as ShopwarePluginService;

class PluginService
{
protected ShopwarePluginService $pluginService;
protected ?PluginEntity $plugin = null;

public function __construct(ShopwarePluginService $pluginService)
{
$this->pluginService = $pluginService;
}

public function getPlugin(Context $context): PluginEntity
{
if(!$this->plugin instanceof PluginEntity) {
$this->plugin = $this->pluginService->getPluginByName($this->getPluginName(), $context);
}

return $this->plugin;
}

public function getAuthor(Context $context): string
{
return $this->getPlugin($context)->getAuthor() ?? '';
}

public function getPath(Context $context): string
{
return $this->getPlugin($context)->getPath() ?? '';
}

public function getVersion(Context $context): string
{
return $this->getPlugin($context)->getVersion();
}

public function getUpgradeVersion(Context $context): string
{
return $this->getPlugin($context)->getUpgradeVersion() ?? '';
}

public function getPluginName(): string
{
$className = PostNLShopware::class;
$chunks = explode('\\', $className);
return end($chunks);
}
}

0 comments on commit a36c2e2

Please sign in to comment.