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
|
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
|
||||||
|
|
||||||
###> symfony/framework-bundle ###
|
###> symfony/framework-bundle ###
|
||||||
APP_ENV=dev
|
APP_ENV=prod
|
||||||
APP_SECRET=e5a2fe31ff8ce325266d52632a0ba5df
|
APP_SECRET=e5a2fe31ff8ce325266d52632a0ba5df
|
||||||
###< symfony/framework-bundle ###
|
###< symfony/framework-bundle ###
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ class HiltesImportCommand extends Command
|
|||||||
*/
|
*/
|
||||||
$hiltesImport = new HiltesImport($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $rootPath);
|
$hiltesImport = new HiltesImport($this->productRepository, $this->warehouseRepository, $this->stockRepository, $this->logger, $rootPath);
|
||||||
|
|
||||||
|
|
||||||
$prodIds = $hiltesImport->startImport($delta);
|
$prodIds = $hiltesImport->startImport($delta);
|
||||||
|
|
||||||
if (isset($r['error'])) {
|
if (isset($r['error'])) {
|
||||||
|
@ -4,7 +4,9 @@ namespace App\EventSubscriber;
|
|||||||
|
|
||||||
use ApiPlatform\Symfony\EventListener\EventPriorities;
|
use ApiPlatform\Symfony\EventListener\EventPriorities;
|
||||||
use App\Entity\Order;
|
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 Maknz\Slack\Client;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -18,8 +20,11 @@ class SlackNotifySubscriber implements EventSubscriberInterface
|
|||||||
* @var Slack
|
* @var Slack
|
||||||
*/
|
*/
|
||||||
private $slackWebhookUrl;
|
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;
|
$this->slackWebhookUrl = $slackWebhookUrl;
|
||||||
}
|
}
|
||||||
@ -38,13 +43,7 @@ class SlackNotifySubscriber implements EventSubscriberInterface
|
|||||||
*/
|
*/
|
||||||
public function sendSlack(ViewEvent $event): void
|
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();
|
$order = $event->getControllerResult();
|
||||||
$method = $event->getRequest()->getMethod();
|
$method = $event->getRequest()->getMethod();
|
||||||
@ -54,15 +53,25 @@ class SlackNotifySubscriber implements EventSubscriberInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg = "Bestellung {$order->getOrderId()}: \n";
|
|
||||||
|
|
||||||
foreach ($order->getData()[0]['positions'] as $item) {
|
foreach ($order->getData()[0]['positions'] as $item) {
|
||||||
if ($item['menge'] > 0 && strlen($item['sku']) > 0) {
|
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['name'];
|
||||||
$msg .= ' ' . $item['sku'];
|
$msg .= ' ' . $item['sku'];
|
||||||
$msg .= ' Menge: ' . $item['menge'] . "\n";
|
$msg .= ' Menge: ' . $item['menge'] . "\n";
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($order->getStatus() == 1) {
|
if ($order->getStatus() == 1) {
|
||||||
$slack->from('CDS-Notify')
|
$slack->from('CDS-Notify')
|
||||||
@ -70,3 +79,25 @@ class SlackNotifySubscriber implements EventSubscriberInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
if ($warehouse) {
|
||||||
foreach ($warehouse as $w) {
|
foreach ($warehouse as $w) {
|
||||||
|
|
||||||
$stock = $this->stockRepository->findBy(['warehouse' => $w]);
|
$warehousesName = $w->getName();
|
||||||
|
|
||||||
|
foreach ($products as $p) {
|
||||||
|
$stock = $this->stockRepository->findOneBy(['product_id' => $p->getId(), 'warehouse' => $w]);
|
||||||
|
|
||||||
if ($stock) {
|
if ($stock) {
|
||||||
foreach ($stock as $s) {
|
$data[$p->getId() . $warehousesName] = [
|
||||||
$warehouse = $s->getWarehouse();
|
'gtin' => $p->getGtin(),
|
||||||
$warehouseName = $warehouse->getName();
|
'stock' => $stock->getInstock(),
|
||||||
|
'warehouse' => $this->arrLager[$warehousesName] ?? 'Lager_' . $warehousesName,
|
||||||
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'
|
'lager' => '01'
|
||||||
];
|
];
|
||||||
|
|
||||||
} else {
|
|
||||||
$this->logger->info('No product for stock ' . $s->getProductId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//Wenn Product nicht gefunden werden kann, dann setzte Bestand auf Null
|
//Wenn Product nicht gefunden werden kann, dann setzte Bestand auf Null
|
||||||
// $data[] = [
|
$this->logger->info('No stock for warehouse ' . $w->getName());
|
||||||
// 'gtin' => $products[$s->getProductId()]->getGtin(),
|
|
||||||
// 'stock' => 0,
|
|
||||||
// 'warehouse' => 0
|
|
||||||
// ];
|
|
||||||
$this->logger->info('No stock for product ' . s->getProductId()->getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($p->getGtin() == '0193128415976') {
|
||||||
|
dump($data[$p->getId() . $warehousesName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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