Skip to content

Commit 3b1bb1f

Browse files
authored
FFWEB-3438: Add automated feed export
Add automated feed export base on Shopware Scheduled Task
1 parent 2063bfb commit 3b1bb1f

7 files changed

Lines changed: 134 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Unreleased
33
### Add
44
- Add to cart button for record list
5+
- Add automated feed export base on Shopware Scheduled Task
56

67
## [v7.0.0] - 2025.07.23
78
### BREAKING

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,24 @@ Following settings are used for uploading already exported feed to a given FTP/S
208208

209209
You can check if the above data is correctly set by clicking on the `Test Connection` button. Please save your settings before clicking on button.
210210

211+
## Automatic Export Settings
212+
213+
![automatic-export-settings.png](docs/assets/automatic-export-settings.png)
214+
215+
The plugin provides a configuration section in the administration panel that allows you to enable or disable automatic export and define which sales channel and language should be used for the products export.
216+
By default, the automatic export is disabled. Once the administrator enables it and choose the sales channel and language, the automatic export will be active.
217+
By default, automatic export is performed once every 48 hours. If you want to change this value, you must overwrite the `ExportScheduledTask` file as follows:
218+
219+
//src/ScheduledTask/ExportScheduledTask.php
220+
public static function getDefaultInterval(): int
221+
{
222+
// change this value to adjust the export interval. This value is in seconds.
223+
// for example: 48 hours = 172800
224+
return 172800;
225+
}
226+
227+
Automatic Export is based on Shopware Scheduled Task. For more information, see the [Shopware documentation](https://developer.shopware.com/docs/guides/plugins/plugins/plugin-fundamentals/add-scheduled-task.html)
228+
211229
## Category Pages
212230

213231
Plugin offers a way to use FACT-Finder® Web Components on category pages using page builder Shopping Experiences. There
88.5 KB
Loading

src/Resources/config/config.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,37 @@
303303
<name>testApiConnection</name>
304304
</component>
305305
</card>
306+
307+
<card>
308+
<title>Automatic Export Settings</title>
309+
<title lang="de-DE">Einstellungen für automatischen Export</title>
310+
<input-field type="bool">
311+
<name>autoExportEnabled</name>
312+
<label>Enable Automatic Export</label>
313+
<label lang="de-DE">Automatischen Export aktivieren</label>
314+
<helpText>Enable or disable the automatic export feature. More information in the documentation</helpText>
315+
<helpText lang="de-DE">Aktivieren oder deaktivieren Sie die Funktion für den automatischen Export.</helpText>
316+
<defaultValue>false</defaultValue>
317+
</input-field>
318+
<component name="sw-entity-single-select">
319+
<name>autoExportSelectedSalesChannel</name>
320+
<label>Select Sales Channel</label>
321+
<label lang="de-DE">Vertriebskanal auswählen</label>
322+
<helpText>Select the sales channel for automatic export.</helpText>
323+
<helpText lang="de-DE">Wählen Sie den Vertriebskanal für den automatischen Export.</helpText>
324+
<entity>sales_channel</entity>
325+
<placeholder>Select a sales channel...</placeholder>
326+
<placeholder lang="de-DE">Vertriebskanal auswählen...</placeholder>
327+
</component>
328+
<component name="sw-entity-single-select">
329+
<name>autoExportSelectedLanguage</name>
330+
<label>Select Language</label>
331+
<label lang="de-DE">Sprache auswählen</label>
332+
<helpText>Select the language for the export.</helpText>
333+
<helpText lang="de-DE">Wählen Sie die Sprache für den Export des Vertriebskanals.</helpText>
334+
<entity>language</entity>
335+
<placeholder>Select a language...</placeholder>
336+
<placeholder lang="de-DE">Sprache auswählen...</placeholder>
337+
</component>
338+
</card>
306339
</config>

src/Resources/config/services.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,16 @@
202202
<service id="Omikron\FactFinder\Shopware6\Utilites\Ssr\Template\Engine" />
203203
<service id="Omikron\FactFinder\Shopware6\Config\FieldRolesInterface"
204204
alias="Omikron\FactFinder\Shopware6\Config\FieldRoles" />
205+
206+
<service id="Omikron\FactFinder\Shopware6\ScheduledTask\ExportScheduledTask">
207+
<tag name="shopware.scheduled.task" />
208+
</service>
209+
<service id="Omikron\FactFinder\Shopware6\ScheduledTask\ExportScheduledTaskHandler">
210+
<argument type="service" id="scheduled_task.repository"/>
211+
<argument type="service" id="monolog.logger.factfinder_channel"/>
212+
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService" />
213+
<argument type="service" id="Omikron\FactFinder\Shopware6\MessageQueue\FeedExportHandler" />
214+
<tag name="messenger.message_handler" />
215+
</service>
205216
</services>
206217
</container>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Omikron\FactFinder\Shopware6\ScheduledTask;
6+
7+
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTask;
8+
9+
class ExportScheduledTask extends ScheduledTask
10+
{
11+
public static function getTaskName(): string
12+
{
13+
return 'factfinder.auto_export_task';
14+
}
15+
16+
public static function getDefaultInterval(): int
17+
{
18+
// change this value to adjust the export interval. This value is in seconds.
19+
// For example, to set the interval to 48 hours = 172800
20+
return 172800;
21+
}
22+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Omikron\FactFinder\Shopware6\ScheduledTask;
6+
7+
use Omikron\FactFinder\Shopware6\Message\FeedExport;
8+
use Omikron\FactFinder\Shopware6\MessageQueue\FeedExportHandler;
9+
use Psr\Log\LoggerInterface;
10+
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
11+
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler;
12+
use Shopware\Core\System\SystemConfig\SystemConfigService;
13+
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
14+
15+
#[AsMessageHandler(handles: ExportScheduledTask::class)]
16+
class ExportScheduledTaskHandler extends ScheduledTaskHandler
17+
{
18+
public function __construct(
19+
EntityRepository $scheduledTaskRepository,
20+
private readonly LoggerInterface $factfinderLogger,
21+
private readonly SystemConfigService $systemConfig,
22+
private readonly FeedExportHandler $feedExportHandler,
23+
) {
24+
parent::__construct($scheduledTaskRepository, $factfinderLogger);
25+
}
26+
27+
public function run(): void
28+
{
29+
$autoExportEnabled = $this->systemConfig->get('OmikronFactFinder.config.autoExportEnabled');
30+
$salesChannel = $this->systemConfig->get('OmikronFactFinder.config.autoExportSelectedSalesChannel');
31+
$language = $this->systemConfig->get('OmikronFactFinder.config.autoExportSelectedLanguage');
32+
33+
if (!$autoExportEnabled || !$salesChannel || !$language) {
34+
$this->factfinderLogger->info('FactFinder auto export is disabled or not configured properly.');
35+
36+
return;
37+
}
38+
39+
try {
40+
$this->feedExportHandler->__invoke(new FeedExport(
41+
$salesChannel,
42+
$language,
43+
'products'
44+
));
45+
} catch (\Exception $e) {
46+
$this->factfinderLogger->error($e->getMessage());
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)