connection = $connection; $this->mailer = $mailer; $this->logger = $logger; $this->configService = $configService; } public function saveNotification(string $email, string $productId): void { try { $this->connection->insert('notifyifavail_plugin_notification', [ 'id' => Uuid::randomBytes(), 'email' => $email, 'product_id' => Uuid::fromHexToBytes($productId), 'created_at' => (new \DateTime())->format('Y-m-d H:i:s'), ]); } catch (\Exception $e) { $this->logger->error('Fehler beim Speichern der Benachrichtigung: ' . $e->getMessage()); throw $e; } } public function notifyCustomers(string $productId, string $productName, string $productUrl, string $shopName): void { try { $emails = $this->connection->fetchFirstColumn( "SELECT email FROM notifyifavail_plugin_notification WHERE product_id = :productId", ['productId' => Uuid::fromHexToBytes($productId)] ); $emailSender = $this->configService->get('NotifyIfAvail.config.emailSender') ?? 'shop@example.com'; $emailSubject = $this->configService->get('NotifyIfAvail.config.emailSubject') ?? 'Ihr gewünschter Artikel ist wieder verfügbar!'; foreach ($emails as $email) { $message = (new Email()) ->from($emailSender) ->to($email) ->subject($emailSubject) ->html("
Hallo,
Sie haben sich für eine Benachrichtigung angemeldet, sobald der folgende Artikel wieder verfügbar ist:
{$productName}
Vielen Dank für Ihr Interesse an unseren Produkten!
Beste Grüße,
{$shopName}-Team