This commit is contained in:
2026-04-03 22:35:49 +02:00
parent 0e7ee957cb
commit e95c4967d2
52 changed files with 7430 additions and 631 deletions

View File

@@ -7,6 +7,7 @@ use App\Core\I18n\Translator;
use App\Core\Support\Logger;
use App\Core\View\Template;
use App\Modules\Accounting\ReceiptRepository;
use App\Modules\Accounting\ReceiptService;
use App\Modules\Automation\AutomationRepository;
use App\Modules\Automation\AutomationService;
use App\Modules\Automation\AutomationExecutionLogRepository;
@@ -207,15 +208,26 @@ final class CronHandlerFactory
)
);
$receiptRepository = new ReceiptRepository($this->db);
$receiptConfigRepository = new ReceiptConfigRepository($this->db);
$receiptService = new ReceiptService(
$receiptRepository,
$receiptConfigRepository,
$companySettingsRepository,
$ordersRepository
);
return new AutomationService(
$automationRepository,
$executionLogRepository,
$emailService,
$ordersRepository,
$companySettingsRepository,
new ReceiptRepository($this->db),
new ReceiptConfigRepository($this->db),
new ShipmentPackageRepository($this->db)
$receiptRepository,
$receiptConfigRepository,
new ShipmentPackageRepository($this->db),
$receiptService
);
}
}

View File

@@ -10,6 +10,8 @@ use Throwable;
final class ShipmentTrackingHandler
{
private const ALLEGRO_EDGE_RATE_LIMIT_SECONDS = 60;
public function __construct(
private readonly ShipmentTrackingRegistry $registry,
private readonly ShipmentPackageRepository $repository,
@@ -28,6 +30,8 @@ final class ShipmentTrackingHandler
$updated = 0;
$errors = 0;
$lastAllegroEdgeRequestTime = 0.0;
foreach ($packages as $package) {
$provider = trim((string) ($package['provider'] ?? ''));
$packageId = (int) ($package['id'] ?? 0);
@@ -38,6 +42,20 @@ final class ShipmentTrackingHandler
}
try {
if ($provider === 'allegro_wza') {
$carrierId = strtolower(trim((string) ($package['carrier_id'] ?? '')));
$isInpost = str_contains($carrierId, 'inpost') || str_contains($carrierId, 'paczkomat');
if (!$isInpost) {
$elapsed = microtime(true) - $lastAllegroEdgeRequestTime;
if ($elapsed < self::ALLEGRO_EDGE_RATE_LIMIT_SECONDS) {
$sleepTime = (int) ceil(self::ALLEGRO_EDGE_RATE_LIMIT_SECONDS - $elapsed);
sleep($sleepTime);
}
$lastAllegroEdgeRequestTime = microtime(true);
}
}
$result = $service->getDeliveryStatus($package);
if ($result !== null) {
$previousStatus = trim((string) ($package['delivery_status'] ?? 'unknown'));