This commit is contained in:
Marko 2025-01-09 18:56:31 +01:00
parent c4db83daec
commit fc829ce96e
No known key found for this signature in database

View File

@ -42,6 +42,11 @@ class SlackNotifySubscriber implements EventSubscriberInterface
]; ];
} }
private function encode(string $text): string
{
return trim(html_entity_decode($text));
}
/** /**
* @param ViewEvent $event * @param ViewEvent $event
@ -49,9 +54,9 @@ class SlackNotifySubscriber implements EventSubscriberInterface
*/ */
public function sendSlack(ViewEvent $event): void public function sendSlack(ViewEvent $event): void
{ {
$order = $event->getControllerResult(); $order = $event->getControllerResult();
$method = $event->getRequest()->getMethod(); $method = $event->getRequest()->getMethod();
$slackmsg = [];
//wenn es keine Bestellung ist oder es kein POST Request ist, dann return //wenn es keine Bestellung ist oder es kein POST Request ist, dann return
if (!$order instanceof Order || Request::METHOD_POST !== $method) { if (!$order instanceof Order || Request::METHOD_POST !== $method) {
@ -64,28 +69,35 @@ class SlackNotifySubscriber implements EventSubscriberInterface
$warehouse = $this->getWarehouseByGtin($item['gtin']); $warehouse = $this->getWarehouseByGtin($item['gtin']);
if ($warehouse == false) { if (!$warehouse) {
$this->logger->error('Warehouse not found for GTIN: ' . $item['gtin']); $this->logger->error('Warehouse not found for GTIN: ' . $item['gtin']);
continue; 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 = "Bestellung {$order->getOrderId()}: \n";
$msg .= $item['marke'] . ' - '; $msg .= $this->encode($item['marke'] . ' - ');
$msg .= $item['name']; $msg .= $this->encode($item['name']);
$msg .= ' - ' . $item['han']; $msg .= $this->encode(' - ' . $item['han']);
$msg .= $this->encode(' - ' . $item['gtin']);
$msg .= ' * - ' . $item['menge'] . "* \n"; $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; return $warehouse;
} }
} }