This commit is contained in:
@@ -60,7 +60,6 @@ class HiltesImportCommand extends Command
|
||||
*/
|
||||
$hiltesImport = new HiltesImport($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $rootPath);
|
||||
|
||||
|
||||
$prodIds = $hiltesImport->startImport($delta);
|
||||
|
||||
if (isset($r['error'])) {
|
||||
|
||||
@@ -4,7 +4,9 @@ namespace App\EventSubscriber;
|
||||
|
||||
use ApiPlatform\Symfony\EventListener\EventPriorities;
|
||||
use App\Entity\Order;
|
||||
use App\Helper\Slack;
|
||||
use App\Repository\ProductRepository;
|
||||
use App\Repository\StockRepository;
|
||||
use App\Repository\WarehouseRepository;
|
||||
use Maknz\Slack\Client;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -18,8 +20,11 @@ class SlackNotifySubscriber implements EventSubscriberInterface
|
||||
* @var Slack
|
||||
*/
|
||||
private $slackWebhookUrl;
|
||||
private $productRepository;
|
||||
private $stockRepository;
|
||||
private $warehouseRepository;
|
||||
|
||||
public function __construct(string $slackWebhookUrl)
|
||||
public function __construct(string $slackWebhookUrl, ProductRepository $productRepository, StockRepository $stockRepository, WarehouseRepository $warehouseRepository)
|
||||
{
|
||||
$this->slackWebhookUrl = $slackWebhookUrl;
|
||||
}
|
||||
@@ -38,13 +43,7 @@ class SlackNotifySubscriber implements EventSubscriberInterface
|
||||
*/
|
||||
public function sendSlack(ViewEvent $event): void
|
||||
{
|
||||
$slack = new Client($this->slackWebhookUrl, [
|
||||
'username' => 'CDS-Notify',
|
||||
'channel' => '#online-verkäufe',
|
||||
'link_names' => true,
|
||||
'icon' => ':robot_face:',
|
||||
'allow_markdown' => true,
|
||||
]);
|
||||
|
||||
|
||||
$order = $event->getControllerResult();
|
||||
$method = $event->getRequest()->getMethod();
|
||||
@@ -54,19 +53,51 @@ class SlackNotifySubscriber implements EventSubscriberInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$msg = "Bestellung {$order->getOrderId()}: \n";
|
||||
|
||||
foreach ($order->getData()[0]['positions'] as $item) {
|
||||
if ($item['menge'] > 0 && strlen($item['sku']) > 0) {
|
||||
|
||||
$warehouse = $this->getWarehouseByGtin($item['sku']);
|
||||
|
||||
$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['name'];
|
||||
$msg .= ' ' . $item['sku'];
|
||||
$msg .= ' Menge: ' . $item['menge'] . "\n";
|
||||
|
||||
if ($order->getStatus() == 1) {
|
||||
$slack->from('CDS-Notify')
|
||||
->send($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($order->getStatus() == 1) {
|
||||
$slack->from('CDS-Notify')
|
||||
->send($msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getWarehouseByGtin(string $gtin)
|
||||
{
|
||||
$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()]);
|
||||
return $warehouse->getName();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,34 +69,28 @@ class Jtl
|
||||
if ($warehouse) {
|
||||
foreach ($warehouse as $w) {
|
||||
|
||||
$stock = $this->stockRepository->findBy(['warehouse' => $w]);
|
||||
$warehousesName = $w->getName();
|
||||
|
||||
if ($stock) {
|
||||
foreach ($stock as $s) {
|
||||
$warehouse = $s->getWarehouse();
|
||||
$warehouseName = $warehouse->getName();
|
||||
foreach ($products as $p) {
|
||||
$stock = $this->stockRepository->findOneBy(['product_id' => $p->getId(), 'warehouse' => $w]);
|
||||
|
||||
if (isset($products[$s->getProductId()])) {
|
||||
$data[$s->getProductId() . $warehouseName] = [
|
||||
'gtin' => $products[$s->getProductId()]->getGtin(),
|
||||
'stock' => $s->getInstock(),
|
||||
'warehouse' => $this->arrLager[$warehouseName] ?? 'Lager_' . $warehouseName,
|
||||
'lager' => '01'
|
||||
];
|
||||
|
||||
} else {
|
||||
$this->logger->info('No product for stock ' . $s->getProductId());
|
||||
}
|
||||
if ($stock) {
|
||||
$data[$p->getId() . $warehousesName] = [
|
||||
'gtin' => $p->getGtin(),
|
||||
'stock' => $stock->getInstock(),
|
||||
'warehouse' => $this->arrLager[$warehousesName] ?? 'Lager_' . $warehousesName,
|
||||
'lager' => '01'
|
||||
];
|
||||
} else {
|
||||
//Wenn Product nicht gefunden werden kann, dann setzte Bestand auf Null
|
||||
$this->logger->info('No stock for warehouse ' . $w->getName());
|
||||
}
|
||||
|
||||
if ($p->getGtin() == '0193128415976') {
|
||||
dump($data[$p->getId() . $warehousesName]);
|
||||
}
|
||||
} else {
|
||||
//Wenn Product nicht gefunden werden kann, dann setzte Bestand auf Null
|
||||
// $data[] = [
|
||||
// 'gtin' => $products[$s->getProductId()]->getGtin(),
|
||||
// 'stock' => 0,
|
||||
// 'warehouse' => 0
|
||||
// ];
|
||||
$this->logger->info('No stock for product ' . s->getProductId()->getId());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user