Skip to content

Commit

Permalink
FFWEB-2953: Add reporting for Shopware marketplace
Browse files Browse the repository at this point in the history
Add reporting for Shopware marketplace
  • Loading branch information
Rayn93 authored Jan 23, 2024
1 parent 3b5f571 commit 4d12391
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog
## Unreleased
### Add
- Add reporting for Shopware marketplace
- Add PHPStan
### Change
- Set FactFinder cookies as required for Cookie Consent Manager
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ NG | ✔️

To install the plugin, open your terminal and run the command:

composer require omikron/shopware6-factfinder^5.0
composer require omikron/shopware6-factfinder

After successfully installation, it will be visible in the extensions list. Depending on the Shopware 6 versions
the view could be different.
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,15 @@
<service id="Omikron\FactFinder\Shopware6\Utilites\Ssr\Template\Engine" />
<service id="Omikron\FactFinder\Shopware6\Config\FieldRolesInterface"
alias="Omikron\FactFinder\Shopware6\Config\FieldRoles" />

<service id="Omikron\FactFinder\Shopware6\ScheduledTask\MarketplaceReportTask">
<tag name="shopware.scheduled.task" />
</service>
<service id="Omikron\FactFinder\Shopware6\ScheduledTask\MarketplaceReportTaskHandler">
<tag name="messenger.message_handler" />
<argument type="service" id="scheduled_task.repository"/>
<argument>%kernel.shopware_version%</argument>
<argument>%instance_id%</argument>
</service>
</services>
</container>
20 changes: 20 additions & 0 deletions src/ScheduledTask/MarketplaceReportTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Omikron\FactFinder\Shopware6\ScheduledTask;

use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTask;

class MarketplaceReportTask extends ScheduledTask
{
public static function getTaskName(): string
{
return 'factfinder.marketplace_report_task';
}

public static function getDefaultInterval(): int
{
return 2592000; // 1 month in seconds
}
}
57 changes: 57 additions & 0 deletions src/ScheduledTask/MarketplaceReportTaskHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Omikron\FactFinder\Shopware6\ScheduledTask;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler(handles: MarketplaceReportTask::class)]
class MarketplaceReportTaskHandler extends ScheduledTaskHandler
{
public const API_IDENTIFIER = 'd7ae3439-1a5c-45bd-b5ca-172b42511c7f';
private Client $client;

public function __construct(
EntityRepository $scheduledTaskRepository,
private readonly string $shopwareVersion,
private readonly ?string $instanceId
) {
parent::__construct($scheduledTaskRepository);
$this->client = new Client();
}

public static function getHandledMessages(): iterable
{
return [MarketplaceReportTask::class];
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function run(): void
{
$now = new \DateTime();
$data = [
'identifier' => self::API_IDENTIFIER,
'reportDate' => $now->format(\DateTimeInterface::ATOM),
'instanceId' => $this->instanceId,
'shopwareVersion' => $this->shopwareVersion,
'reportDataKeys' => [
'numberOfSubscriptions' => 0,
'numberOfCustomers' => 1,
],
];
$request = new Request(
'POST',
'https://api.shopware.com/shopwarepartners/reports/technology',
[],
json_encode($data)
);
$this->client->send($request);
}
}

0 comments on commit 4d12391

Please sign in to comment.