fixes
This commit is contained in:
parent
c4db83daec
commit
fc829ce96e
@ -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,27 +69,34 @@ 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;
|
||||
}
|
||||
|
||||
$msg = "Bestellung {$order->getOrderId()}: \n";
|
||||
$msg .= $this->encode($item['marke'] . ' - ');
|
||||
$msg .= $this->encode($item['name']);
|
||||
$msg .= $this->encode(' - ' . $item['han']);
|
||||
$msg .= $this->encode(' - ' . $item['gtin']);
|
||||
$msg .= ' * - ' . $item['menge'] . "* \n";
|
||||
|
||||
$slackmsg[$warehouse] .= $msg;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($slackmsg as $key => $value) {
|
||||
sleep(1);
|
||||
|
||||
$slack = new Client($this->slackWebhookUrl, [
|
||||
'username' => 'CDS-Notify',
|
||||
'channel' => '#online_verkäufe' . '_' . $warehouse,
|
||||
'channel' => '#online_verkäufe' . '_' . $key,
|
||||
'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";
|
||||
|
||||
$slack->from('CDS-Notify')->send($msg);
|
||||
}
|
||||
$slack->from('CDS-Notify')->send($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,8 +132,6 @@ class SlackNotifySubscriber implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $warehouse;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user