Add Stock & Warehouse

This commit is contained in:
Marko 2022-07-01 15:31:34 +02:00
parent 460411ab43
commit a2ef85c188
9 changed files with 486 additions and 23 deletions

View File

@ -2,7 +2,7 @@
<project version="4">
<component name="DBNavigator.Project.DataEditorManager">
<record-view-column-sorting-type value="BY_INDEX" />
<value-preview-text-wrapping value="true" />
<value-preview-text-wrapping value="false" />
<value-preview-pinned value="false" />
</component>
<component name="DBNavigator.Project.DataExportManager">
@ -27,9 +27,17 @@
<show-object-properties value="true" />
<loaded-nodes />
</component>
<component name="DBNavigator.Project.DatabaseConsoleManager">
<connection id="1831174e-679a-4b20-bd4b-18a5044d813c">
<console name="Connection" type="STANDARD" schema="" session="Main" />
</connection>
</component>
<component name="DBNavigator.Project.DatabaseFileManager">
<open-files />
</component>
<component name="DBNavigator.Project.DatabaseSessionManager">
<connection id="1831174e-679a-4b20-bd4b-18a5044d813c" />
</component>
<component name="DBNavigator.Project.EditorStateManager">
<last-used-providers />
</component>
@ -58,7 +66,92 @@
<recently-used-interfaces />
</component>
<component name="DBNavigator.Project.Settings">
<connections />
<connections>
<connection id="1831174e-679a-4b20-bd4b-18a5044d813c" active="true" signed="true">
<database>
<name value="Connection" />
<description value="" />
<database-type value="MYSQL" />
<config-type value="BASIC" />
<database-version value="9999.0" />
<driver-source value="BUILTIN" />
<driver-library value="C:\Program Files\HeidiSQL" />
<driver value="" />
<url-type value="DATABASE" />
<host value="127.0.0.1" />
<port value="3306" />
<database value="cds_connector" />
<type value="USER_PASSWORD" />
<user value="root" />
<deprecated-pwd value="cm9vdA==" />
</database>
<properties>
<auto-commit value="false" />
</properties>
<ssh-settings>
<active value="false" />
<proxy-host value="" />
<proxy-port value="22" />
<proxy-user value="" />
<deprecated-proxy-pwd value="" />
<auth-type value="PASSWORD" />
<key-file value="" />
<key-passphrase value="" />
</ssh-settings>
<ssl-settings>
<active value="false" />
<certificate-authority-file value="" />
<client-certificate-file value="" />
<client-key-file value="" />
</ssl-settings>
<details>
<charset value="UTF-8" />
<session-management value="true" />
<ddl-file-binding value="true" />
<database-logging value="true" />
<connect-automatically value="true" />
<restore-workspace value="true" />
<restore-workspace-deep value="false" />
<environment-type value="default" />
<connectivity-timeout value="5" />
<idle-time-to-disconnect value="30" />
<idle-time-to-disconnect-pool value="5" />
<credential-expiry-time value="10" />
<max-connection-pool-size value="7" />
<alternative-statement-delimiter value="" />
</details>
<object-filters hide-empty-schemas="false" hide-pseudo-columns="false">
<object-type-filter>
<object-type name="SCHEMA" enabled="true" />
<object-type name="USER" enabled="true" />
<object-type name="ROLE" enabled="true" />
<object-type name="PRIVILEGE" enabled="true" />
<object-type name="CHARSET" enabled="true" />
<object-type name="TABLE" enabled="true" />
<object-type name="VIEW" enabled="true" />
<object-type name="MATERIALIZED_VIEW" enabled="true" />
<object-type name="NESTED_TABLE" enabled="true" />
<object-type name="COLUMN" enabled="true" />
<object-type name="INDEX" enabled="true" />
<object-type name="CONSTRAINT" enabled="true" />
<object-type name="DATASET_TRIGGER" enabled="true" />
<object-type name="DATABASE_TRIGGER" enabled="true" />
<object-type name="SYNONYM" enabled="true" />
<object-type name="SEQUENCE" enabled="true" />
<object-type name="PROCEDURE" enabled="true" />
<object-type name="FUNCTION" enabled="true" />
<object-type name="PACKAGE" enabled="true" />
<object-type name="TYPE" enabled="true" />
<object-type name="TYPE_ATTRIBUTE" enabled="true" />
<object-type name="ARGUMENT" enabled="true" />
<object-type name="DIMENSION" enabled="true" />
<object-type name="CLUSTER" enabled="true" />
<object-type name="DBLINK" enabled="true" />
</object-type-filter>
<object-name-filters />
</object-filters>
</connection>
</connections>
<browser-settings>
<general>
<display-mode value="TABBED" />
@ -145,11 +238,11 @@
<nulls-first value="true" />
<max-sorting-columns value="4" />
</sorting>
<tracking-columns>
<columnNames value="" />
<audit-columns>
<column-names value="" />
<visible value="true" />
<editable value="false" />
</tracking-columns>
</audit-columns>
</dataset-grid-settings>
<dataset-editor-settings>
<text-editor-popup>

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

View File

@ -69,22 +69,7 @@ class SwGetOrdersCommand extends Command
//offene Bestellungen aus Datenbank holen
$this->orderData = $this->getOrders();
//Bestelldetails aus SW holen
$this->getOrdersDataFromSW();
foreach ($this->orderData as $order) {
$io->info('Bestellung ID: '.$order->getId());
$io->info('Bestellung Order-ID: '.$order->getOrderId());
$io->info('Bestellung Data: '.var_export($order->getData(),1));
$this->saveOrdersData($order);
}
$this->getOrderDetails();
$io->success('Done!');
return Command::SUCCESS;
@ -98,6 +83,19 @@ class SwGetOrdersCommand extends Command
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
*/

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

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

@ -0,0 +1,75 @@
<?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,50 @@
<?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');
}
}

View File

@ -48,8 +48,6 @@ class OrdersRepository extends ServiceEntityRepository
throw $this->createNotFoundException('Order not found: '.$entity->getId());
}
}
public function remove(Orders $entity, bool $flush = false): void

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