fixed slack
Some checks failed
continuous-integration/drone/push Build is failing

update composer
This commit is contained in:
Marko
2024-01-09 17:15:53 +01:00
parent 3ac3c884f0
commit bc1c6b85bc
4 changed files with 426 additions and 410 deletions

View File

@@ -27,6 +27,9 @@ class SlackNotifySubscriber implements EventSubscriberInterface
public function __construct(string $slackWebhookUrl, ProductRepository $productRepository, StockRepository $stockRepository, WarehouseRepository $warehouseRepository)
{
$this->slackWebhookUrl = $slackWebhookUrl;
$this->productRepository = $productRepository;
$this->stockRepository = $stockRepository;
$this->warehouseRepository = $warehouseRepository;
}
public static function getSubscribedEvents(): array
@@ -44,7 +47,6 @@ class SlackNotifySubscriber implements EventSubscriberInterface
public function sendSlack(ViewEvent $event): void
{
$order = $event->getControllerResult();
$method = $event->getRequest()->getMethod();
@@ -53,21 +55,20 @@ class SlackNotifySubscriber implements EventSubscriberInterface
return;
}
//if (is_array($order->getData()[0]['positions'] != null)) {
foreach ($order->getData()[0]['positions'] as $item) {
if ($item['menge'] > 0 && strlen($item['sku']) > 0) {
if ($item['menge'] > 0) {
$warehouse = $this->getWarehouseByGtin($item['sku']);
$warehouse = $this->getWarehouseByGtin($item['gtin']);
$slack = new Client($this->slackWebhookUrl, [
'username' => 'CDS-Notify',
'channel' => '#online-verkäufe' . '_' . $warehouse,
'channel' => '#online_verkäufe' . '_' . $warehouse,
'link_names' => true,
'icon' => ':robot_face:',
'allow_markdown' => true,
]);
$msg = "Bestellung {$order->getOrderId()}: \n";
$msg .= $item['name'];
$msg .= ' ' . $item['sku'];
@@ -79,19 +80,27 @@ class SlackNotifySubscriber implements EventSubscriberInterface
}
}
}
// }
}
/**
* @param string $gtin
* @return string|null
*/
private function getWarehouseByGtin(string $gtin)
{
if ($gtin == null) {
return false;
}
$product = $this->productRepository->findOneBy(['gtin' => $gtin]);
if ($product) {
$stock = $this->stockRepository->findOneBy(['product_id' => $product->getId()]);
if ($stock) {
$warehouse = $this->warehouseRepository->findOneBy(['id' => $stock->getWarehouseId()]);
$warehouse = $this->warehouseRepository->findOneBy(['id' => $stock->getWarehouse()->getId()]);
return $warehouse->getName();
}
}