From 0bc202449473d1dee391f9dd9380fd2f56c5d6c2 Mon Sep 17 00:00:00 2001
From: Marko <52066939+HeX87@users.noreply.github.com>
Date: Thu, 21 Mar 2024 16:45:32 +0100
Subject: [PATCH] fix double slack notification

---
 src/EventSubscriber/SlackNotifySubscriber.php | 37 +++++++++----------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/src/EventSubscriber/SlackNotifySubscriber.php b/src/EventSubscriber/SlackNotifySubscriber.php
index fbbc548..82af665 100644
--- a/src/EventSubscriber/SlackNotifySubscriber.php
+++ b/src/EventSubscriber/SlackNotifySubscriber.php
@@ -63,32 +63,29 @@ class SlackNotifySubscriber implements EventSubscriberInterface
             foreach ($order->getData()[0]['positions'] as $item) {
                 if ($item['menge'] > 0) {
 
-                    $warehouses = $this->getWarehouseByGtin($item['gtin']);
+                    $warehouse = $this->getWarehouseByGtin($item['gtin']);
 
-                    if ($warehouses == false) {
+                    if ($warehouse == false) {
                         continue;
                     }
 
-                    foreach ($warehouses as $warehouse) {
+                    $slack = new Client($this->slackWebhookUrl, [
+                        'username' => 'CDS-Notify',
+                        'channel' => '#online_verkäufe' . '_' . $warehouse,
+                        'link_names' => true,
+                        'icon' => ':robot_face:',
+                        'allow_markdown' => true,
+                    ]);
 
-                        $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 .= ' * - ' . $item['menge'] . "* \n";
+                    $msg = "Bestellung {$order->getOrderId()}: \n";
+                    $msg .= $item['marke'] . ' - ';
+                    $msg .= $item['name'];
+                    $msg .= ' - ' . $item['han'];
+                    $msg .= ' * - ' . $item['menge'] . "* \n";
 
 
-                        $slack->from('CDS-Notify')->send($msg);
+                    $slack->from('CDS-Notify')->send($msg);
 
-                    }
                 }
             }
         }
@@ -103,7 +100,7 @@ class SlackNotifySubscriber implements EventSubscriberInterface
         if ($gtin == null) {
             return false;
         }
-        $warehouse = [];
+        $warehouse = "";
 
         $product = $this->productRepository->findOneBy(['gtin' => $gtin]);
 
@@ -116,7 +113,7 @@ class SlackNotifySubscriber implements EventSubscriberInterface
                     $w = $this->warehouseRepository->findOneBy(['id' => $item->getWarehouse()->getId()]);
 
                     if ($w->getPrio() > $prio) {
-                        $warehouse[] = $w->getName();
+                        $warehouse = $w->getName();
                         $prio = $w->getPrio();
                     }
                 }