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
No known key found for this signature in database
4 changed files with 426 additions and 410 deletions

View File

@ -5,7 +5,7 @@ php_version: "8.2"
webserver_type: apache-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: false
xdebug_enabled: true
additional_hostnames: [ ]
additional_fqdns: [ ]
database:

798
composer.lock generated

File diff suppressed because it is too large Load Diff

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();
}
}

View File

@ -85,15 +85,10 @@ class Jtl
//Wenn Product nicht gefunden werden kann, dann setzte Bestand auf Null
$this->logger->info('No stock for warehouse ' . $w->getName());
}
// if ($p->getGtin() == '0193128415983') {
// dump($data[$p->getId() . $warehousesName]);
// }
}
}
}
return $data;
}