# Conflicts:
#	.env
This commit is contained in:
dotworker 2023-01-05 10:55:01 +01:00
commit cd71e7a2fe
34 changed files with 24909 additions and 297 deletions

25
.drone.yml Normal file
View File

@ -0,0 +1,25 @@
kind: pipeline
name: default
steps:
- name: install
image: composer
commands:
- composer install
- name: cleanup
image: php:8.1
commands:
- apt-get update && apt-get install -y git zip
- curl -L https://phar.phpunit.de/phpunit.phar -o /usr/local/bin/phpunit
- curl -L https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -o /usr/local/bin/phpcs
- curl -L https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar -o /usr/local/bin/phpcbf
- chmod +x /usr/local/bin/phpunit
- chmod +x /usr/local/bin/phpcs
- chmod +x /usr/local/bin/phpcbf
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- phpcs -d memory_limit=512M --extensions=php --standard=PSR2 ./src/
- name: test
image: php:8.1
commands:
- vendor/bin/phpunit

6
.env
View File

@ -9,6 +9,7 @@
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
@ -30,3 +31,8 @@ DATABASE_URL="mysql://root:geheim@127.0.0.1:3306/cds_connector?serverVersion=5.7
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###
SHOPWARE_API_URL="development.dev.localhost"
SHOPWARE_API_KEY="S2hySDNyZ214dGRVQmFBSURQbkRvajIyZldxOHB4RktZakxaYmo"
SHOPWARE_API_ID="SWUAB1JGAFHTMME5DUGWDWN1EQ"

6
.env.test Normal file
View File

@ -0,0 +1,6 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots

10
.idea/phpunit.xml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PHPUnit">
<option name="directories">
<list>
<option value="$PROJECT_DIR$/tests" />
</list>
</option>
</component>
</project>

View File

@ -1,3 +1,5 @@
[![Build Status](https://ci.basehosts.de/api/badges/OrangeJungle/CdsConnector/status.svg)](https://ci.basehosts.de/OrangeJungle/CdsConnector)
# CdsConnector
================
@ -14,5 +16,5 @@ Installiere Abhängigkeiten
> make install
Starte MySQL-Server:
> docker compose up
> docker compose up

View File

@ -15,11 +15,14 @@
"nelmio/cors-bundle": "^2.2",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.6",
"sensio/framework-extra-bundle": "^6.2",
"symfony/asset": "6.1.*",
"symfony/console": "6.1.*",
"symfony/dotenv": "6.1.*",
"symfony/expression-language": "6.1.*",
"symfony/filesystem": "6.1.*",
"symfony/flex": "^2",
"symfony/form": "6.1.*",
"symfony/framework-bundle": "6.1.*",
"symfony/property-access": "6.1.*",
"symfony/property-info": "6.1.*",
@ -29,12 +32,17 @@
"symfony/serializer": "6.1.*",
"symfony/twig-bundle": "6.1.*",
"symfony/validator": "6.1.*",
"symfony/yaml": "6.1.*"
"symfony/yaml": "6.1.*",
"vin-sw/shopware-sdk": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "6.1.*",
"symfony/css-selector": "6.1.*",
"symfony/debug-bundle": "6.1.*",
"symfony/maker-bundle": "^1.43",
"symfony/monolog-bundle": "^3.0",
"symfony/phpunit-bridge": "^6.1",
"symfony/stopwatch": "6.1.*",
"symfony/web-profiler-bundle": "6.1.*"
},

3465
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,4 +12,5 @@ return [
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
];

View File

@ -1,6 +1,9 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: '%env(APP_SECRET)%'
# SHOPWARE_API_URL: '%env(string:SHOPWARE_API_URL)%'
# SHOPWARE_API_KEY: '%env(string:SHOPWARE_API_KEY)%'
# SHOPWARE_API_ID: '%env(string:SHOPWARE_API_ID)%'
#csrf_protection: true
http_method_override: false

View File

@ -0,0 +1,3 @@
sensio_framework_extra:
router:
annotations: false

View File

@ -4,6 +4,15 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
# the secret key used to generate tokens
# you should change it to a secret key that is not public
# see https://symfony.com/doc/current/security/token_storage.html#secrets-in-symfony-secrets-v3
# the url of the shopware api
SHOPWARE_API_URL: '%env(SHOPWARE_API_URL)%'
# the api key of the shopware api
SHOPWARE_API_KEY: '%env(SHOPWARE_API_KEY)%'
# the api id of the shopware api
SHOPWARE_API_ID: '%env(SHOPWARE_API_ID)%'
services:
# default configuration for services in *this* file

21
deploy.yaml Normal file
View File

@ -0,0 +1,21 @@
import:
- recipe/symfony.php
config:
repository: 'https://mmoeller:Linchen90@gitbase.de/OrangeJungle/CdsConnector.git'
hosts:
192.168.178.95:
alias: 'staging'
remote_user: pi
deploy_path: '~/CdsConnector'
tasks:
build:
- cd: '{{release_path}}'
- run: 'composer install'
after:
deploy:failed: deploy:unlock

1
hiltes/c2h/WU040801.0001 Normal file
View File

@ -0,0 +1 @@
Test

20661
hiltes/h2c/WS000001.0000 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@ final class Version20220622115500 extends AbstractMigration
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE orders (id INT AUTO_INCREMENT NOT NULL, order_id VARCHAR(255) NOT NULL, status INT NOT NULL, data JSON NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE orders (id INT AUTO_INCREMENT NOT NULL, order_id VARCHAR(255) NOT NULL, status INT NULL, data JSON NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
}
public function down(Schema $schema): void

View File

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220630134334 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE stock (id INT AUTO_INCREMENT NOT NULL, warehouse_id_id INT DEFAULT NULL, product_id VARCHAR(255) NOT NULL, stock INT NOT NULL, update_time DATETIME DEFAULT NULL, INDEX IDX_4B365660FE25E29A (warehouse_id_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE warehouse (id INT AUTO_INCREMENT NOT NULL, priority INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE stock ADD CONSTRAINT FK_4B365660FE25E29A FOREIGN KEY (warehouse_id_id) REFERENCES warehouse (id)');
$this->addSql('ALTER TABLE orders CHANGE status status INT NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE stock DROP FOREIGN KEY FK_4B365660FE25E29A');
$this->addSql('DROP TABLE stock');
$this->addSql('DROP TABLE warehouse');
$this->addSql('ALTER TABLE orders CHANGE status status INT DEFAULT NULL');
}
}

42
phpunit.xml.dist Normal file
View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
convertDeprecationsToExceptions="false"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<!-- Run `composer require symfony/panther` before enabling this extension -->
<!--
<extensions>
<extension class="Symfony\Component\Panther\ServerExtension" />
</extensions>
-->
</phpunit>

View File

@ -0,0 +1,52 @@
<?php
namespace App\Command;
use App\Repository\OrdersRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use App\Helper\Hiltes;
#[AsCommand(
name: 'hiltes:export',
description: 'Erstellt die Hiltes-Exportdatei aus den aktuellen Bestelldaten',
)]
class HiltesExportCommand extends Command
{
public function __construct(OrdersRepository $ordersRepository, LoggerInterface $logger)
{
$this->ordersRepository = $ordersRepository;
$this->logger = $logger;
parent::__construct();
}
protected function configure(): void
{
$this
->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$hiltes = new Hiltes();
$hiltes->export('Test');
$io->success('Done!');
return Command::SUCCESS;
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'hiltes:import',
description: 'Add a short description for your command',
)]
class HiltesImportCommand extends Command
{
protected function configure(): void
{
$this
->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$arg1 = $input->getArgument('arg1');
if ($arg1) {
$io->note(sprintf('You passed an argument: %s', $arg1));
}
if ($input->getOption('option1')) {
// ...
}
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
return Command::SUCCESS;
}
}

View File

@ -0,0 +1,151 @@
<?php
namespace App\Command;
use App\Controller\ShopwareController;
use App\Entity\Orders;
use App\Repository\OrdersRepository;
use Doctrine\ORM\Mapping as ORM;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Vin\ShopwareSdk\Client\AdminAuthenticator;
use Vin\ShopwareSdk\Client\GrantType\ClientCredentialsGrantType;
use Vin\ShopwareSdk\Data\Context;
use Vin\ShopwareSdk\Data\Criteria;
use Vin\ShopwareSdk\Data\Entity\EntityCollection;
use Vin\ShopwareSdk\Data\Entity\Order\OrderDefinition;
use Vin\ShopwareSdk\Data\Filter\EqualsAnyFilter;
use Vin\ShopwareSdk\Data\Filter\EqualsFilter;
use Vin\ShopwareSdk\Factory\RepositoryFactory;
#[AsCommand(
name: 'sw:get-orders',
description: 'Holt alle offenen Bestellungen von Shopware ab',
)]
class SwGetOrdersCommand extends Command
{
private $ordersRepository;
private $logger;
private $orderData;
public function __construct(OrdersRepository $ordersRepository, LoggerInterface $logger)
{
$this->ordersRepository = $ordersRepository;
$this->logger = $logger;
parent::__construct();
}
protected function configure(): void
{
// $this
// ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
// ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
// ;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
// $arg1 = $input->getArgument('arg1');
//
// if ($arg1) {
// $io->note(sprintf('You passed an argument: %s', $arg1));
// }
//
// if ($input->getOption('option1')) {
// // ...
// }
//offene Bestellungen aus Datenbank holen
$this->orderData = $this->getOrders();
$this->getOrderDetails();
$io->success('Done!');
return Command::SUCCESS;
}
/**
* @return array
*/
private function getOrders():array
{
return $this->ordersRepository->findAll();
}
/**
* @return void
*/
public function getOrderDetails(): void
{
//Bestelldetails aus SW holen
$this->getOrdersDataFromSW();
foreach ($this->orderData as $order) {
$this->saveOrdersData($order);
}
}
/**
* @return \Vin\ShopwareSdk\Data\AccessToken|void
*/
private function shopwareAuth()
{
try {
$grantType = new ClientCredentialsGrantType($_ENV['SHOPWARE_API_ID'], $_ENV['SHOPWARE_API_KEY']);
$adminClient = new AdminAuthenticator($grantType, $_ENV['SHOPWARE_API_URL']);
return $adminClient->fetchAccessToken();
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
}
/**
* holt alle fehlende Bestelldetails aus SW
*/
private function getOrdersDataFromSW(): void
{
foreach ($this->orderData as $value) {
// Bei Shopware API anmelden
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
// Create the repository for the entity
$orderRepository = RepositoryFactory::create(OrderDefinition::ENTITY_NAME);
// Create the criteria
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('id', $value->getOrderId()));
//Beziehungen zu Produkten holen
$criteria->addAssociation('lineItems');
try {
$orders = $orderRepository->search($criteria, $context);
$value->setData((array)$orders->getEntities());
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
}
}
/**
* @param $orderData
* @return void
*/
private function saveOrdersData($orderData): void
{
$orderData->setStatus = 1;
$this->ordersRepository->add($orderData, true);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace App\Controller;
use App\Entity\Orders;
use App\Form\OrdersType;
use App\Repository\OrdersRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Psr\Log\LoggerInterface;
#[Route('/orders')]
class OrdersController extends AbstractController
{
private $logger;
private $ordersRepository;
public function index(
OrdersRepository $ordersRepository,
LoggerInterface $logger
)
{
$this->logger = $logger;
$this->ordersRepository = $ordersRepository;
}
public function getOrders(): Orders
{
$this->logger->info('I just got the logger');
$orders = $this->ordersRepository->findAll();
return $orders->getData();
}
}

View File

@ -2,13 +2,18 @@
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use App\Repository\OrdersRepository;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
#[ORM\Entity(repositoryClass: OrdersRepository::class)]
#[ApiResource(itemOperations: ["GET"])]
#[ORM\HasLifecycleCallbacks]
#[ApiResource(
description: "Manage orders",
itemOperations: ["GET"],
normalizationContext: ["groups" => "read"]
)]
class Orders
{
#[ORM\Id]
@ -19,12 +24,16 @@ class Orders
/** Shopware Order ID */
#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
#[ApiProperty(example: "467e9804347c4071942c99b55b108142")]
#[Group("read")]
private $order_id;
#[ORM\Column(type: 'integer')]
#[ApiProperty(example: "1")]
private $status;
#[ORM\Column(type: 'json')]
#[ApiProperty(writable: false)]
private $data = [];
public function getId(): ?int
@ -40,7 +49,6 @@ class Orders
public function setOrderId(string $order_id): self
{
$this->order_id = $order_id;
return $this;
}
@ -52,7 +60,6 @@ class Orders
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
@ -61,10 +68,11 @@ class Orders
return $this->data;
}
public function setData(array $data): self
#[ORM\PrePersist]
public function setData(array $data): self
{
$this->data = $data;
return $this;
}
}

80
src/Entity/Stock.php Normal file
View File

@ -0,0 +1,80 @@
<?php
namespace App\Entity;
use App\Repository\StockRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: StockRepository::class)]
class Stock
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $product_id;
#[ORM\Column(type: 'integer')]
private $stock;
#[ORM\Column(type: 'datetime', nullable: true)]
private $update_time;
#[ORM\ManyToOne(targetEntity: Warehouse::class, inversedBy: 'warehouse_id')]
private $warehouse_id;
public function getId(): ?int
{
return $this->id;
}
public function getProductId(): ?string
{
return $this->product_id;
}
public function setProductId(string $product_id): self
{
$this->product_id = $product_id;
return $this;
}
public function getStock(): ?int
{
return $this->stock;
}
public function setStock(int $stock): self
{
$this->stock = $stock;
return $this;
}
public function getUpdateTime(): ?\DateTimeInterface
{
return $this->update_time;
}
public function setUpdateTime(?\DateTimeInterface $update_time): self
{
$this->update_time = $update_time;
return $this;
}
public function getWarehouseId(): ?Warehouse
{
return $this->warehouse_id;
}
public function setWarehouseId(?Warehouse $warehouse_id): self
{
$this->warehouse_id = $warehouse_id;
return $this;
}
}

74
src/Entity/Warehouse.php Normal file
View File

@ -0,0 +1,74 @@
<?php
namespace App\Entity;
use App\Repository\WarehouseRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: WarehouseRepository::class)]
class Warehouse
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\OneToMany(mappedBy: 'warehouse_id', targetEntity: Stock::class)]
private $warehouse_id;
#[ORM\Column(type: 'integer')]
private $priority;
public function __construct()
{
$this->warehouse_id = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, Stock>
*/
public function getWarehouseId(): Collection
{
return $this->warehouse_id;
}
public function addWarehouseId(Stock $warehouseId): self
{
if (!$this->warehouse_id->contains($warehouseId)) {
$this->warehouse_id[] = $warehouseId;
$warehouseId->setWarehouseId($this);
}
return $this;
}
public function removeWarehouseId(Stock $warehouseId): self
{
if ($this->warehouse_id->removeElement($warehouseId)) {
// set the owning side to null (unless already changed)
if ($warehouseId->getWarehouseId() === $this) {
$warehouseId->setWarehouseId(null);
}
}
return $this;
}
public function getPriority(): ?int
{
return $this->priority;
}
public function setPriority(int $priority): self
{
$this->priority = $priority;
return $this;
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\EventSubscriber;
use ApiPlatform\Core\EventListener\EventPriorities;
use App\Command\SwGetOrdersCommand;
use App\Entity\Orders;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;
final class OrdersSubscriber implements EventSubscriberInterface
{
private LoggerInterface $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* @return array[]
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::VIEW => ['getShopwareOrder', EventPriorities::POST_WRITE],
];
}
/**
* @param ViewEvent $event
* @return void
*/
public function getShopwareOrder(ViewEvent $event): void
{
$data = $event->getControllerResult();
$method = $event->getRequest()->getMethod();
$this->logger->info('hier');
}
}

27
src/Form/OrdersType.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace App\Form;
use App\Entity\Orders;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class OrdersType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('order_id')
->add('status')
->add('data')
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Orders::class,
]);
}
}

62
src/Helper/Hiltes.php Normal file
View File

@ -0,0 +1,62 @@
<?php
namespace App\Helper;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;
class Hiltes
{
// init file system
protected $fsObject;
protected $current_dir_path;
public function __construct()
{
$this->fsObject = new Filesystem();
$this->current_dir_path = getcwd();
}
/**
* Aufbau des Dateinamens:
* WU + Datum(TTMM) + Fortlaufendenummer (x2) + . +Filialnummer(x4)
* Beispieldateiname : WU220401.0001
*/
public function createFileName() :String
{
$date = date('dm');
$number = '01';
$filial = '0001';
return 'WU'.$date.$number.'.'.$filial;
}
public function import()
{
}
/**
* @param string $data
* @return void
*/
public function export(string $data)
{
try {
$new_file_path = $this->current_dir_path . "/hiltes/c2h/".$this->createFileName();
if (!$this->fsObject->exists($new_file_path))
{
$this->fsObject->touch($new_file_path);
$this->fsObject->chmod($new_file_path, 0777);
$this->fsObject->dumpFile($new_file_path, $data);
}
} catch (IOExceptionInterface $exception) {
echo "Error creating file at". $exception->getPath();
}
}
}

View File

@ -5,6 +5,7 @@ namespace App\Repository;
use App\Entity\Orders;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* @extends ServiceEntityRepository<Orders>
@ -16,13 +17,27 @@ use Doctrine\Persistence\ManagerRegistry;
*/
class OrdersRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
private ValidatorInterface $validator;
public function __construct(ManagerRegistry $registry, ValidatorInterface $validator)
{
parent::__construct($registry, Orders::class);
$this->validator = $validator;
}
/**
* @param Orders $entity
* @param bool $flush
* @return void
*/
public function add(Orders $entity, bool $flush = false): void
{
$errors = $this->validator->validate($entity);
if (count($errors) > 0) {
var_dump($errors);
}
$this->getEntityManager()->persist($entity);
if ($flush) {
@ -30,6 +45,25 @@ class OrdersRepository extends ServiceEntityRepository
}
}
/**
* @param Orders $entity
* @param bool $flush
* @return void
*/
public function update(Orders $entity, bool $flush = false): void
{
$order = $this->getEntityManager()->find(Orders::class, $entity->getId());
if (!$order) {
throw $this->createNotFoundException('Order not found: '.$entity->getId());
}
}
/**
* @param Orders $entity
* @param bool $flush
* @return void
*/
public function remove(Orders $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
@ -39,28 +73,33 @@ class OrdersRepository extends ServiceEntityRepository
}
}
// /**
// * @return Orders[] Returns an array of Orders objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('o')
// ->andWhere('o.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('o.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
/**
* @return Orders[] Returns an array of Orders objects
*/
public function findByStatus($status): array
{
return $this->createQueryBuilder('o')
->andWhere('o.status = :val')
->setParameter('val', $status)
->orderBy('o.id', 'ASC')
->setMaxResults(100)
->getQuery()
->getResult()
;
}
// public function findOneBySomeField($value): ?Orders
// {
// return $this->createQueryBuilder('o')
// ->andWhere('o.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
/**
* @param $orderId
* @return Orders|null
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByOrderId($orderId): ?Orders
{
return $this->createQueryBuilder('o')
->andWhere('o.order_id = :val')
->setParameter('val', $orderId)
->getQuery()
->getOneOrNullResult()
;
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Stock;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Stock>
*
* @method Stock|null find($id, $lockMode = null, $lockVersion = null)
* @method Stock|null findOneBy(array $criteria, array $orderBy = null)
* @method Stock[] findAll()
* @method Stock[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class StockRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Stock::class);
}
public function add(Stock $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Stock $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Stock[] Returns an array of Stock objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Stock
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Warehouse;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Warehouse>
*
* @method Warehouse|null find($id, $lockMode = null, $lockVersion = null)
* @method Warehouse|null findOneBy(array $criteria, array $orderBy = null)
* @method Warehouse[] findAll()
* @method Warehouse[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class WarehouseRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Warehouse::class);
}
public function add(Warehouse $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Warehouse $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Warehouse[] Returns an array of Warehouse objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('w.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Warehouse
// {
// return $this->createQueryBuilder('w')
// ->andWhere('w.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -61,6 +61,32 @@
"config/packages/nelmio_cors.yaml"
]
},
"phpunit/phpunit": {
"version": "9.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "9.3",
"ref": "a6249a6c4392e9169b87abf93225f7f9f59025e6"
},
"files": [
".env.test",
"phpunit.xml.dist",
"tests/bootstrap.php"
]
},
"sensio/framework-extra-bundle": {
"version": "6.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "5.2",
"ref": "fb7e19da7f013d0d422fa9bce16f5c510e27609b"
},
"files": [
"config/packages/sensio_framework_extra.yaml"
]
},
"symfony/console": {
"version": "6.1",
"recipe": {
@ -91,7 +117,7 @@
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "c0eeb50665f0f77226616b6038a9b06c03752d8e"
"ref": "146251ae39e06a95be0fe3d13c807bcf3938b172"
},
"files": [
".env"
@ -137,6 +163,21 @@
"config/packages/monolog.yaml"
]
},
"symfony/phpunit-bridge": {
"version": "6.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "5.3",
"ref": "97cb3dc7b0f39c7cfc4b7553504c9d7b7795de96"
},
"files": [
".env.test",
"bin/phpunit",
"phpunit.xml.dist",
"tests/bootstrap.php"
]
},
"symfony/routing": {
"version": "6.1",
"recipe": {

16
tests/OrdersTest.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace App\Tests;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
class OrdersTest extends ApiTestCase
{
public function testSomething(): void
{
$response = static::createClient()->request('GET', '/');
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['@id' => '/']);
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Tests\Shopware;
use PHPUnit\Framework\TestCase;
class OrdersTest extends TestCase
{
public function testSomething(): void
{
$this->assertTrue(true);
}
}

11
tests/bootstrap.php Normal file
View File

@ -0,0 +1,11 @@
<?php
use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__).'/vendor/autoload.php';
if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) {
require dirname(__DIR__).'/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
}