This commit is contained in:
parent
5d9db25d73
commit
2747d53c50
2
.env
2
.env
@ -15,7 +15,7 @@
|
||||
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
APP_ENV=dev
|
||||
APP_ENV=prod
|
||||
APP_SECRET=e5a2fe31ff8ce325266d52632a0ba5df
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
98
tests/Helper/HiltesImportTest.php
Normal file
98
tests/Helper/HiltesImportTest.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Helper;
|
||||
|
||||
use App\Entity\Product;
|
||||
use App\Entity\Stock;
|
||||
use App\Entity\Warehouse;
|
||||
use App\Helper\HiltesImport;
|
||||
use App\Repository\ProductRepository;
|
||||
use App\Repository\StockRepository;
|
||||
use App\Repository\WarehouseRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class HiltesImportTest extends TestCase
|
||||
{
|
||||
private $productRepository;
|
||||
private $warehouseRepository;
|
||||
private $stockRepository;
|
||||
private $logger;
|
||||
private $rootPath;
|
||||
private $hiltesImport;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->productRepository = $this->createMock(ProductRepository::class);
|
||||
$this->warehouseRepository = $this->createMock(WarehouseRepository::class);
|
||||
$this->stockRepository = $this->createMock(StockRepository::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->rootPath = '/';
|
||||
|
||||
$this->hiltesImport = new HiltesImport(
|
||||
$this->productRepository,
|
||||
$this->warehouseRepository,
|
||||
$this->stockRepository,
|
||||
$this->logger,
|
||||
$this->rootPath
|
||||
);
|
||||
}
|
||||
|
||||
public function testStartImportWithNoFiles()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('No Files to Import');
|
||||
|
||||
$this->hiltesImport->startImport();
|
||||
}
|
||||
|
||||
public function testStartImportWithFiles()
|
||||
{
|
||||
// Mock the getFiles method to return true
|
||||
$hiltesImport = $this->getMockBuilder(HiltesImport::class)
|
||||
->setConstructorArgs([
|
||||
$this->productRepository,
|
||||
$this->warehouseRepository,
|
||||
$this->stockRepository,
|
||||
$this->logger,
|
||||
$this->rootPath
|
||||
])
|
||||
->onlyMethods(['getFiles'])
|
||||
->getMock();
|
||||
|
||||
$hiltesImport->method('getFiles')->willReturn(true);
|
||||
|
||||
$this->assertNull($hiltesImport->startImport());
|
||||
}
|
||||
|
||||
public function testGetFilesWithNoResults()
|
||||
{
|
||||
$this->assertFalse($this->hiltesImport->getFiles());
|
||||
}
|
||||
|
||||
public function testSaveDataWithNoWarehouse()
|
||||
{
|
||||
$this->logger->expects($this->once())
|
||||
->method('error')
|
||||
->with('No Warehouse');
|
||||
|
||||
$this->assertFalse($this->hiltesImport->saveData(['product1', '100']));
|
||||
}
|
||||
|
||||
public function testSaveDataWithValidData()
|
||||
{
|
||||
$warehouse = new Warehouse();
|
||||
$warehouse->setName('Warehouse1');
|
||||
|
||||
$product = new Product();
|
||||
$product->setGtin('product1');
|
||||
|
||||
$this->warehouseRepository->method('findOneBy')->willReturn($warehouse);
|
||||
$this->productRepository->method('findOneBy')->willReturn($product);
|
||||
|
||||
$this->stockRepository->expects($this->once())
|
||||
->method('save');
|
||||
|
||||
$this->assertTrue($this->hiltesImport->saveData(['product1', '100', '', 'Warehouse1']));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user