Files
orderPRO/bin/cron.php
Jacek Pyziak 1b5e403c31 Add Allegro shipment service and related components
- Implement AllegroShipmentService for managing shipment creation and status checks.
- Create ShipmentController to handle shipment preparation and label downloading.
- Introduce ShipmentPackageRepository for database interactions related to shipment packages.
- Add methods for retrieving delivery services, creating shipments, checking creation status, and downloading labels.
- Implement address validation and token management for Allegro API integration.
2026-03-06 01:06:59 +01:00

77 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Core\Application;
use App\Modules\Cron\AllegroOrdersImportHandler;
use App\Modules\Cron\AllegroStatusSyncHandler;
use App\Modules\Cron\AllegroTokenRefreshHandler;
use App\Modules\Cron\CronRepository;
use App\Modules\Cron\CronRunner;
use App\Modules\Orders\OrderImportRepository;
use App\Modules\Orders\OrdersRepository;
use App\Modules\Settings\AllegroApiClient;
use App\Modules\Settings\AllegroIntegrationRepository;
use App\Modules\Settings\AllegroOrderImportService;
use App\Modules\Settings\AllegroOrdersSyncService;
use App\Modules\Settings\AllegroOrderSyncStateRepository;
use App\Modules\Settings\AllegroOAuthClient;
use App\Modules\Settings\AllegroStatusSyncService;
use App\Modules\Settings\AllegroStatusMappingRepository;
/** @var Application $app */
$app = require dirname(__DIR__) . '/bootstrap/app.php';
$limit = 20;
foreach (array_slice($argv, 1) as $arg) {
if (preg_match('/^--limit=(\d+)$/', (string) $arg, $matches) === 1) {
$limit = max(1, min(100, (int) ($matches[1] ?? 20)));
}
}
$cronRepository = new CronRepository($app->db());
$integrationRepository = new AllegroIntegrationRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
);
$oauthClient = new AllegroOAuthClient();
$apiClient = new AllegroApiClient();
$statusMappingRepository = new AllegroStatusMappingRepository($app->db());
$orderImportService = new AllegroOrderImportService(
$integrationRepository,
$oauthClient,
$apiClient,
new OrderImportRepository($app->db()),
$statusMappingRepository,
new OrdersRepository($app->db())
);
$ordersSyncService = new AllegroOrdersSyncService(
$integrationRepository,
new AllegroOrderSyncStateRepository($app->db()),
$oauthClient,
$apiClient,
$orderImportService
);
$runner = new CronRunner(
$cronRepository,
$app->logger(),
[
'allegro_token_refresh' => new AllegroTokenRefreshHandler(
$integrationRepository,
$oauthClient
),
'allegro_orders_import' => new AllegroOrdersImportHandler(
$ordersSyncService
),
'allegro_status_sync' => new AllegroStatusSyncHandler(
new AllegroStatusSyncService(
$cronRepository,
$ordersSyncService
)
),
]
);
$result = $runner->run($limit);
fwrite(STDOUT, json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL);