diff --git a/src/EventSubscriber/SlackNotifySubscriber.php b/src/EventSubscriber/SlackNotifySubscriber.php index a351cd5..53bab9a 100644 --- a/src/EventSubscriber/SlackNotifySubscriber.php +++ b/src/EventSubscriber/SlackNotifySubscriber.php @@ -42,6 +42,11 @@ class SlackNotifySubscriber implements EventSubscriberInterface ]; } + private function encode(string $text): string + { + return trim(html_entity_decode($text)); + } + /** * @param ViewEvent $event @@ -49,9 +54,9 @@ class SlackNotifySubscriber implements EventSubscriberInterface */ public function sendSlack(ViewEvent $event): void { - $order = $event->getControllerResult(); $method = $event->getRequest()->getMethod(); + $slackmsg = []; //wenn es keine Bestellung ist oder es kein POST Request ist, dann return if (!$order instanceof Order || Request::METHOD_POST !== $method) { @@ -64,28 +69,35 @@ class SlackNotifySubscriber implements EventSubscriberInterface $warehouse = $this->getWarehouseByGtin($item['gtin']); - if ($warehouse == false) { + if (!$warehouse) { $this->logger->error('Warehouse not found for GTIN: ' . $item['gtin']); continue; } - $slack = new Client($this->slackWebhookUrl, [ - 'username' => 'CDS-Notify', - 'channel' => '#online_verkäufe' . '_' . $warehouse, - 'link_names' => true, - 'icon' => ':robot_face:', - 'allow_markdown' => true, - ]); - $msg = "Bestellung {$order->getOrderId()}: \n"; - $msg .= $item['marke'] . ' - '; - $msg .= $item['name']; - $msg .= ' - ' . $item['han']; + $msg .= $this->encode($item['marke'] . ' - '); + $msg .= $this->encode($item['name']); + $msg .= $this->encode(' - ' . $item['han']); + $msg .= $this->encode(' - ' . $item['gtin']); $msg .= ' * - ' . $item['menge'] . "* \n"; - $slack->from('CDS-Notify')->send($msg); + $slackmsg[$warehouse] .= $msg; } } + + foreach ($slackmsg as $key => $value) { + sleep(1); + + $slack = new Client($this->slackWebhookUrl, [ + 'username' => 'CDS-Notify', + 'channel' => '#online_verkäufe' . '_' . $key, + 'link_names' => true, + 'icon' => ':robot_face:', + 'allow_markdown' => true, + ]); + + $slack->from('CDS-Notify')->send($value); + } } } @@ -120,8 +132,6 @@ class SlackNotifySubscriber implements EventSubscriberInterface } } } - return $warehouse; - } } \ No newline at end of file